From 754f583e97ce70718066d8a1ca4f6da21830f3fe Mon Sep 17 00:00:00 2001 From: Jeff McMillen Date: Thu, 5 Dec 2024 10:45:12 -0600 Subject: [PATCH] Trash mutation actually works as intended --- .../DataFilesToolbar/DataFilesToolbar.jsx | 34 ++++++------------- .../src/hooks/datafiles/mutations/useTrash.ts | 31 +++++++---------- 2 files changed, 24 insertions(+), 41 deletions(-) diff --git a/client/src/components/DataFiles/DataFilesToolbar/DataFilesToolbar.jsx b/client/src/components/DataFiles/DataFilesToolbar/DataFilesToolbar.jsx index 715214666..cf3550e68 100644 --- a/client/src/components/DataFiles/DataFilesToolbar/DataFilesToolbar.jsx +++ b/client/src/components/DataFiles/DataFilesToolbar/DataFilesToolbar.jsx @@ -174,29 +174,17 @@ const DataFilesToolbar = ({ scheme, api }) => { } }; - const trashCallback = useCallback(() => { - const filteredSelected = selectedFiles.filter( - (f) => status[f.system + f.path] !== 'SUCCESS' - ); - trash({ - filteredSelected, reloadPage - }); - - - - // dispatch({ - // type: 'DATA_FILES_TRASH', - // payload: { - // src: filteredSelected, - // homeDir: selectedSystem?.homeDir || '', - // reloadCallback: reloadPage, - // }, - // }); - }, [selectedFiles, selectedSystem, reloadPage]); + const homeDir = selectedSystem?.homeDir; - - - // const { status: trashStatus } = useTrash(); + const trashCallback = useCallback(() => { + trash({ + destSystem: selectedSystem.system, + homeDir: homeDir, + callback: reloadPage, + }); + }, + [selectedFiles, reloadPage, status] + ); const empty = () => { dispatch({ @@ -282,7 +270,7 @@ const DataFilesToolbar = ({ scheme, api }) => { diff --git a/client/src/hooks/datafiles/mutations/useTrash.ts b/client/src/hooks/datafiles/mutations/useTrash.ts index 8b4d61083..a6bd90c92 100644 --- a/client/src/hooks/datafiles/mutations/useTrash.ts +++ b/client/src/hooks/datafiles/mutations/useTrash.ts @@ -2,7 +2,6 @@ import { useSelector, useDispatch, shallowEqual } from 'react-redux'; import { useMutation } from '@tanstack/react-query'; import { useSelectedFiles } from 'hooks/datafiles'; import Cookies from 'js-cookie'; -import { apiClient } from 'utils/apiClient'; export async function trashUtil({ api, @@ -17,19 +16,12 @@ export async function trashUtil({ path: string; homeDir: string; }) { - // const body = { - // homeDir: homeDir - // }; - console.log(homeDir); const url = `/api/datafiles/${api}/trash/${scheme}/${system}/${path}/`; - // const request = await apiClient.put(url, { + // const request = await apiClient.put(url, body, { // headers: { - // 'X-CSRFToken': Cookies.get('csrftoken'), + // 'X-CSRFToken': Cookies.get('csrftoken' || ''), // }, // withCredentials: true, - // body: JSON.stringify({ - // homeDir: homeDir, - // }), // }); const request = await fetch(url, { method: 'PUT', @@ -53,9 +45,10 @@ function useTrash() { shallowEqual ); - const { api, scheme, homeDir } = useSelector( + const { api, scheme } = useSelector( (state: any) => state.files.params.FilesListing ); + const setStatus = (newStatus: any) => { dispatch({ type: 'DATA_FILES_SET_OPERATION_STATUS', @@ -66,11 +59,13 @@ function useTrash() { const { mutateAsync } = useMutation({ mutationFn: trashUtil }); const trash = ({ - selection, - // callback, + destSystem, + homeDir, + callback, }: { - selection: any; - // callback: any; + destSystem: string; + homeDir: any; + callback: any; }) => { const filteredSelected = selected.filter( (f: any) => status[f.id] !== 'SUCCESS' @@ -89,7 +84,7 @@ function useTrash() { { api: api, scheme: scheme, - system: file.system, + system: destSystem, path: file.path, homeDir: homeDir, }, @@ -106,10 +101,10 @@ function useTrash() { dispatch({ type: 'ADD_TOAST', payload: { - message: `${selection} moved to Trash`, + message: `File moved to Trash`, }, }); - // callback; + callback(); }, onError: () => { dispatch({