Skip to content

Commit

Permalink
VectorSelector : Adjusted according to changes in `SmartNodeSelecto…
Browse files Browse the repository at this point in the history
…r` (equinor#413)

* Extended property state updates
* Adjusted error variables
  • Loading branch information
rubenthoms authored Jun 25, 2021
1 parent 2dc78bb commit bbcc6c3
Showing 1 changed file with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ export default class VectorSelectorComponent extends SmartNodeSelectorComponent
super(props);
this.props = props;

let hasError = false;
let error = "";
let error: string | undefined;
try {
this.treeData = new TreeData({
treeData: this.modifyTreeData(props.data, props.numMetaNodes),
delimiter: props.delimiter,
});
} catch (e) {
hasError = true;
error = e;
}

Expand All @@ -90,12 +88,55 @@ export default class VectorSelectorComponent extends SmartNodeSelectorComponent
nodeSelections,
currentTagIndex: 0,
suggestionsVisible: false,
hasError: hasError,
error: error,
hasError: error !== undefined,
error: error || "",
};
}

componentDidUpdate(prevProps: VectorSelectorPropType): void {
if (
(this.props.data &&
JSON.stringify(this.props.data) !==
JSON.stringify(prevProps.data)) ||
(this.props.delimiter &&
this.props.delimiter !== prevProps.delimiter) ||
(this.props.numMetaNodes &&
this.props.numMetaNodes !== prevProps.numMetaNodes)
) {
let error: string | undefined;
try {
this.treeData = new TreeData({
treeData: this.modifyTreeData(
this.props.data,
this.props.numMetaNodes
),
delimiter: this.props.delimiter,
});
} catch (e) {
this.treeData = null;
error = e;
}
const nodeSelections: VectorSelection[] = [];
for (const node of this.state.nodeSelections) {
nodeSelections.push(
this.createNewNodeSelection(node.getNodePath())
);
}

this.setState(
{
nodeSelections: nodeSelections,
currentTagIndex: this.state.currentTagIndex,
suggestionsVisible: this.state.suggestionsVisible,
hasError: error !== undefined,
error: error || "",
},
() => {
this.updateSelectedTagsAndNodes();
}
);
}

const selectedTags = this.state.nodeSelections
.filter((nodeSelection) => nodeSelection.isValid())
.map((nodeSelection) =>
Expand Down Expand Up @@ -161,7 +202,7 @@ export default class VectorSelectorComponent extends SmartNodeSelectorComponent
level: number
) => {
const newData: TreeDataNode[] = [];
if (level == numMetaNodes && data) {
if (level === numMetaNodes && data) {
const types = {};
for (let i = 0; i < data.length; i++) {
let type = "others";
Expand Down

0 comments on commit bbcc6c3

Please sign in to comment.