mirror of
https://github.com/YFGaia/dify-plus.git
synced 2026-06-04 10:14:00 +08:00
fix(web): use Array.from() for FileList to fix tsc type errors (#31398)
This commit is contained in:
@@ -125,7 +125,7 @@ jobs:
|
|||||||
- name: Web type check
|
- name: Web type check
|
||||||
if: steps.changed-files.outputs.any_changed == 'true'
|
if: steps.changed-files.outputs.any_changed == 'true'
|
||||||
working-directory: ./web
|
working-directory: ./web
|
||||||
run: pnpm run type-check:tsgo
|
run: pnpm run type-check
|
||||||
|
|
||||||
- name: Web dead code check
|
- name: Web dead code check
|
||||||
if: steps.changed-files.outputs.any_changed == 'true'
|
if: steps.changed-files.outputs.any_changed == 'true'
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ const CSVUploader: FC<Props> = ({
|
|||||||
setDragging(false)
|
setDragging(false)
|
||||||
if (!e.dataTransfer)
|
if (!e.dataTransfer)
|
||||||
return
|
return
|
||||||
const files = [...e.dataTransfer.files]
|
const files = Array.from(e.dataTransfer.files)
|
||||||
if (files.length > 1) {
|
if (files.length > 1) {
|
||||||
notify({ type: 'error', message: t('stepOne.uploader.validation.count', { ns: 'datasetCreation' }) })
|
notify({ type: 'error', message: t('stepOne.uploader.validation.count', { ns: 'datasetCreation' }) })
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ const Uploader: FC<Props> = ({
|
|||||||
setDragging(false)
|
setDragging(false)
|
||||||
if (!e.dataTransfer)
|
if (!e.dataTransfer)
|
||||||
return
|
return
|
||||||
const files = [...e.dataTransfer.files]
|
const files = Array.from(e.dataTransfer.files)
|
||||||
if (files.length > 1) {
|
if (files.length > 1) {
|
||||||
notify({ type: 'error', message: t('stepOne.uploader.validation.count', { ns: 'datasetCreation' }) })
|
notify({ type: 'error', message: t('stepOne.uploader.validation.count', { ns: 'datasetCreation' }) })
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export const useDSLDragDrop = ({ onDSLFileDropped, containerRef, enabled = true
|
|||||||
if (!e.dataTransfer)
|
if (!e.dataTransfer)
|
||||||
return
|
return
|
||||||
|
|
||||||
const files = [...e.dataTransfer.files]
|
const files = Array.from(e.dataTransfer.files)
|
||||||
if (files.length === 0)
|
if (files.length === 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ const Uploader: FC<Props> = ({
|
|||||||
setDragging(false)
|
setDragging(false)
|
||||||
if (!e.dataTransfer)
|
if (!e.dataTransfer)
|
||||||
return
|
return
|
||||||
const files = [...e.dataTransfer.files]
|
const files = Array.from(e.dataTransfer.files)
|
||||||
if (files.length > 1) {
|
if (files.length > 1) {
|
||||||
notify({ type: 'error', message: t('stepOne.uploader.validation.count', { ns: 'datasetCreation' }) })
|
notify({ type: 'error', message: t('stepOne.uploader.validation.count', { ns: 'datasetCreation' }) })
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ const FileUploader = ({
|
|||||||
onFileListUpdate?.([...fileListRef.current])
|
onFileListUpdate?.([...fileListRef.current])
|
||||||
}
|
}
|
||||||
const fileChangeHandle = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
const fileChangeHandle = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
let files = [...(e.target.files ?? [])] as File[]
|
let files = Array.from(e.target.files ?? []) as File[]
|
||||||
files = files.slice(0, fileUploadConfig.batch_count_limit)
|
files = files.slice(0, fileUploadConfig.batch_count_limit)
|
||||||
initialUpload(files.filter(isValid))
|
initialUpload(files.filter(isValid))
|
||||||
}, [isValid, initialUpload, fileUploadConfig])
|
}, [isValid, initialUpload, fileUploadConfig])
|
||||||
|
|||||||
+2
-2
@@ -230,7 +230,7 @@ const LocalFile = ({
|
|||||||
if (!e.dataTransfer)
|
if (!e.dataTransfer)
|
||||||
return
|
return
|
||||||
|
|
||||||
let files = [...e.dataTransfer.files] as File[]
|
let files = Array.from(e.dataTransfer.files) as File[]
|
||||||
if (!supportBatchUpload)
|
if (!supportBatchUpload)
|
||||||
files = files.slice(0, 1)
|
files = files.slice(0, 1)
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ const LocalFile = ({
|
|||||||
updateFileList([...fileListRef.current])
|
updateFileList([...fileListRef.current])
|
||||||
}
|
}
|
||||||
const fileChangeHandle = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
const fileChangeHandle = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
let files = [...(e.target.files ?? [])] as File[]
|
let files = Array.from(e.target.files ?? []) as File[]
|
||||||
files = files.slice(0, fileUploadConfig.batch_count_limit)
|
files = files.slice(0, fileUploadConfig.batch_count_limit)
|
||||||
initialUpload(files.filter(isValid))
|
initialUpload(files.filter(isValid))
|
||||||
}, [isValid, initialUpload, fileUploadConfig.batch_count_limit])
|
}, [isValid, initialUpload, fileUploadConfig.batch_count_limit])
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ const CSVUploader: FC<Props> = ({
|
|||||||
setDragging(false)
|
setDragging(false)
|
||||||
if (!e.dataTransfer)
|
if (!e.dataTransfer)
|
||||||
return
|
return
|
||||||
const files = [...e.dataTransfer.files]
|
const files = Array.from(e.dataTransfer.files)
|
||||||
if (files.length > 1) {
|
if (files.length > 1) {
|
||||||
notify({ type: 'error', message: t('stepOne.uploader.validation.count', { ns: 'datasetCreation' }) })
|
notify({ type: 'error', message: t('stepOne.uploader.validation.count', { ns: 'datasetCreation' }) })
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export const useUploader = ({ onFileChange, containerRef, enabled = true }: Uplo
|
|||||||
setDragging(false)
|
setDragging(false)
|
||||||
if (!e.dataTransfer)
|
if (!e.dataTransfer)
|
||||||
return
|
return
|
||||||
const files = [...e.dataTransfer.files]
|
const files = Array.from(e.dataTransfer.files)
|
||||||
if (files.length > 0)
|
if (files.length > 0)
|
||||||
onFileChange(files[0])
|
onFileChange(files[0])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user