TagSpaces is an offline, open source, document manager with tagging support
Disable dropping tags in read-only tag groups (#2287)
Stanimirad1aec3129d4
diff --git a/.gitignore b/.gitignoreindex b982f3c51..ef9e0bf8c 100644--- a/.gitignore+++ b/.gitignore@@ -137,3 +137,4 @@ txtagspsacesprothird-party+extconfig.jsdiff --git a/src/renderer/components/EditDescriptionButtons.tsx b/src/renderer/components/EditDescriptionButtons.tsxindex 4f291a231..4f2dd664b 100644--- a/src/renderer/components/EditDescriptionButtons.tsx+++ b/src/renderer/components/EditDescriptionButtons.tsx@@ -15,6 +15,7 @@ import { formatDateTime4Tag } from '@tagspaces/tagspaces-common/misc';import { extractTitle } from '@tagspaces/tagspaces-common/paths';import React from 'react';import { useTranslation } from 'react-i18next';+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';interface ButtonsProps {getHtml: () => string;@@ -29,6 +30,7 @@ const EditDescriptionButtons: React.FC<ButtonsProps> = ({ getHtml }) => {isEditDescriptionMode,setEditDescriptionMode,} = useFilePropertiesContext();+ const { findLocation } = useCurrentLocationContext();const { openedEntry, reloadOpenedFile } = useOpenedEntryContext();const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);const theme = useTheme();@@ -147,7 +149,11 @@ const EditDescriptionButtons: React.FC<ButtonsProps> = ({ getHtml }) => {<ProTooltip tooltip={!isEditDescriptionMode && t('editDescription')}><TsButtondata-tid="editDescriptionTID"- disabled={!Pro || isEditMode}+ disabled={+ !Pro ||+ isEditMode ||+ findLocation(openedEntry.locationID)?.isReadOnly+ }style={{borderTopLeftRadius: isEditDescriptionMode? 0diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsxindex 3ad1a0250..389c459d4 100644--- a/src/renderer/components/EntryProperties.tsx+++ b/src/renderer/components/EntryProperties.tsx@@ -383,8 +383,10 @@ function EntryProperties(props: Props) {color = 'transparent';}//openedEntry.color = color;- setBackgroundColorChange(openedEntry, color).then(() => {- openedEntry.meta = { ...openedEntry.meta, color };+ setBackgroundColorChange(openedEntry, color).then((success) => {+ if (success) {+ openedEntry.meta = { ...openedEntry.meta, color };+ }});};diff --git a/src/renderer/components/FolderContainer.tsx b/src/renderer/components/FolderContainer.tsxindex d12cbfd11..af795e4a2 100644--- a/src/renderer/components/FolderContainer.tsx+++ b/src/renderer/components/FolderContainer.tsx@@ -29,6 +29,7 @@ import { useFileUploadDialogContext } from '-/components/dialogs/hooks/useFileUpimport { useProTeaserDialogContext } from '-/components/dialogs/hooks/useProTeaserDialogContext';import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';import { useBrowserHistoryContext } from '-/hooks/useBrowserHistoryContext';+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { AvailablePerspectives, PerspectiveIDs } from '-/perspectives';@@ -69,13 +70,13 @@ function FolderContainer(props: Props) {const { t } = useTranslation();const theme = useTheme();const keyBindings = useSelector(getKeyBindingObject);+ const { findLocation } = useCurrentLocationContext();const { goForward, goBack, historyIndex } = useBrowserHistoryContext();const { openFileUploadDialog } = useFileUploadDialogContext();const { openProTeaserDialog } = useProTeaserDialogContext();const { openEntry } = useOpenedEntryContext();const aiDefaultProvider: AIProvider = useSelector(getDefaultAIProvider);const {- setSearchQuery,currentDirectoryEntries,currentDirectoryPath,getPerspective,@@ -187,6 +188,7 @@ function FolderContainer(props: Props) {const openSearchKeyBinding = `${adjustKeyBinding(keyBindings.openSearch)}`;const smallScreen = useMediaQuery(theme.breakpoints.down('md'));+ const readOnlyLocation = findLocation()?.isReadOnly;return (<div@@ -358,24 +360,34 @@ function FolderContainer(props: Props) {>{perspectiveToggleButtons}{aiDefaultProvider && (- <ToggleButton- value=""- aria-label="chat-label"- data-tid="chatTID"- style={{- marginLeft: 5,- borderColor: theme.palette.divider,- color: theme.palette.primary.main,- backgroundColor: theme.palette.background.default,- }}- onClick={() => {- openEntry(currentDirectoryPath, TabNames.aiTab);- }}+ <Tooltip+ title={+ readOnlyLocation+ ? t('core:aiChatForFolderDisabled')+ : t('core:aiChatForFolder')+ }>- <Tooltip title="AI Chat for this folder">+ <ToggleButton+ value=""+ // disabled={readOnlyLocation}+ aria-label="chat-label"+ data-tid="chatTID"+ style={{+ marginLeft: 5,+ borderColor: theme.palette.divider,+ ...(!readOnlyLocation && {+ color: theme.palette.primary.main,+ }),+ backgroundColor: theme.palette.background.default,+ }}+ onClick={() => {+ if (readOnlyLocation) return;+ openEntry(currentDirectoryPath, TabNames.aiTab);+ }}+ ><ChatIcon />- </Tooltip>- </ToggleButton>+ </ToggleButton>+ </Tooltip>)}</ToggleButtonGroup>)}diff --git a/src/renderer/components/TagGroupTitleDnD.tsx b/src/renderer/components/TagGroupTitleDnD.tsxindex f245fc25f..06ed3a5e1 100644--- a/src/renderer/components/TagGroupTitleDnD.tsx+++ b/src/renderer/components/TagGroupTitleDnD.tsx@@ -125,6 +125,8 @@ function TagGroupTitleDnD(props: Props) {return '';}+ const readOnly = tagGroup.readOnly ? 'read-only ' : '';+const tagGroupTitle = (<Boxdata-tid={'tagLibraryTagGroupTitle_' + tagGroup.title}@@ -133,7 +135,12 @@ function TagGroupTitleDnD(props: Props) {height: '100%',borderRadius: AppConfig.defaultCSSRadius,}}- title={'Number of tags in this tag group: ' + tagGroup.children.length}+ title={+ 'Number of tags in this ' ++ readOnly ++ 'tag group: ' ++ tagGroup.children.length+ }><Gridcontainerdiff --git a/src/renderer/components/TagLibrary.tsx b/src/renderer/components/TagLibrary.tsxindex 07cf2339d..3840e89a7 100644--- a/src/renderer/components/TagLibrary.tsx+++ b/src/renderer/components/TagLibrary.tsx@@ -108,9 +108,6 @@ function TagLibrary(props: Props) {const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);const firstRender = useFirstRender();- const isTagLibraryReadOnly =- window.ExtTagLibrary && window.ExtTagLibrary.length > 0;-useEffect(() => {if (Pro && saveTagInLocation && firstRender) {refreshTagsFromLocation();@@ -227,7 +224,7 @@ function TagLibrary(props: Props) {handleTagGroupMenu={handleTagGroupMenu}toggleTagGroup={toggleTagGroupDispatch}tagGroupCollapsed={tagGroupCollapsed}- isReadOnly={tagGroup.readOnly || isTagLibraryReadOnly}+ isReadOnly={tagGroup.readOnly}/><Collapse in={tagGroup.expanded} unmountOnExit><TagGroupContainer taggroup={tagGroup}>@@ -293,7 +290,7 @@ function TagLibrary(props: Props) {' tag groups'}menuButton={- !isTagLibraryReadOnly && (+ tagGroups.some((tg) => !tg.readOnly) && (<TsIconButtondata-tid="tagLibraryMenu"onClick={handleTagLibraryMenu}diff --git a/src/renderer/components/chat/AiGenDescButton.tsx b/src/renderer/components/chat/AiGenDescButton.tsxindex 2f6c4aaab..ac70632b1 100644--- a/src/renderer/components/chat/AiGenDescButton.tsx+++ b/src/renderer/components/chat/AiGenDescButton.tsx@@ -32,6 +32,7 @@ import { useState } from 'react';import { useTranslation } from 'react-i18next';import { useDispatch } from 'react-redux';import { AIIcon } from '../CommonIcons';+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';type Props = TSButtonProps & {};@@ -40,6 +41,7 @@ function AiGenDescButton(props: Props) {const { disabled } = props;const dispatch: AppDispatch = useDispatch();//const defaultAiProvider: AIProvider = useSelector(getDefaultAIProvider);+ const { findLocation } = useCurrentLocationContext();const { openedEntry } = useOpenedEntryContext();const { setDescriptionChange } = useIOActionsContext();const { descriptionGenerate } = useChatContext();@@ -50,7 +52,11 @@ function AiGenDescButton(props: Props) {const [isLoading, setIsLoading] = useState<boolean>(false);//const openedEntryModel = getEntryModel(openedEntry?.name, defaultAiProvider);- if (!openedEntry || !openedEntry.isFile) {+ if (+ !openedEntry ||+ !openedEntry.isFile ||+ findLocation(openedEntry.locationID)?.isReadOnly+ ) {//|| !openedEntryModel) {return null;}diff --git a/src/renderer/components/chat/AiGenTagsButton.tsx b/src/renderer/components/chat/AiGenTagsButton.tsxindex d5bf1d16f..dee910675 100644--- a/src/renderer/components/chat/AiGenTagsButton.tsx+++ b/src/renderer/components/chat/AiGenTagsButton.tsx@@ -32,6 +32,7 @@ import { useState } from 'react';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';import { AIIcon } from '../CommonIcons';+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';type Props = TSButtonProps & {variant?: OverridableStringUnion<@@ -48,6 +49,7 @@ function AiGenTagsButton(props: Props) {const { fromDescription, variant, disabled, entries, generationCompleted } =props;const { t } = useTranslation();+ const { findLocation } = useCurrentLocationContext();const { openedEntry } = useOpenedEntryContext();const { tagsGenerate, checkOllamaModels } = useChatContext();const { openAiGenerationDialog } = useAiGenerationDialogContext();@@ -70,7 +72,12 @@ function AiGenTagsButton(props: Props) {].includes(entry.extension),);- if (!generateEntries || !defaultAiProvider || !extensionSupported) {+ if (+ !generateEntries ||+ !defaultAiProvider ||+ !extensionSupported ||+ findLocation(openedEntry?.locationID)?.isReadOnly+ ) {return null;}diff --git a/src/renderer/components/menus/TagMenu.tsx b/src/renderer/components/menus/TagMenu.tsxindex 305b459e9..7febec3ca 100644--- a/src/renderer/components/menus/TagMenu.tsx+++ b/src/renderer/components/menus/TagMenu.tsx@@ -34,9 +34,6 @@ import MenuItem from '@mui/material/MenuItem';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';-const isTagLibraryReadOnly =- window.ExtTagLibrary && window.ExtTagLibrary.length > 0;-interface Props {anchorEl?: Element;open?: boolean;@@ -121,7 +118,7 @@ function TagMenu(props: Props) {<ListItemText primary={t('core:applyTag')} /></MenuItem>)}- {!tagGroupReadOnly && !isSmartTag && !isTagLibraryReadOnly && (+ {!tagGroupReadOnly && !isSmartTag && (<MenuItem data-tid="editTagDialog" onClick={showEditTagMenuDialog}><ListItemIcon><Edit />@@ -129,7 +126,7 @@ function TagMenu(props: Props) {<ListItemText primary={t('core:editTag')} /></MenuItem>)}- {!tagGroupReadOnly && !isSmartTag && !isTagLibraryReadOnly && (+ {!tagGroupReadOnly && !isSmartTag && (<MenuItem data-tid="deleteTagDialog" onClick={openDeleteTagDialog}><ListItemIcon><DeleteIcon />diff --git a/src/renderer/hooks/EntryPropsTabsContextProvider.tsx b/src/renderer/hooks/EntryPropsTabsContextProvider.tsxindex 7aff64811..a3ba2969b 100644--- a/src/renderer/hooks/EntryPropsTabsContextProvider.tsx+++ b/src/renderer/hooks/EntryPropsTabsContextProvider.tsx@@ -118,7 +118,7 @@ export const EntryPropsTabsContextProvider = ({}async function getTabsArray(oEntry: TS.OpenedEntry): Promise<TabItem[]> {- //const location: CommonLocation = findLocation(oEntry.locationID);+ const openedLocation: CommonLocation = findLocation(oEntry.locationID);const tab1: TabItem = {icon: <EntryPropertiesIcon />,title: t('core:details'),@@ -147,12 +147,14 @@ export const EntryPropsTabsContextProvider = ({}if ((oEntry && !oEntry.isFile) || (devMode && Pro)) {- const tab4: TabItem = {- icon: <AIIcon />,- title: oEntry.isFile ? t('core:aiSettingsTab') : t('core:aiChatTab'),- name: TabNames.aiTab,- };- tabsArray.push(tab4);+ if (!openedLocation.isReadOnly) {+ const tab4: TabItem = {+ icon: <AIIcon />,+ title: oEntry.isFile ? t('core:aiSettingsTab') : t('core:aiChatTab'),+ name: TabNames.aiTab,+ };+ tabsArray.push(tab4);+ }}const tab5: TabItem = {icon: <LinkIcon />,diff --git a/src/renderer/hooks/FilePropertiesContextProvider.tsx b/src/renderer/hooks/FilePropertiesContextProvider.tsxindex 10a3406a6..69680bcaa 100644--- a/src/renderer/hooks/FilePropertiesContextProvider.tsx+++ b/src/renderer/hooks/FilePropertiesContextProvider.tsx@@ -86,6 +86,16 @@ export const FilePropertiesContextProvider = ({useEffect(() => {if (openedEntry) {+ const openedLocation = findLocation(openedEntry.locationID);+ if (openedLocation) {+ if (openedLocation.isReadOnly) {+ if (isEditDescriptionMode) {+ setIsEditDescriptionMode(false);+ }+ } else if (!isEditDescriptionMode) {+ setIsEditDescriptionMode(true);+ }+ }if (isDescriptionChanged.current) {// handle not saved changessaveDescriptionConfirmOpened(true);diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsxindex 8859b0c0e..0cafd49d0 100644--- a/src/renderer/hooks/IOActionsContextProvider.tsx+++ b/src/renderer/hooks/IOActionsContextProvider.tsx@@ -1687,12 +1687,18 @@ export const IOActionsContextProvider = ({{ path: metaFilePath, locationID: entry.locationID },content,true,- ).then((success) => {- if (success) {- reflectUpdateSidecarMeta(entry.path, meta);- }- return meta;- });+ )+ .then((success) => {+ if (success) {+ reflectUpdateSidecarMeta(entry.path, meta);+ }+ return meta;+ })+ .catch((err) => {+ console.log('Error ' + entry.path + ' with ' + err);+ showNotification('Error: ' + err.message, 'error', true);+ return undefined;+ });}return Promise.reject(new Error('file not found' + entry.path));}diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsxindex 3ef1fae8a..ed29551f6 100644--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx@@ -1237,6 +1237,14 @@ export const TaggingActionsContextProvider = ({indexToGroup = index;}});+ if (tagGroups[indexToGroup] && tagGroups[indexToGroup].readOnly) {+ showNotification(+ 'Error move tag. Read only Tag Group: ' + tagGroups[indexToGroup].title,+ 'error',+ true,+ );+ return;+ }if (indexFromGroup >= 0 && tagGroups[indexFromGroup].children) {tagIndexForRemoving = tagGroups[indexFromGroup].children.findIndex((tag) => tag.title === tagTitle,@@ -1252,16 +1260,18 @@ export const TaggingActionsContextProvider = ({);if (!found) {newTagLibrary[indexToGroup].children.push(tag);- newTagLibrary[indexFromGroup].children = [- ...newTagLibrary[indexFromGroup].children.slice(- 0,- tagIndexForRemoving,- ),- ...newTagLibrary[indexFromGroup].children.slice(- tagIndexForRemoving + 1,- ),- ];- return saveTagLibrary(newTagLibrary);+ if (!newTagLibrary[indexFromGroup].readOnly) {+ newTagLibrary[indexFromGroup].children = [+ ...newTagLibrary[indexFromGroup].children.slice(+ 0,+ tagIndexForRemoving,+ ),+ ...newTagLibrary[indexFromGroup].children.slice(+ tagIndexForRemoving + 1,+ ),+ ];+ }+ saveTagLibrary(newTagLibrary);}console.log('Tag with this title already exists in the target tag group');}diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.jsonindex ab1467479..b00c0458f 100644--- a/src/renderer/locales/en/core.json+++ b/src/renderer/locales/en/core.json@@ -909,6 +909,8 @@"engineName": "AI Engine Name","maxCollectedTag": "Max Collected Tag","aiChatTab": "AI Chat",+ "aiChatForFolder": "AI Chat for this folder",+ "aiChatForFolderDisabled": "AI Chat disabled for read-only folders","yourMessageForAI": "Your message for the AI","links": "Links","outgoingLinks": "Outgoing Links",diff --git a/src/renderer/services/taglibrary-utils.ts b/src/renderer/services/taglibrary-utils.tsindex a5e53c437..bdb89fe88 100644--- a/src/renderer/services/taglibrary-utils.ts+++ b/src/renderer/services/taglibrary-utils.ts@@ -11,7 +11,10 @@ export const tagLibraryKey = 'tsTagLibrary';export function getTagLibrary(): TS.TagGroup[] {if (window.ExtTagLibrary) {- return window.ExtTagLibrary;+ return window.ExtTagLibrary.map((tagGroup) => ({+ ...tagGroup,+ readOnly: true,+ }));}const item = localStorage.getItem(tagLibraryKey);if (item) {