Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected shouldSelectNode(node: TreeNodeItem, selection: Readonly) {
const nodeKey = this.getNodeKey(node);
if (nodeKey === undefined)
return false;
// consider node selected if it's key is in selection
if (selection.has(nodeKey))
return true;
// ... or if it's an ECInstances node and any of instance keys is in selection
if (NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.some((instanceKey) => selection.has(instanceKey)))
return true;
// ... or if it's an ECInstance node and instance key is in selection
if (NodeKey.isInstanceNodeKey(nodeKey) && selection.has(nodeKey.instanceKey))
return true;
return false;
}
private isNodeSelected(node: TreeNodeItem): boolean {
if (!this._selectionHandler)
return false;
const selection = this._selectionHandler.getSelection();
// consider node selected if it's key is in selection
const nodeKey = this.props.dataProvider.getNodeKey(node);
if (selection.has(nodeKey))
return true;
// ... or if it's an ECInstances node and any of instance keys is in selection
if (NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.some((instanceKey) => selection.has(instanceKey)))
return true;
// ... or if it's an ECInstance node and instance key is in selection
if (NodeKey.isInstanceNodeKey(nodeKey) && selection.has(nodeKey.instanceKey))
return true;
return false;
}
public getDisplayStatus(node: TreeNodeItem): VisibilityStatus | Promise {
const key = this._props.dataProvider.getNodeKey(node);
if (!NodeKey.isInstancesNodeKey(key))
return { isDisplayed: false, isDisabled: true };
if (isSubjectNode(node)) {
// note: subject nodes may be merged to represent multiple subject instances
return this.getSubjectDisplayStatus(key.instanceKeys.map((k) => k.id));
}
if (isModelNode(node))
return this.getModelDisplayStatus(key.instanceKeys[0].id);
if (isCategoryNode(node))
return this.getCategoryDisplayStatus(key.instanceKeys[0].id, this.getCategoryParentModelId(node));
return this.getElementDisplayStatus(key.instanceKeys[0].id, this.getElementModelId(node), this.getElementCategoryId(node));
}
public async changeVisibility(node: TreeNodeItem, on: boolean) {
const key = this._props.dataProvider.getNodeKey(node);
if (!NodeKey.isInstancesNodeKey(key))
return;
if (isSubjectNode(node)) {
await this.changeSubjectState(key.instanceKeys.map((k) => k.id), on);
} else if (isModelNode(node)) {
await this.changeModelState(key.instanceKeys[0].id, on);
} else if (isCategoryNode(node)) {
this.changeCategoryState(key.instanceKeys[0].id, this.getCategoryParentModelId(node), on);
} else {
await this.changeElementState(key.instanceKeys[0].id, this.getElementModelId(node), this.getElementCategoryId(node), on);
}
}