Code Monkey home page Code Monkey logo

react-field-mapping's People

Contributors

iamnotblank avatar shaojun427 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-field-mapping's Issues

OnChange suggestion

Hi zsjjs, great library there, some problem it has when I have a function like

  if (isMultipleSourceToOneTargetThatIsAcceptable(relation)) {
              console.log("new");
              this.setState({
                relation
              });
            } else {
                  }

but I discover it still chang even I am not setting that, is it an uncontrolled component?

Invalid mapping relation error

Hey
Features are really cool.
Found an issue where if there is any invalid key values in the relation , then arrow is displaying by connecting first source row to first target row.

this.state = { relation: [{ source: { key: "Nofield" }, target: { key: "field502" } }]}

shows connecting arrow between first source row and first target row like below,
image

多个使用时,手动连线只有最新的可以,其他的不行

使用场景:在不同tab中使用react-field-mapping
操作:tab1使用mapping1,tab2使用mapping2,新增tab3使用组件mapping3时,
问题:mapping3手动连线和同行连线等均可使用;
mapping1、mapping2手动连线不可用,其他同行连线可用
期望:mapping1、mapping2仍然可以手动连线

组件加载完后,如果上面有元素的高度发生变化,会导致连线的定位不准确

const sourceCols = [
{ title: '源表字段', key: 'name', width: '80px' },
{ title: '类型', key: 'type', width: '100px' },
{ title: '描述', key: 'desc', width: '150px' },
{ title: '操作', key: 'operate', width: '80px', align: 'center', render: (value, record) => {
return <a href="javascript:void(0);" onClick={
() => {
alert(JSON.stringify(record));
}
}>查看详情;
}}
];
const targetCols = [
{ title: '目标表字段', key: 'name', width: '50%' },
{ title: '类型', key: 'type', width: '50%' }
];
const sData = new Array(7).fill().map((item, idx) => ({
name: field${idx + 1},
type: 'string',
key: field${idx + 1},
desc: 这是表字段field${idx + 1},
operate: 测试${idx}
}));
const tData = new Array(11).fill().map((item, idx) => ({
name: field${idx + 4},
type: 'string',
key: field${idx + 4}
}))
class App extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
relation: [],
sourceData: [],
targetData: []
};
}
getRelation() {
console.log(this.state.relation);
alert(JSON.stringify(this.state.relation));
}
sameLine() {
const {sourceData, targetData} = this.state;
const len = sourceData.length > targetData.length ? targetData.length : sourceData.length;
const relation = [];
for(let i=0; i<len; i++ ) {
relation.push({
source: sourceData[i],
target: targetData[i]
});
}
this.setState({
relation
});
}
sameName() {
const {sourceData, targetData} = this.state;
const relation = [];
sourceData.map(item => {
targetData.map(n => {
if(item.name === n.name) {
relation.push({
source: item,
target: n
});
}
});
});
this.setState({
relation
});
}
cancelRelation() {
this.setState({
relation: []
});
}
getData=()=>{
this.setState({ sourceData: sData, targetData: tData })
}
render() {
const { sourceData, targetData } = this.state;
const option = {
source: {
data: sourceData,
onChange: (data) => { // isSort开启后,必须开启才会生效
this.setState({
sourceData: data
});
},
columns: sourceCols
},
target: {
data: targetData,
onChange: (data) => {
this.setState({
targetData: data
});
},
columns: targetCols
},
relation: this.state.relation,
// onDrawStart: (source, relation) => {
// console.log("onDrawStart: ", source, relation);
// },
// onDrawing: (source, relation) => {
// console.log("onDrawing: ", source, relation);
// },
// onDrawEnd: (source, target, relation) => {
// console.log("onDrawEnd: ", source, relation);
// },
onChange: (relation) => {
this.setState({
relation
});
},
isSort: true
};
return



<div style={{
width: 800
}}>
{this.state.visible&&<div style={{ height: 30 }}>
}
<FieldMapping {...option} />


获取映射关系
同行关联
同名关联
取消关联
<button onClick={()=>this.setState({visible: !this.state.visible})}>显隐
加载数据


;
}
}

ReactDOM.render(
,
document.getElementById('Test')
);

https://codepen.io/godIsMe/pen/xvgYdx中打开:
把上面的代码拷贝进去,操作:显隐 -- 加载数据 -- 连线
可以复现

功能优化

最开始的onChange是只监听relation变化的,后来增加了表字段的排序,所以修改排序后就需要手动在onChange里面修改外层的sourceData同步变化。原来的表是基于业务需求定死的两个字段name、type,而不是按Table做的,应该算是一个字段的List。后面基于前面的问题作出以下优化,会有破坏性升级。
1、source、target的原title属性删除,增加类似table的columns属性,原data必传name和type改成标识符key,其他为自定义列字段即可。
2、onChange改为只有关联的change监听,表的change放到各自的table属性里面去。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.