From f77817af5cdb3816688091887511d74128aedd10 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Wed, 5 Feb 2025 23:06:03 +0400 Subject: [PATCH 1/3] fixed moving tags between subspaces --- src/space/services/tag/tag.service.ts | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/space/services/tag/tag.service.ts b/src/space/services/tag/tag.service.ts index 2dee0c7..be783b2 100644 --- a/src/space/services/tag/tag.service.ts +++ b/src/space/services/tag/tag.service.ts @@ -543,6 +543,23 @@ export class TagService { // Extract tags marked for addition in spaceTags const spaceTagsToAdd = spaceTags?.filter((tag) => tag.action === 'add'); + const subspaceTagsToAdd = subspaceModels.flatMap( + (subspace) => subspace.tags?.filter((tag) => tag.action === 'add') || [], + ); + + const subspaceTagsToDelete = subspaceModels.flatMap( + (subspace) => + subspace.tags?.filter((tag) => tag.action === 'delete') || [], + ); + + const subspaceTagsToDeleteUuids = new Set( + subspaceTagsToDelete.map((tag) => tag.uuid), + ); + + const commonTagsInSubspaces = subspaceTagsToAdd.filter((tag) => + subspaceTagsToDeleteUuids.has(tag.uuid), + ); + // Find UUIDs of tags that are common between spaceTagsToAdd and subspace tags marked for deletion const commonTagUuids = new Set( spaceTagsToAdd @@ -560,11 +577,25 @@ export class TagService { ); // Modify subspaceModels by removing tags with UUIDs present in commonTagUuids - const modifiedSubspaces = subspaceModels.map((subspace) => ({ + let modifiedSubspaces = subspaceModels.map((subspace) => ({ ...subspace, tags: subspace.tags?.filter((tag) => !commonTagUuids.has(tag.uuid)) || [], })); + modifiedSubspaces = modifiedSubspaces.map((subspace) => ({ + ...subspace, + tags: + subspace.tags?.filter( + (tag) => + !( + tag.action === 'delete' && + commonTagsInSubspaces.some( + (commonTag) => commonTag.uuid === tag.uuid, + ) + ), + ) || [], + })); + return modifiedSubspaces; } } From 21addb7ac0cdc618714cdfa7b1d7b7cc3c675ad6 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Wed, 5 Feb 2025 23:06:18 +0400 Subject: [PATCH 2/3] fixed moving tags between subspace models --- src/space-model/services/tag-model.service.ts | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/space-model/services/tag-model.service.ts b/src/space-model/services/tag-model.service.ts index b663590..7f70c89 100644 --- a/src/space-model/services/tag-model.service.ts +++ b/src/space-model/services/tag-model.service.ts @@ -519,6 +519,23 @@ export class TagModelService { // Extract tags marked for addition in spaceTags const spaceTagsToAdd = spaceTags.filter((tag) => tag.action === 'add'); + const subspaceTagsToAdd = subspaceModels.flatMap( + (subspace) => subspace.tags?.filter((tag) => tag.action === 'add') || [], + ); + + const subspaceTagsToDelete = subspaceModels.flatMap( + (subspace) => + subspace.tags?.filter((tag) => tag.action === 'delete') || [], + ); + + const subspaceTagsToDeleteUuids = new Set( + subspaceTagsToDelete.map((tag) => tag.uuid), + ); + + const commonTagsInSubspaces = subspaceTagsToAdd.filter((tag) => + subspaceTagsToDeleteUuids.has(tag.uuid), + ); + // Find UUIDs of tags that are common between spaceTagsToAdd and subspace tags marked for deletion const commonTagUuids = new Set( spaceTagsToAdd @@ -536,11 +553,26 @@ export class TagModelService { ); // Modify subspaceModels by removing tags with UUIDs present in commonTagUuids - const modifiedSubspaces = subspaceModels.map((subspace) => ({ + let modifiedSubspaces = subspaceModels.map((subspace) => ({ ...subspace, tags: subspace.tags?.filter((tag) => !commonTagUuids.has(tag.uuid)) || [], })); + modifiedSubspaces = modifiedSubspaces.map((subspace) => ({ + ...subspace, + tags: + subspace.tags?.filter( + (tag) => + !( + tag.action === 'delete' && + commonTagsInSubspaces.some( + (commonTag) => commonTag.uuid === tag.uuid, + ) + ), + ) || [], + })); + + return modifiedSubspaces; } } From 06760649ff02343fea516562885903051121416f Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Wed, 5 Feb 2025 23:09:34 +0400 Subject: [PATCH 3/3] prettier --- src/space-model/services/tag-model.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/space-model/services/tag-model.service.ts b/src/space-model/services/tag-model.service.ts index 7f70c89..b23bc7e 100644 --- a/src/space-model/services/tag-model.service.ts +++ b/src/space-model/services/tag-model.service.ts @@ -572,7 +572,6 @@ export class TagModelService { ) || [], })); - return modifiedSubspaces; } }