diff --git a/webapp/packages/core-app/src/shared/NodesManager/NavNodeInfoResource.ts b/webapp/packages/core-app/src/shared/NodesManager/NavNodeInfoResource.ts index 52e6825476..c21bacdc3b 100644 --- a/webapp/packages/core-app/src/shared/NodesManager/NavNodeInfoResource.ts +++ b/webapp/packages/core-app/src/shared/NodesManager/NavNodeInfoResource.ts @@ -95,6 +95,13 @@ export class NavNodeInfoResource extends CachedMapResource { }); } + getParent(key: string): string | undefined; + getParent(key: ResourceKeyList): (string | undefined)[]; + getParent(key: ResourceKey): string | undefined | (string | undefined)[]; + getParent(key: ResourceKey): string | undefined | (string | undefined)[] { + return ResourceKeyUtils.map(key, key => this.get(key)?.parentId); + } + setParent(key: string, parentId: string): void; setParent(key: ResourceKeyList, parentId: string): void; setParent(key: ResourceKey, parentId: string): void; diff --git a/webapp/packages/core-app/src/shared/NodesManager/NavTreeResource.ts b/webapp/packages/core-app/src/shared/NodesManager/NavTreeResource.ts index 7501796b4e..4e3bd6e040 100644 --- a/webapp/packages/core-app/src/shared/NodesManager/NavTreeResource.ts +++ b/webapp/packages/core-app/src/shared/NodesManager/NavTreeResource.ts @@ -68,6 +68,7 @@ export class NavTreeResource extends CachedMapResource { childrenLimit: computed, setDetails: action, setNavObject: action, + moveToNode: action, deleteInNode: action, unshiftToNode: action, pushToNode: action, @@ -205,6 +206,8 @@ export class NavTreeResource extends CachedMapResource { nodePaths: ResourceKeyUtils.toArray(key), folderPath: folder?.id, }); + + this.moveToNode(key, target); } finally { this.markDataLoaded(target); } @@ -229,8 +232,39 @@ export class NavTreeResource extends CachedMapResource { this.markOutdated(node.parentId); } + moveToNode(key: string, target: string): void; + moveToNode(key: ResourceKeyList, target: string): void; + moveToNode(keyObject: ResourceKey, target: string): void; + moveToNode(keyObject: ResourceKey, target: string): void { + ResourceKeyUtils.forEach(keyObject, key => { + const parentId = this.navNodeInfoResource.getParent(key); + + if (parentId !== undefined) { + const currentValue = this.data.get(parentId); + + if (currentValue) { + const nodeInfo = this.navNodeInfoResource.get(parentId); + const children = currentValue.filter(value => value !== key); + + if (nodeInfo) { + nodeInfo.hasChildren = children.length > 0; + } + this.data.set(parentId, children); + } + } + + this.navNodeInfoResource.setParent(key, target); + }); + + this.pushToNode(target, ResourceKeyUtils.toArray(keyObject)); + this.markUpdated(target); + this.markUpdated(keyObject); + this.onItemAdd.execute(keyObject); + } + deleteInNode(key: string, value: string[]): void; deleteInNode(key: ResourceKeyList, value: string[][]): void; + deleteInNode(keyObject: ResourceKey, valueObject: string[] | string[][]): void; deleteInNode(keyObject: ResourceKey, valueObject: string[] | string[][]): void { const deletedKeys: string[] = []; @@ -239,7 +273,13 @@ export class NavTreeResource extends CachedMapResource { const currentValue = this.data.get(key); if (currentValue) { - this.data.set(key, currentValue.filter(value => !values.includes(value))); + const children = currentValue.filter(value => !values.includes(value)); + const nodeInfo = this.navNodeInfoResource.get(key); + + if (nodeInfo) { + nodeInfo.hasChildren = children.length > 0; + } + this.data.set(key, children); } deletedKeys.push(...values); @@ -256,8 +296,13 @@ export class NavTreeResource extends CachedMapResource { ResourceKeyUtils.forEach(keyObject, (key, i) => { const values = i === -1 ? (valueObject as string[]) : (valueObject as string[][])[i]; const currentValue = this.data.get(key) || []; + const nodeInfo = this.navNodeInfoResource.get(key); currentValue.unshift(...values); + + if (nodeInfo) { + nodeInfo.hasChildren = currentValue.length > 0; + } this.data.set(key, currentValue); }); @@ -271,8 +316,13 @@ export class NavTreeResource extends CachedMapResource { ResourceKeyUtils.forEach(keyObject, (key, i) => { const values = i === -1 ? (valueObject as string[]) : (valueObject as string[][])[i]; const currentValue = this.data.get(key) || []; + const nodeInfo = this.navNodeInfoResource.get(key); currentValue.push(...values); + + if (nodeInfo) { + nodeInfo.hasChildren = currentValue.length > 0; + } this.data.set(key, currentValue); }); diff --git a/webapp/packages/plugin-connections/src/NavNodes/ConnectionFoldersBootstrap.ts b/webapp/packages/plugin-connections/src/NavNodes/ConnectionFoldersBootstrap.ts index 59d26d45cd..a2c3617231 100644 --- a/webapp/packages/plugin-connections/src/NavNodes/ConnectionFoldersBootstrap.ts +++ b/webapp/packages/plugin-connections/src/NavNodes/ConnectionFoldersBootstrap.ts @@ -130,6 +130,7 @@ export class ConnectionFoldersBootstrap extends Bootstrap { ) { const move = contexts.getContext(navNodeMoveContext); const nodes = getNodesFromContext(moveContexts); + const nodeIdList = nodes.map(node => node.id); const children = this.navTreeResource.get(targetNode.id); if (type === ENodeMoveType.CanDrop && targetNode.nodeType) { @@ -144,7 +145,12 @@ export class ConnectionFoldersBootstrap extends Bootstrap { move.setCanMove(true); } } else { - await this.navTreeResource.moveTo(resourceKeyList(nodes.map(node => node.id)), targetNode.id); + await this.navTreeResource.moveTo(resourceKeyList(nodeIdList), targetNode.id); + const connections = nodeIdList + .map(nodeId => this.connectionInfoResource.getConnectionForNode(nodeId)?.id) + .filter(Boolean as any); + + this.connectionInfoResource.markOutdated(resourceKeyList(connections)); } }