TagSpaces is an offline, open source, document manager with tagging support
Tags to readonly locations changes (#2286)
Stanimir391fd3d644d8
diff --git a/src/renderer/components/TagContainerMenu.tsx b/src/renderer/components/TagContainerMenu.tsxindex bef8f95b8..29a169721 100644--- a/src/renderer/components/TagContainerMenu.tsx+++ b/src/renderer/components/TagContainerMenu.tsx@@ -17,7 +17,6 @@*/import { MoreMenuIcon, RemoveIcon } from '-/components/CommonIcons';-import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { TS } from '-/tagspaces.namespace';interface Props {@@ -28,11 +27,11 @@ interface Props {}function TagContainerMenu(props: Props) {- const { readOnlyMode } = useCurrentLocationContext();+ //const { readOnlyMode } = useCurrentLocationContext();const { deleteIcon, tag, handleRemoveTag, tagMode } = props;- if (readOnlyMode) {+ /*if (readOnlyMode) {return <div style={{ width: 10 }} />;- }+ }*/if (tagMode === 'display') {return <div style={{ width: 10 }} />;}diff --git a/src/renderer/components/TagLibrary.tsx b/src/renderer/components/TagLibrary.tsxindex b29eafc36..07cf2339d 100644--- a/src/renderer/components/TagLibrary.tsx+++ b/src/renderer/components/TagLibrary.tsx@@ -19,7 +19,6 @@import AppConfig from '-/AppConfig';import { MoreMenuIcon } from '-/components/CommonIcons';import SidePanelTitle from '-/components/SidePanelTitle';-import TagContainer from '-/components/TagContainer';import TagContainerDnd from '-/components/TagContainerDnd';import TagGroupContainer from '-/components/TagGroupContainer';import TagGroupTitleDnD from '-/components/TagGroupTitleDnD';@@ -75,13 +74,12 @@ function TagLibrary(props: Props) {} = useTaggingActionsContext();const { getTagGroups } = useTagGroupsLocationContext();const { selectedEntries } = useSelectedEntriesContext();- const { readOnlyMode, findLocation, locations } = useCurrentLocationContext();+ const { findLocation, locations } = useCurrentLocationContext();const { tagGroups } = useEditedTagLibraryContext();const dispatch: AppDispatch = useDispatch();const tagBackgroundColor = useSelector(getTagColor);const tagTextColor = useSelector(getTagTextColor);const tagGroupCollapsed: Array<string> = useSelector(getTagGroupCollapsed);- //const locations: Array<CommonLocation> = useSelector(getLocations);const toggleTagGroupDispatch = (uuid) =>dispatch(SettingsActions.toggleTagGroup(uuid));@@ -156,11 +154,6 @@ function TagLibrary(props: Props) {) => {setTagGroupMenuAnchorEl(event.currentTarget);setSelectedTagGroupEntry(tagGroup);- /* this.setState({- tagGroupMenuOpened: true,- tagGroupMenuAnchorEl: event.currentTarget,- selectedTagGroupEntry: tagGroup- }); */};const handleTagMenuCallback = useCallback(@@ -192,10 +185,6 @@ function TagLibrary(props: Props) {const handleTagLibraryMenu = (event: any) => {setTagLibraryMenuAnchorEl(event.currentTarget);- /* this.setState({- tagLibraryMenuOpened: true,- tagLibraryMenuAnchorEl: event.currentTarget- }); */};const showCreateTagGroupDialog = () => {@@ -246,17 +235,6 @@ function TagLibrary(props: Props) {tagGroup.children.map((tag: TS.Tag, idx) => {const isSmartTag =tag.functionality && tag.functionality.length > 0;- if (readOnlyMode) {- return (- <TagContainer- key={tagGroup.uuid + tag.title}- tag={tag}- tagGroup={tagGroup}- tagMode={isSmartTag ? 'display' : 'default'}- handleTagMenu={handleTagMenuCallback}- />- );- }return (<TagContainerDndkey={tagGroup.uuid + tag.title}diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsxindex e65ce9ce5..8859b0c0e 100644--- a/src/renderer/hooks/IOActionsContextProvider.tsx+++ b/src/renderer/hooks/IOActionsContextProvider.tsx@@ -1544,7 +1544,7 @@ export const IOActionsContextProvider = ({.catch((error) => {console.log(`Error while renaming file ${filePath}`, error);showNotification(- `Error while renaming file ${filePath}`,+ `Error while renaming file ${filePath}: ` + error.message,'error',true,);diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsxindex ccb14e798..3ef1fae8a 100644--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx@@ -372,6 +372,91 @@ export const TaggingActionsContextProvider = ({return Promise.resolve(true);}+ function saveMataDataTags(+ entry: TS.FileSystemEntry,+ updatedFsEntryMeta: TS.FileSystemEntryMeta,+ reflect = true,+ ): Promise<TS.FileSystemEntry> {+ return saveMetaDataPromise(entry, updatedFsEntryMeta)+ .then((meta) => {+ if (reflect) {+ reflectUpdateMeta({ ...entry, meta });+ }+ return { ...entry, meta };+ })+ .catch((err) => {+ console.log('Error adding tags for ' + entry.path + ' with ' + err);+ showNotification(+ t('core:addingTagsFailed') + ': ' + err.message,+ 'error',+ true,+ );+ return entry;+ });+ }++ function renameFileTags(+ entry: TS.FileSystemEntry,+ newFilePath: string,+ reflect = true,+ ): Promise<TS.FileSystemEntry> {+ return renameFile(entry.path, newFilePath, entry.locationID, reflect)+ .then((success) => {+ return success+ ? {+ ...entry,+ tags: extractTagsAsObjects(+ newFilePath,+ tagDelimiter,+ currentLocation?.getDirSeparator(),+ ),+ name: extractFileName(+ newFilePath,+ currentLocation?.getDirSeparator(),+ ),+ path: newFilePath,+ }+ : undefined;+ })+ .catch((err) => {+ console.log('Error adding tags for ' + entry.path + ' with ' + err);+ showNotification(+ t('core:addingTagsFailed') + ': ' + err.message,+ 'error',+ true,+ );+ return entry;+ });+ }++ function getNonExistingTags(+ newTagsArray: Array<TS.Tag>,+ fileTagsArray: string[],+ sideCarTagsArray: Array<TS.Tag>,+ ): TS.Tag[] {+ const newTags = [];+ if (newTagsArray) {+ for (let i = 0; i < newTagsArray.length; i += 1) {+ // check if tag is already in the fileTagsArray+ if (+ !fileTagsArray ||+ fileTagsArray.indexOf(newTagsArray[i].title) === -1+ ) {+ // check if tag is already in the sideCarTagsArray+ if (+ !sideCarTagsArray ||+ sideCarTagsArray.findIndex(+ (sideCarTag) => sideCarTag.title === newTagsArray[i].title,+ ) === -1+ ) {+ newTags.push(newTagsArray[i]);+ }+ }+ }+ }+ return newTags;+ }+/*** @param entry: TS.FileSystemEntry* @param tags@@ -389,14 +474,6 @@ export const TaggingActionsContextProvider = ({if (collectTags) {collectTagsToLibrary(tags);}- /*let fsEntryMeta;- try {- fsEntryMeta = entry.isFile- ? await currentLocation.loadFileMetaDataPromise(entry.path)- : await currentLocation.loadDirMetaDataPromise(entry.path);- } catch (error) {- console.log('No sidecar found ' + error);- }*/if (!entry.isFile || persistTagsInSidecarFile) {// Handling adding tags in sidecar@@ -425,45 +502,14 @@ export const TaggingActionsContextProvider = ({...entry.meta,tags: newTags,};- return saveMetaDataPromise(entry, updatedFsEntryMeta)- .then(() => {- if (reflect) {- reflectUpdateMeta({ ...entry, meta: updatedFsEntryMeta });- }- return { ...entry, meta: updatedFsEntryMeta };- })- .catch((err) => {- console.log(- 'Error adding tags for ' + entry.path + ' with ' + err,- );- showNotification(- t('core:addingTagsFailed' as any) as string,- 'error',- true,- );- return entry;- });+ return saveMataDataTags(entry, updatedFsEntryMeta, reflect);}} else {- const newFsEntryMeta = { tags };- return saveMetaDataPromise(entry, newFsEntryMeta)- .then((meta) => {- if (reflect) {- reflectUpdateMeta({ ...entry, meta });- }- return { ...entry, meta };- })- .catch((error) => {- console.log(- 'Error adding tags for ' + entry.path + ' with ' + error,- );- showNotification(- t('core:addingTagsFailed' as any) as string,- 'error',- true,- );- return entry;- });+ const newFsEntryMeta: TS.FileSystemEntryMeta = {+ id: getUuid(),+ tags,+ };+ return saveMataDataTags(entry, newFsEntryMeta, reflect);}} else if (entry.meta) {// Handling tags in filename by existing sidecar@@ -483,28 +529,7 @@ export const TaggingActionsContextProvider = ({uniqueTags.map((tag) => tag.title),);if (entry.path !== newFilePath) {- return renameFile(- entry.path,- newFilePath,- entry.locationID,- reflect,- ).then((success) => {- return success- ? {- ...entry,- tags: extractTagsAsObjects(- newFilePath,- tagDelimiter,- currentLocation?.getDirSeparator(),- ),- name: extractFileName(- newFilePath,- currentLocation?.getDirSeparator(),- ),- path: newFilePath,- }- : undefined;- });+ return renameFileTags(entry, newFilePath, reflect);}}} else {@@ -514,59 +539,10 @@ export const TaggingActionsContextProvider = ({tags.map((tag) => tag.title),);if (entry.path !== newFilePath) {- return renameFile(- entry.path,- newFilePath,- entry.locationID,- reflect,- ).then((success) => {- return success- ? {- ...entry,- tags: extractTagsAsObjects(- newFilePath,- tagDelimiter,- currentLocation?.getDirSeparator(),- ),- name: extractFileName(- newFilePath,- currentLocation?.getDirSeparator(),- ),- path: newFilePath,- }- : undefined;- });+ return renameFileTags(entry, newFilePath, reflect);}}return Promise.resolve(entry);-- function getNonExistingTags(- newTagsArray: Array<TS.Tag>,- fileTagsArray: string[],- sideCarTagsArray: Array<TS.Tag>,- ): TS.Tag[] {- const newTags = [];- if (newTagsArray) {- for (let i = 0; i < newTagsArray.length; i += 1) {- // check if tag is already in the fileTagsArray- if (- !fileTagsArray ||- fileTagsArray.indexOf(newTagsArray[i].title) === -1- ) {- // check if tag is already in the sideCarTagsArray- if (- !sideCarTagsArray ||- sideCarTagsArray.findIndex(- (sideCarTag) => sideCarTag.title === newTagsArray[i].title,- ) === -1- ) {- newTags.push(newTagsArray[i]);- }- }- }- }- return newTags;- }}return Promise.resolve(undefined);}diff --git a/src/renderer/utils/CommonLocation.ts b/src/renderer/utils/CommonLocation.tsindex 08c55c220..2716178a7 100644--- a/src/renderer/utils/CommonLocation.ts+++ b/src/renderer/utils/CommonLocation.ts@@ -551,6 +551,9 @@ export class CommonLocation implements TS.Location {onProgress = undefined,force = false,): Promise<any> => {+ if (this.isReadOnly) {+ return Promise.reject(new Error('read only Location'));+ }if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.renameFilePromise(@@ -581,6 +584,9 @@ export class CommonLocation implements TS.Location {dirPath: string,newDirName: string,): Promise<any> => {+ if (this.isReadOnly) {+ return Promise.reject(new Error('read only Location'));+ }if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.renameDirectoryPromise(