Commit 649062fc authored by Patrik Meijer's avatar Patrik Meijer
Browse files

FIX selection handling of AttributeEditor

parent 9e386f7f
......@@ -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)
});
}
......@@ -174,7 +183,6 @@ export default class AttributeEditor extends Component {
return (
<Card>
<Territory
activeNode={selection[0]}
gmeClient={gmeClient}
territory={territory}
onUpdate={this.handleEvents}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment