From 6e4f41bb03222b57caa4c1b997a53c7fb6074e52 Mon Sep 17 00:00:00 2001 From: nsemets Date: Fri, 6 Feb 2026 12:45:27 +0200 Subject: [PATCH] fix(files): fixed move file to parent --- .../move-file-dialog.component.ts | 2 +- .../shared/mappers/nodes/base-node.mapper.ts | 31 +++++++++++++++++-- src/app/shared/services/resource.service.ts | 5 +-- .../current-resource.actions.ts | 3 +- .../current-resource.state.ts | 2 +- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/app/features/files/components/move-file-dialog/move-file-dialog.component.ts b/src/app/features/files/components/move-file-dialog/move-file-dialog.component.ts index b9d5863bb..493e85134 100644 --- a/src/app/features/files/components/move-file-dialog/move-file-dialog.component.ts +++ b/src/app/features/files/components/move-file-dialog/move-file-dialog.component.ts @@ -130,7 +130,7 @@ export class MoveFileDialogComponent { const currentProject = this.currentProject(); if (currentProject) { const rootParentId = currentProject.rootResourceId ?? currentProject.id; - this.actions.getComponentsTree(rootParentId, currentProject.id, ResourceType.Project); + this.actions.getComponentsTree(rootParentId, currentProject.id, ResourceType.Project, true); } effect(() => { diff --git a/src/app/shared/mappers/nodes/base-node.mapper.ts b/src/app/shared/mappers/nodes/base-node.mapper.ts index fa0645bac..24dd37b15 100644 --- a/src/app/shared/mappers/nodes/base-node.mapper.ts +++ b/src/app/shared/mappers/nodes/base-node.mapper.ts @@ -20,8 +20,16 @@ export class BaseNodeMapper { }; } - static getNodesWithChildren(data: BaseNodeDataJsonApi[], parentId: string): NodeShortInfoModel[] { - return this.getAllDescendants(data, parentId).map((item) => ({ + static getNodesWithChildren( + data: BaseNodeDataJsonApi[], + parentId: string, + includeAncestors = false + ): NodeShortInfoModel[] { + const nodes = includeAncestors + ? this.getAllAncestorsAndDescendants(data, parentId) + : this.getAllDescendants(data, parentId); + + return nodes.map((item) => ({ id: item.id, title: replaceBadEncodedChars(item.attributes.title), isPublic: item.attributes.public, @@ -82,4 +90,23 @@ export class BaseNodeMapper { return [parent, ...descendants]; } + + static getAllAncestors(allNodes: BaseNodeDataJsonApi[], nodeId: string): BaseNodeDataJsonApi[] { + const node = allNodes.find((n) => n.id === nodeId); + if (!node) return []; + + const parentId = node.relationships.parent?.data?.id; + if (!parentId) return [node]; + + const ancestors = this.getAllAncestors(allNodes, parentId); + + return [node, ...ancestors]; + } + + static getAllAncestorsAndDescendants(allNodes: BaseNodeDataJsonApi[], nodeId: string): BaseNodeDataJsonApi[] { + const ancestors = this.getAllAncestors(allNodes, nodeId); + const descendants = this.getAllDescendants(allNodes, nodeId).slice(1); + + return [...ancestors, ...descendants]; + } } diff --git a/src/app/shared/services/resource.service.ts b/src/app/shared/services/resource.service.ts index 3b1d51fb2..d1290d022 100644 --- a/src/app/shared/services/resource.service.ts +++ b/src/app/shared/services/resource.service.ts @@ -76,12 +76,13 @@ export class ResourceGuidService { getResourceWithChildren( rootParentId: string, resourceId: string, - resourceType: ResourceType + resourceType: ResourceType, + includeAncestors = false ): Observable { const resourcePath = this.urlMap.get(resourceType); return this.jsonApiService .get(`${this.apiUrl}/${resourcePath}/?filter[root]=${rootParentId}&page[size]=100`) - .pipe(map((response) => BaseNodeMapper.getNodesWithChildren(response.data, resourceId))); + .pipe(map((response) => BaseNodeMapper.getNodesWithChildren(response.data, resourceId, includeAncestors))); } } diff --git a/src/app/shared/stores/current-resource/current-resource.actions.ts b/src/app/shared/stores/current-resource/current-resource.actions.ts index f911603e7..10ef71daa 100644 --- a/src/app/shared/stores/current-resource/current-resource.actions.ts +++ b/src/app/shared/stores/current-resource/current-resource.actions.ts @@ -24,6 +24,7 @@ export class GetResourceWithChildren { constructor( public rootParentId: string, public resourceId: string, - public resourceType: ResourceType + public resourceType: ResourceType, + public includeAncestors = false ) {} } diff --git a/src/app/shared/stores/current-resource/current-resource.state.ts b/src/app/shared/stores/current-resource/current-resource.state.ts index 199c355d8..9bceb57bc 100644 --- a/src/app/shared/stores/current-resource/current-resource.state.ts +++ b/src/app/shared/stores/current-resource/current-resource.state.ts @@ -87,7 +87,7 @@ export class CurrentResourceState { }); return this.resourceService - .getResourceWithChildren(action.rootParentId, action.resourceId, action.resourceType) + .getResourceWithChildren(action.rootParentId, action.resourceId, action.resourceType, action.includeAncestors) .pipe( tap((children) => { ctx.patchState({