From c55e9d16da6e402b5349cfe84d1dce3496f541c5 Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 7 Aug 2024 10:12:11 +0800 Subject: [PATCH] feat: Move files in file manager #1826 (#1837) ### What problem does this PR solve? feat: Move files in file manager #1826 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/assets/svg/move.svg | 6 ++ web/src/hooks/file-manager-hooks.ts | 45 +++++++++++++ web/src/locales/en.ts | 2 + web/src/locales/zh-traditional.ts | 2 + web/src/locales/zh.ts | 2 + .../pages/file-manager/action-cell/index.tsx | 30 +++++++-- web/src/pages/file-manager/file-toolbar.tsx | 23 ++++++- .../folder-create-modal/index.tsx | 16 +---- web/src/pages/file-manager/hooks.ts | 46 +++++++++++++ web/src/pages/file-manager/index.tsx | 20 +++++- .../move-file-modal/async-tree-select.tsx | 64 +++++++++++++++++++ .../file-manager/move-file-modal/index.tsx | 54 ++++++++++++++++ web/src/services/file-manager-service.ts | 5 ++ web/src/utils/api.ts | 1 + 14 files changed, 292 insertions(+), 24 deletions(-) create mode 100644 web/src/assets/svg/move.svg create mode 100644 web/src/pages/file-manager/move-file-modal/async-tree-select.tsx create mode 100644 web/src/pages/file-manager/move-file-modal/index.tsx diff --git a/web/src/assets/svg/move.svg b/web/src/assets/svg/move.svg new file mode 100644 index 0000000000..1e9e7c9a47 --- /dev/null +++ b/web/src/assets/svg/move.svg @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/web/src/hooks/file-manager-hooks.ts b/web/src/hooks/file-manager-hooks.ts index c8a9a2048f..1918f0bd71 100644 --- a/web/src/hooks/file-manager-hooks.ts +++ b/web/src/hooks/file-manager-hooks.ts @@ -28,6 +28,23 @@ export interface IListResult { loading: boolean; } +export const useFetchPureFileList = () => { + const { mutateAsync, isPending: loading } = useMutation({ + mutationKey: ['fetchPureFileList'], + gcTime: 0, + + mutationFn: async (parentId: string) => { + const { data } = await fileManagerService.listFile({ + parent_id: parentId, + }); + + return data; + }, + }); + + return { loading, fetchList: mutateAsync }; +}; + export const useFetchFileList = (): ResponseType & IListResult => { const { searchString, handleInputChange } = useHandleSearchChange(); const { pagination, setPagination } = useGetPaginationWithRouter(); @@ -225,3 +242,31 @@ export const useConnectToKnowledge = () => { return { data, loading, connectFileToKnowledge: mutateAsync }; }; + +export interface IMoveFileBody { + src_file_ids: string[]; + dest_file_id: string; // target folder id +} + +export const useMoveFile = () => { + const queryClient = useQueryClient(); + const { t } = useTranslation(); + + const { + data, + isPending: loading, + mutateAsync, + } = useMutation({ + mutationKey: ['moveFile'], + mutationFn: async (params: IMoveFileBody) => { + const { data } = await fileManagerService.moveFile(params); + if (data.retcode === 0) { + message.success(t('message.operated')); + queryClient.invalidateQueries({ queryKey: ['fetchFileList'] }); + } + return data.retcode; + }, + }); + + return { data, loading, moveFile: mutateAsync }; +}; diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index 360befc0a2..bae6ea8e79 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -26,6 +26,7 @@ export default { download: 'Download', close: 'Close', preview: 'Preview', + move: 'Move', }, login: { login: 'Sign in', @@ -564,6 +565,7 @@ The above is the content you need to summarize.`, fileError: 'File error', uploadLimit: 'The file size cannot exceed 10M, and the total number of files cannot exceed 128', + destinationFolder: 'Destination folder', }, flow: { cite: 'Cite', diff --git a/web/src/locales/zh-traditional.ts b/web/src/locales/zh-traditional.ts index fc2502037f..e266259029 100644 --- a/web/src/locales/zh-traditional.ts +++ b/web/src/locales/zh-traditional.ts @@ -26,6 +26,7 @@ export default { download: '下載', close: '關閉', preview: '預覽', + move: '移動', }, login: { login: '登入', @@ -524,6 +525,7 @@ export default { preview: '預覽', fileError: '文件錯誤', uploadLimit: '文件大小不能超過10M,文件總數不超過128個', + destinationFolder: '目標資料夾', }, flow: { cite: '引用', diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts index c30ecee9c8..d22a3ba1bd 100644 --- a/web/src/locales/zh.ts +++ b/web/src/locales/zh.ts @@ -26,6 +26,7 @@ export default { download: '下载', close: '关闭', preview: '预览', + move: '移动', }, login: { login: '登录', @@ -542,6 +543,7 @@ export default { preview: '预览', fileError: '文件错误', uploadLimit: '文件大小不能超过10M,文件总数不超过128个', + destinationFolder: '目标文件夹', }, flow: { flow: '工作流', diff --git a/web/src/pages/file-manager/action-cell/index.tsx b/web/src/pages/file-manager/action-cell/index.tsx index 56996428b9..6962eb350a 100644 --- a/web/src/pages/file-manager/action-cell/index.tsx +++ b/web/src/pages/file-manager/action-cell/index.tsx @@ -1,6 +1,12 @@ +import NewDocumentLink from '@/components/new-document-link'; +import SvgIcon from '@/components/svg-icon'; import { useTranslate } from '@/hooks/common-hooks'; import { IFile } from '@/interfaces/database/file-manager'; import { api_host } from '@/utils/api'; +import { + getExtension, + isSupportedPreviewDocumentType, +} from '@/utils/document-util'; import { downloadFile } from '@/utils/file-util'; import { DeleteOutlined, @@ -11,18 +17,13 @@ import { } from '@ant-design/icons'; import { Button, Space, Tooltip } from 'antd'; import { useHandleDeleteFile } from '../hooks'; - -import NewDocumentLink from '@/components/new-document-link'; -import { - getExtension, - isSupportedPreviewDocumentType, -} from '@/utils/document-util'; import styles from './index.less'; interface IProps { record: IFile; setCurrentRecord: (record: any) => void; showRenameModal: (record: IFile) => void; + showMoveFileModal: (ids: string[]) => void; showConnectToKnowledgeModal: (record: IFile) => void; setSelectedRowKeys(keys: string[]): void; } @@ -33,6 +34,7 @@ const ActionCell = ({ showRenameModal, showConnectToKnowledgeModal, setSelectedRowKeys, + showMoveFileModal, }: IProps) => { const documentId = record.id; const beingUsed = false; @@ -64,6 +66,10 @@ const ActionCell = ({ showConnectToKnowledgeModal(record); }; + const onShowMoveFileModal = () => { + showMoveFileModal([documentId]); + }; + return ( {isKnowledgeBase || ( @@ -90,6 +96,18 @@ const ActionCell = ({ )} + {isKnowledgeBase || ( + + + + )} {isKnowledgeBase || (