Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit 88803e3

Browse files
refactor: Extract single file download logic to custom hook (langflow-ai#8944)
✨ (use-custom-handle-bulk-files-download.ts): add custom hook to handle bulk files download functionality ✨ (use-custom-handle-single-file-download.ts): add custom hook to handle single file download functionality 🔧 (index.tsx): fix import path for use-custom-handle-bulk-files-download hook in filesPage 🔧 (index.tsx): fix import path for use-custom-handle-single-file-download hook in filesContextMenuComponent Co-authored-by: Carlos Coelho <80289056+carlosrcoelho@users.noreply.github.com>
1 parent f390d3a commit 88803e3

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

src/frontend/src/customization/hooks/custom-handle-bulk-files-download.tsx renamed to src/frontend/src/customization/hooks/use-custom-handle-bulk-files-download.ts

File renamed without changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useGetDownloadFileV2 } from "@/controllers/API/queries/file-management";
2+
import { FileType } from "@/types/file_management";
3+
4+
interface SingleFileDownloadParams {
5+
id: string;
6+
filename: string;
7+
type: string;
8+
}
9+
10+
export const useCustomHandleSingleFileDownload = (file: FileType) => {
11+
const { mutate: downloadFile } = useGetDownloadFileV2({
12+
id: file.id,
13+
filename: file.name,
14+
type: file.path.split(".").pop() || "",
15+
});
16+
17+
const handleSingleDownload = (
18+
params?: SingleFileDownloadParams,
19+
setSuccessData?: (data: { title: string }) => void,
20+
setErrorData?: (data: { title: string; list: string[] }) => void,
21+
) => {
22+
downloadFile();
23+
};
24+
25+
return { handleSingleDownload };
26+
};

src/frontend/src/modals/fileManagerModal/components/filesContextMenuComponent/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
DropdownMenuItem,
66
DropdownMenuTrigger,
77
} from "@/components/ui/dropdown-menu";
8-
import { useGetDownloadFileV2 } from "@/controllers/API/queries/file-management";
98
import { useDeleteFileV2 } from "@/controllers/API/queries/file-management/use-delete-file";
109
import { useDuplicateFileV2 } from "@/controllers/API/queries/file-management/use-duplicate-file";
10+
import { useCustomHandleSingleFileDownload } from "@/customization/hooks/use-custom-handle-single-file-download";
1111
import ConfirmationModal from "@/modals/confirmationModal";
1212
import useAlertStore from "@/stores/alertStore";
1313
import { FileType } from "@/types/file_management";
@@ -29,11 +29,7 @@ export default function FilesContextMenuComponent({
2929

3030
const setSuccessData = useAlertStore((state) => state.setSuccessData);
3131

32-
const { mutate: downloadFile } = useGetDownloadFileV2({
33-
id: file.id,
34-
filename: file.name,
35-
type: file.path.split(".").pop() || "",
36-
});
32+
const { handleSingleDownload } = useCustomHandleSingleFileDownload(file);
3733

3834
const { mutate: deleteFile } = useDeleteFileV2({
3935
id: file.id,
@@ -54,7 +50,7 @@ export default function FilesContextMenuComponent({
5450
console.log("replace");
5551
break;
5652
case "download":
57-
downloadFile();
53+
handleSingleDownload();
5854
break;
5955
case "delete":
6056
setShowDeleteConfirmation(true);

src/frontend/src/pages/MainPage/pages/filesPage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { SidebarTrigger } from "@/components/ui/sidebar";
99
import { useGetFilesV2 } from "@/controllers/API/queries/file-management";
1010
import { useDeleteFilesV2 } from "@/controllers/API/queries/file-management/use-delete-files";
1111
import { usePostRenameFileV2 } from "@/controllers/API/queries/file-management/use-put-rename-file";
12-
import { useCustomHandleBulkFilesDownload } from "@/customization/hooks/custom-handle-bulk-files-download";
12+
import { useCustomHandleBulkFilesDownload } from "@/customization/hooks/use-custom-handle-bulk-files-download";
1313
import { customPostUploadFileV2 } from "@/customization/hooks/use-custom-post-upload-file";
1414
import useUploadFile from "@/hooks/files/use-upload-file";
1515
import DeleteConfirmationModal from "@/modals/deleteConfirmationModal";

0 commit comments

Comments
 (0)