Commit 8d8b062e by Archer Committed by GitHub

add max count to image import (#5144)

parent 2078cdf0
...@@ -39,16 +39,19 @@ const FileSelector = ({ ...@@ -39,16 +39,19 @@ const FileSelector = ({
const systemMaxSize = (feConfigs?.uploadFileMaxSize || 1024) * 1024 * 1024; const systemMaxSize = (feConfigs?.uploadFileMaxSize || 1024) * 1024 * 1024;
const displayMaxSize = maxSize || formatFileSize(systemMaxSize); const displayMaxSize = maxSize || formatFileSize(systemMaxSize);
const formatMaxCount = feConfigs.uploadFileMaxAmount
? Math.min(maxCount, feConfigs.uploadFileMaxAmount)
: maxCount;
const { File, onOpen } = useSelectFile({ const { File, onOpen } = useSelectFile({
fileType, fileType,
multiple: maxCount > 1, multiple: formatMaxCount > 1,
maxCount maxCount: formatMaxCount
}); });
const [isDragging, setIsDragging] = useState(false); const [isDragging, setIsDragging] = useState(false);
const isMaxSelected = useMemo( const isMaxSelected = useMemo(
() => selectFiles.length >= maxCount, () => selectFiles.length >= formatMaxCount,
[maxCount, selectFiles.length] [formatMaxCount, selectFiles.length]
); );
const filterTypeReg = new RegExp( const filterTypeReg = new RegExp(
...@@ -68,10 +71,10 @@ const FileSelector = ({ ...@@ -68,10 +71,10 @@ const FileSelector = ({
size: formatFileSize(file.size) size: formatFileSize(file.size)
})); }));
const newFiles = [...fileList, ...selectFiles].slice(0, maxCount); const newFiles = [...fileList, ...selectFiles].slice(0, formatMaxCount);
setSelectFiles(newFiles); setSelectFiles(newFiles);
}, },
[maxCount, selectFiles, setSelectFiles] [formatMaxCount, selectFiles, setSelectFiles]
); );
const handleDragEnter = (e: DragEvent<HTMLDivElement>) => { const handleDragEnter = (e: DragEvent<HTMLDivElement>) => {
...@@ -206,7 +209,7 @@ const FileSelector = ({ ...@@ -206,7 +209,7 @@ const FileSelector = ({
)} )}
<Box color={'myGray.500'} fontSize={'xs'}> <Box color={'myGray.500'} fontSize={'xs'}>
{/* max count */} {/* max count */}
{maxCount && <>{t('file:support_max_count', { maxCount })}, </>} {formatMaxCount && <>{t('file:support_max_count', { maxCount: formatMaxCount })}, </>}
{/* max size */} {/* max size */}
{t('file:support_max_size', { maxSize: displayMaxSize })} {t('file:support_max_size', { maxSize: displayMaxSize })}
</Box> </Box>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment