diff --git a/web/app/components/datasets/create/file-uploader/index.tsx b/web/app/components/datasets/create/file-uploader/index.tsx index 63bd554215..092f2f0ab5 100644 --- a/web/app/components/datasets/create/file-uploader/index.tsx +++ b/web/app/components/datasets/create/file-uploader/index.tsx @@ -47,6 +47,10 @@ const FileUploader = ({ const dropRef = useRef(null) const dragRef = useRef(null) const fileUploader = useRef(null) + + // For upload folder + const dirUploader = useRef(null) + const hideUpload = notSupportBatchUpload && fileList.length > 0 const { data: fileUploadConfigResponse } = useSWR({ url: '/files/upload' }, fetchFileUploadConfig) @@ -214,6 +218,12 @@ const FileUploader = ({ fileUploader.current.click() } + // click on button, use folder upload + const selectFolderHandle = () => { + if (dirUploader.current) + dirUploader.current.click() + } + const removeFile = (fileID: string) => { if (fileUploader.current) fileUploader.current.value = '' @@ -223,7 +233,15 @@ const FileUploader = ({ } const fileChangeHandle = useCallback((e: React.ChangeEvent) => { const files = [...(e.target.files ?? [])] as File[] - initialUpload(files.filter(isValid)) + const validFiles = files.filter(isValid) + initialUpload(validFiles) + }, [isValid, initialUpload]) + + // Callback for folder upload + const folderChangeHandle = useCallback((e: React.ChangeEvent) => { + const files = [...(e.target.files ?? [])] as File[] + const validFiles = files.filter(isValid) + initialUpload(validFiles) }, [isValid, initialUpload]) const { theme } = useTheme() @@ -245,15 +263,36 @@ const FileUploader = ({ return (
{!hideUpload && ( - + <> + + {/* folder uploader */} + + + )} + + {/* give user a “Upload Folder” button */} + {!hideUpload && ( + )}
{t('datasetCreation.stepOne.uploader.title')}