Skip to content

Commit 64457ef

Browse files
committed
Merge branch 'hotfix/26.2.2'
2 parents d92ff04 + b93fe19 commit 64457ef

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

src/app/features/files/components/move-file-dialog/move-file-dialog.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class MoveFileDialogComponent {
130130
const currentProject = this.currentProject();
131131
if (currentProject) {
132132
const rootParentId = currentProject.rootResourceId ?? currentProject.id;
133-
this.actions.getComponentsTree(rootParentId, currentProject.id, ResourceType.Project);
133+
this.actions.getComponentsTree(rootParentId, currentProject.id, ResourceType.Project, true);
134134
}
135135

136136
effect(() => {

src/app/shared/mappers/nodes/base-node.mapper.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ export class BaseNodeMapper {
2020
};
2121
}
2222

23-
static getNodesWithChildren(data: BaseNodeDataJsonApi[], parentId: string): NodeShortInfoModel[] {
24-
return this.getAllDescendants(data, parentId).map((item) => ({
23+
static getNodesWithChildren(
24+
data: BaseNodeDataJsonApi[],
25+
parentId: string,
26+
includeAncestors = false
27+
): NodeShortInfoModel[] {
28+
const nodes = includeAncestors
29+
? this.getAllAncestorsAndDescendants(data, parentId)
30+
: this.getAllDescendants(data, parentId);
31+
32+
return nodes.map((item) => ({
2533
id: item.id,
2634
title: replaceBadEncodedChars(item.attributes.title),
2735
isPublic: item.attributes.public,
@@ -82,4 +90,23 @@ export class BaseNodeMapper {
8290

8391
return [parent, ...descendants];
8492
}
93+
94+
static getAllAncestors(allNodes: BaseNodeDataJsonApi[], nodeId: string): BaseNodeDataJsonApi[] {
95+
const node = allNodes.find((n) => n.id === nodeId);
96+
if (!node) return [];
97+
98+
const parentId = node.relationships.parent?.data?.id;
99+
if (!parentId) return [node];
100+
101+
const ancestors = this.getAllAncestors(allNodes, parentId);
102+
103+
return [node, ...ancestors];
104+
}
105+
106+
static getAllAncestorsAndDescendants(allNodes: BaseNodeDataJsonApi[], nodeId: string): BaseNodeDataJsonApi[] {
107+
const ancestors = this.getAllAncestors(allNodes, nodeId);
108+
const descendants = this.getAllDescendants(allNodes, nodeId).slice(1);
109+
110+
return [...ancestors, ...descendants];
111+
}
85112
}

src/app/shared/services/resource.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ export class ResourceGuidService {
7676
getResourceWithChildren(
7777
rootParentId: string,
7878
resourceId: string,
79-
resourceType: ResourceType
79+
resourceType: ResourceType,
80+
includeAncestors = false
8081
): Observable<NodeShortInfoModel[]> {
8182
const resourcePath = this.urlMap.get(resourceType);
8283

8384
return this.jsonApiService
8485
.get<NodesResponseJsonApi>(`${this.apiUrl}/${resourcePath}/?filter[root]=${rootParentId}&page[size]=100`)
85-
.pipe(map((response) => BaseNodeMapper.getNodesWithChildren(response.data, resourceId)));
86+
.pipe(map((response) => BaseNodeMapper.getNodesWithChildren(response.data, resourceId, includeAncestors)));
8687
}
8788
}

src/app/shared/stores/current-resource/current-resource.actions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class GetResourceWithChildren {
2424
constructor(
2525
public rootParentId: string,
2626
public resourceId: string,
27-
public resourceType: ResourceType
27+
public resourceType: ResourceType,
28+
public includeAncestors = false
2829
) {}
2930
}

src/app/shared/stores/current-resource/current-resource.state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class CurrentResourceState {
8787
});
8888

8989
return this.resourceService
90-
.getResourceWithChildren(action.rootParentId, action.resourceId, action.resourceType)
90+
.getResourceWithChildren(action.rootParentId, action.resourceId, action.resourceType, action.includeAncestors)
9191
.pipe(
9292
tap((children) => {
9393
ctx.patchState({

0 commit comments

Comments
 (0)