Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix - Dragging a tag to a folder makes it disappear (#2260)

Stanimir479c9c3eb3f8
diff --git a/package.json b/package.json
index 35e7f2ee6..188136f8a 100644
--- a/package.json
+++ b/package.json
@@ -245,7 +245,7 @@
"zod-to-json-schema": "^3.24.1"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.118"
+ "@tagspacespro/tagspacespro": "5.0.119-alpha.0"
},
"devDependencies": {
"@electron/notarize": "^2.5.0",
diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsx
index d582640a4..7431f905c 100644
--- a/src/renderer/components/EntryProperties.tsx
+++ b/src/renderer/components/EntryProperties.tsx
@@ -166,8 +166,7 @@ function EntryProperties(props: Props) {
saveDirectoryPerspective,
} = useIOActionsContext();
const { metaActions } = useEditedEntryMetaContext();
- const { addTagsToFsEntry, removeTags, removeAllTags } =
- useTaggingActionsContext();
+ const { addTagsToFsEntry, removeTagsFromEntry } = useTaggingActionsContext();
const { findLocation, readOnlyMode } = useCurrentLocationContext();
const { showNotification } = useNotificationContext();
@@ -396,12 +395,12 @@ function EntryProperties(props: Props) {
if (action === 'remove-value') {
if (!value) {
// no tags left in the select element
- return removeAllTags([openedEntry.path]);
+ return removeTagsFromEntry(openedEntry);
} else {
- return removeTags([openedEntry.path], value);
+ return removeTagsFromEntry(openedEntry, value);
}
} else if (action === 'clear') {
- return removeAllTags([openedEntry.path]);
+ return removeTagsFromEntry(openedEntry);
}
// create-option or select-option
const tags =
@@ -553,7 +552,7 @@ function EntryProperties(props: Props) {
)}
</Grid>
<Grid size={12}>
- <TagDropContainer entryPath={openedEntry.path}>
+ <TagDropContainer entry={openedEntry}>
<TagsSelect
label={t('core:fileTags')}
dataTid="PropertiesTagsSelectTID"
diff --git a/src/renderer/components/TagContainerDnd.tsx b/src/renderer/components/TagContainerDnd.tsx
index c996ef78d..66f9f1190 100644
--- a/src/renderer/components/TagContainerDnd.tsx
+++ b/src/renderer/components/TagContainerDnd.tsx
@@ -108,7 +108,7 @@ const TagContainerDnd = (props: Props) => {
addTags(selectedEntries, [item.tag]);
} else {
addTags(
- [currentLocation.toFsEntry(dropResult.entryPath, true)],
+ [currentLocation.toFsEntry(dropResult.entryPath, dropResult.isFile)],
[item.tag],
);
}
diff --git a/src/renderer/components/TagDropContainer.tsx b/src/renderer/components/TagDropContainer.tsx
index 53af1e1b2..56c035378 100644
--- a/src/renderer/components/TagDropContainer.tsx
+++ b/src/renderer/components/TagDropContainer.tsx
@@ -23,8 +23,8 @@ import { TS } from '-/tagspaces.namespace';
interface Props {
children: ReactNode;
- entryPath: string;
- selectedEntries?: Array<TS.FileSystemEntry>;
+ entry?: TS.FileSystemEntry;
+ //selectedEntries?: Array<TS.FileSystemEntry>;
}
interface DragItem {
@@ -34,6 +34,7 @@ interface DragItem {
}
function TagDropContainer(props: Props) {
+ const { entry } = props;
const ref = useRef<HTMLDivElement>(null);
const [collectedProps, drop] = useDrop({
@@ -44,16 +45,18 @@ function TagDropContainer(props: Props) {
handlerId: monitor.getHandlerId(),
isActive,
canDrop: monitor.canDrop(),
- selectedEntries: props.selectedEntries,
- entryPath: props.entryPath,
+ //selectedEntries: props.selectedEntries,
+ entryPath: entry?.path,
+ isFile: entry?.isFile,
};
},
drop(item: DragItem, monitor: DropTargetMonitor) {
// console.log('DROP: ', item);
// console.log('DROP: ', monitor.canDrop());
return {
- selectedEntries: collectedProps.selectedEntries,
+ //selectedEntries: collectedProps.selectedEntries,
entryPath: collectedProps.entryPath,
+ isFile: collectedProps.isFile,
};
},
});
diff --git a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx
index 7191ccfe1..923647a01 100644
--- a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx
+++ b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx
@@ -55,8 +55,7 @@ function AddRemoveTagsDialog(props: Props) {
const selected = props.selected ? props.selected : selectedEntries;
const { findLocation } = useCurrentLocationContext();
- const { addTagsToFsEntries, removeTags, removeAllTags } =
- useTaggingActionsContext();
+ const { addTagsToFsEntries, removeTags } = useTaggingActionsContext();
const [newlyAddedTags, setNewlyAddedTags] = useState<TS.Tag[]>([]);
const inputTags = useRef<TS.Tag[]>([]);
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
@@ -116,16 +115,14 @@ function AddRemoveTagsDialog(props: Props) {
const removeTagsAction = () => {
if (selected && selected.length > 0) {
- const paths = selected.map((entry) => entry.path);
- removeTags(paths, [...newlyAddedTags, ...inputTags.current]);
+ removeTags(selected, [...newlyAddedTags, ...inputTags.current]);
}
onCloseDialog(true);
};
const removeAllTagsAction = () => {
if (selected && selected.length > 0) {
- const paths = selected.map((entry) => entry.path);
- removeAllTags(paths);
+ removeTags(selected);
}
onCloseDialog(true);
};
diff --git a/src/renderer/components/menus/EntryTagMenu.tsx b/src/renderer/components/menus/EntryTagMenu.tsx
index 48269d919..a3c16a9de 100644
--- a/src/renderer/components/menus/EntryTagMenu.tsx
+++ b/src/renderer/components/menus/EntryTagMenu.tsx
@@ -56,7 +56,8 @@ function EntryTagMenu(props: Props) {
const { t } = useTranslation();
const { setSearchQuery } = useDirectoryContentContext();
- const { removeTags, openEditEntryTagDialog } = useTaggingActionsContext();
+ const { removeTagsFromEntry, openEditEntryTagDialog } =
+ useTaggingActionsContext();
const { readOnlyMode } = useCurrentLocationContext();
const maxSearchResults: number = useSelector(getMaxSearchResults);
@@ -86,7 +87,7 @@ function EntryTagMenu(props: Props) {
if (removeTagsProps) {
removeTagsProps([currentEntry.path], [selectedTag]);
} else {
- removeTags([currentEntry.path], [selectedTag]);
+ removeTagsFromEntry(currentEntry, [selectedTag]);
}
onClose();
}
diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsx
index 64851877d..b28736182 100644
--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx
+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx
@@ -81,9 +81,14 @@ type TaggingActionsContextData = {
collectTags?: boolean,
) => Promise<TS.FileSystemEntry>;
editTagForEntry: (path: string, tag: TS.Tag, newTagTitle?: string) => void;
- removeTags: (paths: Array<string>, tags?: Array<TS.Tag>) => Promise<boolean>;
- removeTagsFromEntry: (path: string, tags?: Array<TS.Tag>) => Promise<string>;
- removeAllTags: (paths: Array<string>) => Promise<boolean>;
+ removeTags: (
+ fsEntries: TS.FileSystemEntry[],
+ tags?: Array<TS.Tag>,
+ ) => Promise<boolean>;
+ removeTagsFromEntry: (
+ fsEntry: TS.FileSystemEntry,
+ tags?: Array<TS.Tag>,
+ ) => Promise<string>;
collectTagsFromLocation: (tagGroup: TS.TagGroup) => void;
createTagGroup: (
entry: TS.TagGroup,
@@ -130,7 +135,6 @@ export const TaggingActionsContext = createContext<TaggingActionsContextData>({
editTagForEntry: undefined,
removeTags: undefined,
removeTagsFromEntry: undefined,
- removeAllTags: undefined,
collectTagsFromLocation: undefined,
createTagGroup: undefined,
mergeTagGroup: undefined,
@@ -779,11 +783,11 @@ export const TaggingActionsContextProvider = ({
}
function removeTags(
- paths: Array<string>,
+ fsEntries: TS.FileSystemEntry[],
tags?: Array<TS.Tag>,
): Promise<boolean> {
- const promises = paths.map((path) =>
- removeTagsFromEntry(path, tags, false),
+ const promises = fsEntries.map((entry) =>
+ removeTagsFromEntry(entry, tags, false),
);
return Promise.all(promises).then((editedPaths) => {
const promiseReflect: Promise<TS.EditAction>[] = [];
@@ -795,7 +799,7 @@ export const TaggingActionsContextProvider = ({
const currentAction: TS.EditAction = {
action: 'update',
entry: fsEntry,
- oldEntryPath: paths[i],
+ oldEntryPath: fsEntries[i].path,
};
return currentAction;
},
@@ -811,13 +815,13 @@ export const TaggingActionsContextProvider = ({
}
/**
- * @param path
+ * @param fsEntry: TS.FileSystemEntry
* @param tags? if undefined will remove all tags
* @param reflect
* return newPath
*/
function removeTagsFromEntry(
- path: string,
+ fsEntry: TS.FileSystemEntry,
tags?: Array<TS.Tag>,
reflect: boolean = true,
): Promise<string> {
@@ -825,7 +829,7 @@ export const TaggingActionsContextProvider = ({
? tags.map((tag) => tag.title)
: undefined;
return currentLocation
- .loadMetaDataPromise(path)
+ .loadMetaDataPromise(fsEntry.path)
.then((fsEntryMeta: TS.FileSystemEntryMeta) => {
return removeTagsFromFilename(fsEntryMeta.isFile, reflect).then(
(newFilePath) => {
@@ -852,9 +856,11 @@ export const TaggingActionsContextProvider = ({
);
})
.catch((error) => {
- console.log('Error removing tags for ' + path + ' with ' + error);
+ console.log(
+ 'Error removing tags for ' + fsEntry.path + ' with ' + error,
+ );
// dispatch(AppActions.showNotification(t('core:removingSidecarTagsFailed'), 'error', true));
- return removeTagsFromFilename(true, reflect);
+ return removeTagsFromFilename(fsEntry.isFile, reflect);
});
function removeTagsFromSideCar(
@@ -903,17 +909,21 @@ export const TaggingActionsContextProvider = ({
reflect = true,
): Promise<string> {
if (!isFile) {
- return Promise.resolve(path);
+ return Promise.resolve(fsEntry.path);
}
return new Promise(async (resolve, reject) => {
const dirSeparator = currentLocation
? currentLocation.getDirSeparator()
: AppConfig.dirSeparator;
- let extractedTags = extractTags(path, tagDelimiter, dirSeparator);
+ let extractedTags = extractTags(
+ fsEntry.path,
+ tagDelimiter,
+ dirSeparator,
+ );
if (extractedTags.length > 0) {
- const fileName = extractFileName(path, dirSeparator);
+ const fileName = extractFileName(fsEntry.path, dirSeparator);
const containingDirectoryPath = extractContainingDirectoryPath(
- path,
+ fsEntry.path,
dirSeparator,
);
if (tagTitlesForRemoving) {
@@ -942,9 +952,9 @@ export const TaggingActionsContextProvider = ({
prefixTagContainer,
filenameTagPlacedAtEnd,
);
- if (path !== newFilePath) {
+ if (fsEntry.path !== newFilePath) {
const success = await renameFile(
- path,
+ fsEntry.path,
newFilePath,
currentLocation.uuid,
reflect,
@@ -957,16 +967,12 @@ export const TaggingActionsContextProvider = ({
}
resolve(newFilePath);
} else {
- resolve(path);
+ resolve(fsEntry.path);
}
});
}
}
- function removeAllTags(paths: Array<string>): Promise<boolean> {
- return removeTags(paths);
- }
-
function collectTagsFromLocation(tagGroup: TS.TagGroup) {
if (getIndex().length < 1) {
showNotification('Please index location first', 'error', true);
@@ -1466,7 +1472,6 @@ export const TaggingActionsContextProvider = ({
editTagForEntry,
removeTags,
removeTagsFromEntry,
- removeAllTags,
collectTagsFromLocation,
createTagGroup,
mergeTagGroup,
diff --git a/src/renderer/perspectives/common/main-container.tsx b/src/renderer/perspectives/common/main-container.tsx
index 20b4e3f6c..40e1d741a 100644
--- a/src/renderer/perspectives/common/main-container.tsx
+++ b/src/renderer/perspectives/common/main-container.tsx
@@ -321,7 +321,7 @@ export const renderCellPlaceholder = () => {
position: 'relative',
}}
>
- <TagDropContainer entryPath="">
+ <TagDropContainer>
<div></div>
</TagDropContainer>
</div>
diff --git a/src/renderer/perspectives/grid/components/MainContainer.tsx b/src/renderer/perspectives/grid/components/MainContainer.tsx
index 718ae83e1..49ba09222 100644
--- a/src/renderer/perspectives/grid/components/MainContainer.tsx
+++ b/src/renderer/perspectives/grid/components/MainContainer.tsx
@@ -319,12 +319,7 @@ function GridPerspective(props: Props) {
const selectionMode = selectedEntries.length > 1;
return (
- <TagDropContainer
- entryPath={fsEntry.path} // TODO remove entryPath it is already included in selectedEntries
- selectedEntries={
- selectedEntries.length > 0 ? selectedEntries : [fsEntry]
- }
- >
+ <TagDropContainer entry={fsEntry}>
<GridCell
selected={selected}
fsEntry={fsEntry}
diff --git a/src/renderer/perspectives/list/components/MainContainer.tsx b/src/renderer/perspectives/list/components/MainContainer.tsx
index c8a14267b..80074d310 100644
--- a/src/renderer/perspectives/list/components/MainContainer.tsx
+++ b/src/renderer/perspectives/list/components/MainContainer.tsx
@@ -316,12 +316,7 @@ function ListPerspective(props: Props) {
const selectionMode = selectedEntries.length > 1;
return (
- <TagDropContainer
- entryPath={fsEntry.path} // TODO remove entryPath it is already included in selectedEntries
- selectedEntries={
- selectedEntries.length > 0 ? selectedEntries : [fsEntry]
- }
- >
+ <TagDropContainer entry={fsEntry}>
<RowCell
selected={selected}
fsEntry={fsEntry}