TagSpaces is an offline, open source, document manager with tagging support
fix #2196 adding tags to taglibrary with context menu and dnd (#2197)
Stanimirafd7893b2b67
diff --git a/package-lock.json b/package-lock.jsonindex 1782aa91f..2ce8ffe59 100644--- a/package-lock.json+++ b/package-lock.json@@ -196,7 +196,7 @@"yarn": "please-use-npm"},"optionalDependencies": {- "@tagspacespro/tagspacespro": "5.0.79"+ "@tagspacespro/tagspacespro": "5.0.81"}},"node_modules/@adobe/css-tools": {@@ -17232,9 +17232,9 @@}},"node_modules/@tagspacespro/tagspacespro": {- "version": "5.0.79",- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.79/a5e4a9a1d40b70e927d26efcf688b385d6d7342c",- "integrity": "sha512-H5GIeZYY2eFKnl/xw1sjcSyVYf3sJNKhZjWz9LbFqcXaed81wLk2ybhx5ZbjkP+4PHtsxvPgRWTKUvij9vKVzg==",+ "version": "5.0.81",+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.81/a9ee401fdfa1fdae966991037bb310000c1590df",+ "integrity": "sha512-NzxWXAH5fWjMLk8+dKvHpZQ6AmNElQRAtlbtcIPlmS7O4j5fVWumyA7hwb3e/RCCUqvTHZAE+VwygmuE0112HA==","license": "Proprietary","optional": true},diff --git a/package.json b/package.jsonindex aa7e980f3..6840d0096 100644--- a/package.json+++ b/package.json@@ -233,7 +233,7 @@"uuid": "^9.0.0"},"optionalDependencies": {- "@tagspacespro/tagspacespro": "5.0.79"+ "@tagspacespro/tagspacespro": "5.0.81"},"devDependencies": {"@electron/notarize": "^2.3.2",diff --git a/src/renderer/components/TagContainerDnd.tsx b/src/renderer/components/TagContainerDnd.tsxindex e9d49ac2a..c07203b40 100644--- a/src/renderer/components/TagContainerDnd.tsx+++ b/src/renderer/components/TagContainerDnd.tsx@@ -86,11 +86,11 @@ const TagContainerDnd = (props: Props) => {// console.log('DropRESULT: ', dropResult);if (dropResult &&- dropResult.tagGroupId &&- tagGroup &&- dropResult.tagGroupId !== tagGroup.uuid+ dropResult.tagGroupId+ //tagGroup &&+ //dropResult.tagGroupId !== tagGroup.uuid) {- if (moveTag) {+ if (moveTag && tagGroup) {// console.log(`Dropped ${item.tagId} from ${tagGroup.uuid} into ${dropResult.tagGroupId}!`);moveTag(item.tag.title, tagGroup.uuid, dropResult.tagGroupId);} else if (addTag) {diff --git a/src/renderer/components/TagContainerMenu.tsx b/src/renderer/components/TagContainerMenu.tsxindex 3747640fb..a49e1b3c1 100644--- a/src/renderer/components/TagContainerMenu.tsx+++ b/src/renderer/components/TagContainerMenu.tsx@@ -42,7 +42,7 @@ function TagContainerMenu(props: Props) {return tagMode === 'remove' ? (deleteIcon || (<RemoveTagIcon- data-tid={'tagRemoveButton_' + tag.title.replace(/ /g, '_')}+ data-tid={'tagRemoveButton_' + tag.title?.replace(/ /g, '_')}style={{color: tag.textcolor,fontSize: 20,@@ -54,7 +54,7 @@ function TagContainerMenu(props: Props) {)) : (<MoreVertIcon- data-tid={'tagMoreButton_' + tag.title.replace(/ /g, '_')}+ data-tid={'tagMoreButton_' + tag.title?.replace(/ /g, '_')}style={{color: tag.textcolor,marginLeft: -5,diff --git a/src/renderer/components/dialogs/AddTagToTagGroupDialog.tsx b/src/renderer/components/dialogs/AddTagToTagGroupDialog.tsxindex 809ea6b99..db3931d67 100644--- a/src/renderer/components/dialogs/AddTagToTagGroupDialog.tsx+++ b/src/renderer/components/dialogs/AddTagToTagGroupDialog.tsx@@ -63,7 +63,7 @@ function AddTagToTagGroupDialog(props: Props) {if (!selectedTag.color) {selectedTag.color = defaultBackgroundColor;}- addTag(selectedTag, tagGroup);+ addTag([selectedTag], tagGroup);//dispatch(AppActions.addTag(selectedTag, tagGroup));props.onClose();};diff --git a/src/renderer/components/dialogs/CreateTagsDialog.tsx b/src/renderer/components/dialogs/CreateTagsDialog.tsxindex 11d1756bd..ea102ae26 100644--- a/src/renderer/components/dialogs/CreateTagsDialog.tsx+++ b/src/renderer/components/dialogs/CreateTagsDialog.tsx@@ -30,6 +30,7 @@ import { TS } from '-/tagspaces.namespace';import DialogCloseButton from '-/components/dialogs/DialogCloseButton';import { useTranslation } from 'react-i18next';import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';+import { parseNewTags } from '-/services/utils-io';interface Props {open: boolean;@@ -75,7 +76,8 @@ function CreateTagsDialog(props: Props) {const onConfirm = () => {if (!inputError) {- addTag(tagTitle, selectedTagGroupEntry.uuid);+ const newTags = parseNewTags(tagTitle, selectedTagGroupEntry);+ addTag(newTags, selectedTagGroupEntry.uuid);onClose();}};diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsxindex 5360b3f2a..0367e0eef 100644--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx@@ -39,7 +39,6 @@ import {getTagDelimiter,getTagTextColor,} from '-/reducers/settings';-import { parseNewTags } from '-/services/utils-io';import {extractContainingDirectoryPath,extractFileName,@@ -88,7 +87,7 @@ type TaggingActionsContextData = {) => Promise<boolean>;mergeTagGroup: (entry: TS.TagGroup) => void;removeTagGroup: (parentTagGroupUuid: TS.Uuid) => void;- addTag: (tag: any, parentTagGroupUuid: TS.Uuid) => void;+ addTag: (tag: TS.Tag[], parentTagGroupUuid: TS.Uuid) => void;editTag: (tag: TS.Tag,parentTagGroupUuid: TS.Uuid,@@ -1221,33 +1220,26 @@ export const TaggingActionsContextProvider = ({}}- function addTag(tag: any, parentTagGroupUuid: TS.Uuid) {+ /**+ * Add tag to tagGroup+ * @param tag+ * @param parentTagGroupUuid - tagGroup ID to add in+ */+ function addTag(tags: TS.Tag[], parentTagGroupUuid: TS.Uuid) {const tgIndex = tagGroups.findIndex((tagGroup) => tagGroup.uuid === parentTagGroupUuid,);if (tgIndex > -1) {const tagGroup = tagGroups[tgIndex];- let newTags: Array<TS.Tag>;- if (typeof tag === 'object' && tag !== null) {- if (tagGroup.children.some((t) => t.title === tag.title)) {- // tag exist- return;- }- const tagObject: TS.Tag = {++ const newTags = [+ ...tagGroup.children,+ ...tags.map((tag) => ({...tag,- textcolor: tag.textcolor, // || tagTextColor,- color: tag.color, // || tagBackgroundColor- };- newTags = [tagObject];- //tagGroupsReturn = saveTagInt(tagObject, parentTagGroupUuid, tagGroups);- } else {- const newTagGroup = {- ...tagGroup,- color: tagGroup.color, // ? tagGroup.color : tagBackgroundColor,- textcolor: tagGroup.textcolor, // ? tagGroup.textcolor : tagTextColor- };- newTags = parseNewTags(tag, newTagGroup);- }+ ...(!tag.color && { color: tagGroup.color }),+ ...(!tag.textcolor && { textcolor: tagGroup.textcolor }),+ })),+ ];saveTags(newTags, tgIndex);if (Pro && tagGroup && tagGroup.locationId) {diff --git a/src/renderer/perspectives/grid/components/GridCell.tsx b/src/renderer/perspectives/grid/components/GridCell.tsxindex 5c2863053..afd6c67b1 100644--- a/src/renderer/perspectives/grid/components/GridCell.tsx+++ b/src/renderer/perspectives/grid/components/GridCell.tsx@@ -235,7 +235,7 @@ function GridCell(props: Props) {};const handleAddTag = (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => {- addTag(tag, parentTagGroupUuid);+ addTag([tag], parentTagGroupUuid);};// remove isNewFile on Cell click it will open file in editModediff --git a/src/renderer/perspectives/list/components/RowCell.tsx b/src/renderer/perspectives/list/components/RowCell.tsxindex 841bf7f19..558529345 100644--- a/src/renderer/perspectives/list/components/RowCell.tsx+++ b/src/renderer/perspectives/list/components/RowCell.tsx@@ -148,7 +148,7 @@ function RowCell(props: Props) {};const handleAddTag = (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => {- addTag(tag, parentTagGroupUuid);+ addTag([tag], parentTagGroupUuid);};// remove isNewFile on Cell click it will open file in editModediff --git a/src/renderer/services/utils-io.ts b/src/renderer/services/utils-io.tsindex e1d06a79d..f34ef2341 100644--- a/src/renderer/services/utils-io.ts+++ b/src/renderer/services/utils-io.ts@@ -338,22 +338,20 @@ export function parseNewTags(tagsInput: string, tagGroup: TS.TagGroup) {// filter out duplicated tagstags = tags.filter((t) => t !== tag.title);});- return taggroupTags.concat(- tags.map((tagTitle) => {- const tag: TS.Tag = {- type: taggroupTags.length > 0 ? taggroupTags[0].type : 'sidecar',- title: tagTitle.trim(),- functionality: '',- description: '',- icon: '',- color: tagGroup.color,- textcolor: tagGroup.textcolor,- style: taggroupTags.length > 0 ? taggroupTags[0].style : '',- modified_date: new Date().getTime(),- };- return tag;- }),- );+ return tags.map((tagTitle) => {+ const tag: TS.Tag = {+ //type: taggroupTags.length > 0 ? taggroupTags[0].type : 'sidecar',+ title: tagTitle.trim(),+ //functionality: '',+ //description: '',+ //icon: '',+ color: tagGroup.color,+ textcolor: tagGroup.textcolor,+ //style: taggroupTags.length > 0 ? taggroupTags[0].style : '',+ modified_date: new Date().getTime(),+ };+ return tag;+ });}}