Fix/upload document limit (#1033)

This commit is contained in:
zxhlyh
2023-08-28 10:53:45 +08:00
committed by GitHub
parent 934def5fcc
commit a7415ecfd8
8 changed files with 57 additions and 12 deletions

View File

@@ -18,6 +18,8 @@ type IFileUploaderProps = {
onFileUpdate: (fileItem: FileItem, progress: number, list: FileItem[]) => void
onFileListUpdate?: (files: any) => void
onPreview: (file: File) => void
countLimit: number
countUsed: number
}
const ACCEPTS = [
@@ -39,6 +41,8 @@ const FileUploader = ({
onFileUpdate,
onFileListUpdate,
onPreview,
countLimit,
countUsed,
}: IFileUploaderProps) => {
const { t } = useTranslation()
const { notify } = useContext(ToastContext)
@@ -145,6 +149,10 @@ const FileUploader = ({
const initialUpload = useCallback((files: File[]) => {
if (!files.length)
return false
if (files.length > countLimit - countUsed) {
notify({ type: 'error', message: t('datasetCreation.stepOne.overCountLimit', { countLimit }) })
return false
}
const preparedFiles = files.map((file, index) => ({
fileID: `file${index}-${Date.now()}`,
file,