remove duplicate issue

This commit is contained in:
faris Aljohari
2025-03-11 12:19:26 +03:00
parent 64f83cbda2
commit f9878ff272

View File

@ -645,9 +645,9 @@ export class SpaceService {
private buildSpaceHierarchy(spaces: SpaceEntity[]): SpaceEntity[] {
const map = new Map<string, SpaceEntity>();
// Step 1: Create a map of spaces by UUID, without creating new instances
spaces.forEach((space) => {
map.set(space.uuid, space); // Use the existing space entity
// Step 1: Create a map of spaces by UUID
spaces.forEach((space: any) => {
map.set(space.uuid, { ...space, children: [] }); // Ensure children are reset
});
// Step 2: Organize the hierarchy
@ -656,13 +656,13 @@ export class SpaceService {
if (space.parent && space.parent.uuid) {
const parent = map.get(space.parent.uuid);
if (parent) {
if (!parent.children) {
parent.children = [];
const child = map.get(space.uuid);
if (child && !parent.children.some((c) => c.uuid === child.uuid)) {
parent.children.push(child);
}
parent.children.push(space);
}
} else {
rootSpaces.push(space);
rootSpaces.push(map.get(space.uuid)!); // Push only root spaces
}
});