From 6d3d3a40ab6771d7cfbc59d46e519244038c22dd Mon Sep 17 00:00:00 2001 From: Jimmy Ben Klieve Date: Mon, 22 Dec 2025 19:04:44 +0800 Subject: [PATCH] fix: hide drop-zone upload button when picked an image (#12088) ### What problem does this PR solve? Hide drop-zone upload button when picked an image in chunk editor dialog ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/src/components/file-uploader.tsx | 120 ++++++++++-------- .../components/chunk-creating-modal/index.tsx | 7 +- 2 files changed, 68 insertions(+), 59 deletions(-) diff --git a/web/src/components/file-uploader.tsx b/web/src/components/file-uploader.tsx index b5d622aad..43b4fcc8d 100644 --- a/web/src/components/file-uploader.tsx +++ b/web/src/components/file-uploader.tsx @@ -145,6 +145,8 @@ interface FileUploaderProps */ maxFileCount?: DropzoneProps['maxFiles']; + hideDropzoneOnMaxFileCount?: boolean; + /** * Whether the uploader should accept multiple files. * @type boolean @@ -178,6 +180,7 @@ export function FileUploader(props: FileUploaderProps) { maxFileCount = 100000000000, multiple = false, disabled = false, + hideDropzoneOnMaxFileCount = false, className, title, description, @@ -189,6 +192,8 @@ export function FileUploader(props: FileUploaderProps) { onChange: onValueChange, }); + const reachesMaxFileCount = (files?.length ?? 0) >= maxFileCount; + const onDrop = React.useCallback( (acceptedFiles: File[], rejectedFiles: FileRejection[]) => { if (!multiple && maxFileCount === 1 && acceptedFiles.length > 1) { @@ -263,65 +268,68 @@ export function FileUploader(props: FileUploaderProps) { return (
- 1 || multiple} - disabled={isDisabled} - > - {({ getRootProps, getInputProps, isDragActive }) => ( -
- - {isDragActive ? ( -
-
-
-

- Drop the files here -

-
- ) : ( -
-
-
-
+ {!(hideDropzoneOnMaxFileCount && reachesMaxFileCount) && ( + 1 || multiple} + disabled={isDisabled} + > + {({ getRootProps, getInputProps, isDragActive }) => ( +
+ + {isDragActive ? ( +
+
+

- {title || t('knowledgeDetails.uploadTitle')} -

-

- {description || t('knowledgeDetails.uploadDescription')} - {/* You can upload - {maxFileCount > 1 - ? ` ${maxFileCount === Infinity ? 'multiple' : maxFileCount} - files (up to ${formatBytes(maxSize)} each)` - : ` a file with ${formatBytes(maxSize)}`} */} + Drop the files here

-
- )} -
- )} - + ) : ( +
+
+
+
+

+ {title || t('knowledgeDetails.uploadTitle')} +

+

+ {description || t('knowledgeDetails.uploadDescription')} + {/* You can upload + {maxFileCount > 1 + ? ` ${maxFileCount === Infinity ? 'multiple' : maxFileCount} + files (up to ${formatBytes(maxSize)} each)` + : ` a file with ${formatBytes(maxSize)}`} */} +

+
+
+ )} +
+ )} + + )} + {files?.length ? (
diff --git a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx index 7a781682f..73d988182 100644 --- a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx +++ b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx @@ -175,18 +175,18 @@ const ChunkCreatingModal: React.FC & kFProps> = ({ {t('chunk.image')} -
+
{data?.data?.img_id && ( )}
& kFProps> = ({ 'image/webp': [], }} maxFileCount={1} + hideDropzoneOnMaxFileCount title={t('chunk.imageUploaderTitle')} description={<>} />