TagSpaces is an offline, open source, document manager with tagging support
fix: issue with taggroups associated with workspaces
Ilian Sapundshiev8ef2555f41f2
diff --git a/src/renderer/hooks/EditedTagLibraryContextProvider.tsx b/src/renderer/hooks/EditedTagLibraryContextProvider.tsxindex 049a843cd..699094986 100644--- a/src/renderer/hooks/EditedTagLibraryContextProvider.tsx+++ b/src/renderer/hooks/EditedTagLibraryContextProvider.tsx@@ -88,14 +88,19 @@ export const EditedTagLibraryContextProvider = ({if (Pro && saveTagInLocation) {getTagsFromLocations().then((locationTagGroups) => {if (locationTagGroups && Object.keys(locationTagGroups).length > 0) {- // rebuild the flattened array- const fresh: TS.TagGroup[] = [- ...getTagLibrary(),- ...Object.entries(locationTagGroups).flatMap(([uuid, groups]) =>- groups.map((g) => ({ ...g, locationId: uuid })),- ),- ];- setTagGroups(fresh);+ // Dedup by uuid: location copy wins over the main-library copy,+ // since saveTagInLocation means the location is the source of truth.+ // getTagsFromLocations already stamps locationId + workSpaceId.+ const byUuid = new Map<string, TS.TagGroup>();+ for (const g of getTagLibrary()) {+ if (g.uuid) byUuid.set(g.uuid, g);+ }+ for (const groups of Object.values(locationTagGroups)) {+ for (const g of groups) {+ if (g.uuid) byUuid.set(g.uuid, g);+ }+ }+ setTagGroups(Array.from(byUuid.values()));}});} else if (force) {diff --git a/src/renderer/hooks/TagGroupsLocationContextProvider.tsx b/src/renderer/hooks/TagGroupsLocationContextProvider.tsxindex 55a808a38..bada0ea43 100644--- a/src/renderer/hooks/TagGroupsLocationContextProvider.tsx+++ b/src/renderer/hooks/TagGroupsLocationContextProvider.tsx@@ -102,8 +102,15 @@ export const TagGroupsLocationContextProvider = ({function getTagGroups(location: CommonLocation): Promise<TS.TagGroup[]> {return loadLocationDataPromise(location).then((fsEntryMeta: TS.FileSystemEntryMeta) => {- if (fsEntryMeta) {- return fsEntryMeta.tagGroups;+ if (fsEntryMeta?.tagGroups) {+ // Stamp locationId and inherit workSpaceId from the parent location+ // so workspace-filter logic can match location-stored tag groups.+ // An explicit workSpaceId on the tag group wins over the location's.+ return fsEntryMeta.tagGroups.map((g) => ({+ ...g,+ locationId: location.uuid,+ workSpaceId: g.workSpaceId ?? location.workSpaceId,+ }));}return undefined;},@@ -305,7 +312,12 @@ export const TagGroupsLocationContextProvider = ({const newTagGroup = { ...tagGroup, children: oldTagGroup.children };let tagGroups;if (fsEntryMeta.tagGroups && fsEntryMeta.tagGroups.length > 0) {- tagGroups = [...fsEntryMeta.tagGroups, newTagGroup];+ tagGroups = [+ ...fsEntryMeta.tagGroups.filter(+ (group) => group.uuid !== tagGroup.uuid,+ ),+ newTagGroup,+ ];} else {tagGroups = [newTagGroup];}