Loading src/components/AttributeEditor/AttributeEditor.jsx +18 −10 Original line number Diff line number Diff line Loading @@ -43,23 +43,32 @@ export default class AttributeEditor extends Component { attributes: [], }; componentDidMount() { const {selection} = this.props; static getTerritoryFromSelection(selection) { const territory = {}; selection.forEach((item) => { territory[item] = {children: 0}; }); this.setState({territory}); return territory; } componentWillReceiveProps(newProps) { const {selection} = newProps; const territory = {}; static getDerivedStateFromProps(nextProps, prevState) { if (nextProps.selection.length !== Object.keys(prevState.territory).length) { return {territory: AttributeEditor.getTerritoryFromSelection(nextProps.selection)} } selection.forEach((item) => { territory[item] = {children: 0}; for (let i = 0; nextProps.selection.length; i += 1) { if (!prevState.territory[nextProps.selection[i]]) { return {territory: AttributeEditor.getTerritoryFromSelection(nextProps.selection)} } } return null; } componentDidMount() { this.setState({ territory: AttributeEditor.getTerritoryFromSelection(this.props.selection) }); } Loading Loading @@ -174,7 +183,6 @@ export default class AttributeEditor extends Component { return ( <Card> <Territory activeNode={selection[0]} gmeClient={gmeClient} territory={territory} onUpdate={this.handleEvents} Loading Loading
src/components/AttributeEditor/AttributeEditor.jsx +18 −10 Original line number Diff line number Diff line Loading @@ -43,23 +43,32 @@ export default class AttributeEditor extends Component { attributes: [], }; componentDidMount() { const {selection} = this.props; static getTerritoryFromSelection(selection) { const territory = {}; selection.forEach((item) => { territory[item] = {children: 0}; }); this.setState({territory}); return territory; } componentWillReceiveProps(newProps) { const {selection} = newProps; const territory = {}; static getDerivedStateFromProps(nextProps, prevState) { if (nextProps.selection.length !== Object.keys(prevState.territory).length) { return {territory: AttributeEditor.getTerritoryFromSelection(nextProps.selection)} } selection.forEach((item) => { territory[item] = {children: 0}; for (let i = 0; nextProps.selection.length; i += 1) { if (!prevState.territory[nextProps.selection[i]]) { return {territory: AttributeEditor.getTerritoryFromSelection(nextProps.selection)} } } return null; } componentDidMount() { this.setState({ territory: AttributeEditor.getTerritoryFromSelection(this.props.selection) }); } Loading Loading @@ -174,7 +183,6 @@ export default class AttributeEditor extends Component { return ( <Card> <Territory activeNode={selection[0]} gmeClient={gmeClient} territory={territory} onUpdate={this.handleEvents} Loading