Skip to content

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

Move to top and bottom menu items missing from the card context menu in kanban (#2330)

Stanimirc8e7d7eeff59
diff --git a/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx
index c45e6341c..aab18db9c 100644
--- a/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx
@@ -45,8 +45,8 @@ type MenuContextData = {
openFileMenu: (
event: MouseEvent | React.MouseEvent<Element, MouseEvent>,
dirPath: string,
- orderTop?: () => void,
- orderBottom?: () => void,
+ orderTop?: (entry: TS.FileSystemEntry) => void,
+ orderBottom?: (entry: TS.FileSystemEntry) => void,
) => void;
// setMousePosition: (x: number, y: number) => void;
closeDirectoryMenu: () => void;
@@ -122,8 +122,8 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {
const directoryPath = useRef<string>(undefined);
const mouseX = useRef<number>(undefined);
const mouseY = useRef<number>(undefined);
- const reorderTop = useRef<() => void>(undefined);
- const reorderBottom = useRef<() => void>(undefined);
+ const reorderTop = useRef<(entry: TS.FileSystemEntry) => void>(undefined);
+ const reorderBottom = useRef<(entry: TS.FileSystemEntry) => void>(undefined);
const menuItems = useRef<React.ReactNode>(undefined);
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
@@ -179,8 +179,8 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {
const openFileMenu = (
event: MouseEvent | React.MouseEvent<Element, MouseEvent>,
dirPath: string,
- orderTop?: () => void,
- orderBottom?: () => void,
+ orderTop?: (entry: TS.FileSystemEntry) => void,
+ orderBottom?: (entry: TS.FileSystemEntry) => void,
) => {
event.preventDefault();
directoryPath.current = dirPath;
diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsx
index 5ae7e233d..7d06f945b 100644
--- a/src/renderer/components/menus/FileMenu.tsx
+++ b/src/renderer/components/menus/FileMenu.tsx
@@ -78,8 +78,8 @@ interface Props {
mouseY?: number;
open: boolean;
onClose: () => void;
- reorderTop?: () => void;
- reorderBottom?: () => void;
+ reorderTop?: (entry: TS.FileSystemEntry) => void;
+ reorderBottom?: (entry: TS.FileSystemEntry) => void;
onDuplicateFile?: (fileDirPath: string) => void;
}
@@ -418,7 +418,7 @@ function FileMenu(props: Props) {
data-tid="reorderTopTID"
onClick={() => {
onClose();
- reorderTop();
+ reorderTop(lastSelectedEntry);
}}
>
<ListItemIcon>
@@ -435,7 +435,7 @@ function FileMenu(props: Props) {
data-tid="reorderBottomTID"
onClick={() => {
onClose();
- reorderBottom();
+ reorderBottom(lastSelectedEntry);
}}
>
<ListItemIcon>
diff --git a/src/renderer/hooks/IOActionsContextProvider.tsx b/src/renderer/hooks/IOActionsContextProvider.tsx
index 547710919..219548760 100644
--- a/src/renderer/hooks/IOActionsContextProvider.tsx
+++ b/src/renderer/hooks/IOActionsContextProvider.tsx
@@ -219,6 +219,11 @@ type IOActionsContextData = {
file: TS.OrderVisibilitySettings,
files?: Array<TS.OrderVisibilitySettings>,
) => Promise<TS.FileSystemEntryMeta>;
+ reorderColumn: (
+ entry: TS.FileSystemEntry,
+ columnFiles?: TS.OrderVisibilitySettings[],
+ filePath?: string,
+ ) => Promise<TS.OrderVisibilitySettings[]>;
};
export const IOActionsContext = createContext<IOActionsContextData>({
@@ -257,6 +262,7 @@ export const IOActionsContext = createContext<IOActionsContextData>({
getDirectoryOrder: undefined,
getFilesOrder: undefined,
pushFileOrder: undefined,
+ reorderColumn: undefined,
});
export type IOActionsContextProviderProps = {
@@ -2076,6 +2082,45 @@ export const IOActionsContextProvider = ({
});
}
+ /**
+ *
+ * @param entry
+ * @param columnFiles if = undefined toTop ordered
+ * @param filePath
+ */
+ function reorderColumn(
+ entry: TS.FileSystemEntry,
+ columnFiles: TS.OrderVisibilitySettings[] = undefined,
+ filePath = undefined,
+ ): Promise<TS.OrderVisibilitySettings[]> {
+ const dirPath = extractContainingDirectoryPath(
+ filePath ? filePath : entry.path,
+ );
+
+ return pushFileOrder(
+ dirPath,
+ {
+ uuid: entry.uuid,
+ name: extractFileName(entry.path, currentLocation?.getDirSeparator()),
+ },
+ columnFiles,
+ )
+ .then((updatedFsEntryMeta) => {
+ return saveCurrentLocationMetaData(dirPath, updatedFsEntryMeta)
+ .then(() => {
+ return updatedFsEntryMeta.customOrder.files;
+ })
+ .catch((err) => {
+ console.log('Error adding files for ' + dirPath + ' with ' + err);
+ return undefined;
+ });
+ })
+ .catch((error) => {
+ console.log('Error reorderTop ' + error);
+ return undefined;
+ });
+ }
+
function toggleDirVisibility(
dir: TS.OrderVisibilitySettings,
parentDirPath: string = undefined,
@@ -2354,6 +2399,7 @@ export const IOActionsContextProvider = ({
getDirectoryOrder,
getFilesOrder,
pushFileOrder,
+ reorderColumn,
};
}, [
warningOpeningFilesExternally,
diff --git a/src/renderer/perspectives/common/CellView.tsx b/src/renderer/perspectives/common/CellView.tsx
index 891645f9e..83b915bf7 100644
--- a/src/renderer/perspectives/common/CellView.tsx
+++ b/src/renderer/perspectives/common/CellView.tsx
@@ -16,6 +16,10 @@
*
*/
+import React from 'react';
+import { extractContainingDirectoryPath } from '@tagspaces/tagspaces-common/paths';
+import { NativeTypes } from 'react-dnd-html5-backend';
+import { useSelector } from 'react-redux';
import AppConfig from '-/AppConfig';
import CustomDragLayer from '-/components/CustomDragLayer';
import DragItemTypes from '-/components/DragItemTypes';
@@ -42,9 +46,6 @@ import { TS } from '-/tagspaces.namespace';
import DragHandleIcon from '@mui/icons-material/DragHandleOutlined';
import Typography from '@mui/material/Typography';
import { useTheme } from '@mui/material/styles';
-import React from 'react';
-import { NativeTypes } from 'react-dnd-html5-backend';
-import { useSelector } from 'react-redux';
interface Props {
fsEntry: TS.FileSystemEntry;
@@ -61,16 +62,18 @@ interface Props {
handleGridCellDblClick,
isLast?: boolean,
) => any;
+ orderTop?: (entry: TS.FileSystemEntry) => void;
+ orderBottom?: (entry: TS.FileSystemEntry) => void;
isLast?: boolean;
}
function CellView(props: Props) {
- const { fsEntry, index, cellContent, isLast } = props;
+ const { fsEntry, index, cellContent, isLast, orderTop, orderBottom } = props;
const { showDirectories, singleClickAction } =
usePerspectiveSettingsContext();
const theme = useTheme();
- const { openMenu } = useMenuContext();
+ const { openFileMenu, openDirectoryMenu } = useMenuContext();
const { openEntryInternal, openedEntry } = useOpenedEntryContext();
const { openDirectory } = useDirectoryContentContext();
const { moveFiles, openFileNatively } = useIOActionsContext();
@@ -127,7 +130,15 @@ function CellView(props: Props) {
} else {
addToSelection(fsEntry);
}
- openMenu(event, fsEntry);
+ if (fsEntry.isFile) {
+ const dirPath = extractContainingDirectoryPath(
+ fsEntry.path,
+ currentLocation?.getDirSeparator(),
+ );
+ openFileMenu(event, dirPath, orderTop, orderBottom);
+ } else {
+ openDirectoryMenu(event, fsEntry.path, true);
+ }
}
};