feat: Enhance file item component with support for disabled state and file type validation

This commit is contained in:
twwu 2025-07-07 14:36:09 +08:00
parent a30b92d6b1
commit 83c8219942
2 changed files with 27 additions and 4 deletions

View File

@ -1,9 +1,13 @@
import React, { useMemo } from 'react'
import type { OnlineDriveFile } from '@/models/pipeline' import type { OnlineDriveFile } from '@/models/pipeline'
import Item from './item' import Item from './item'
import EmptyFolder from './empty-folder' import EmptyFolder from './empty-folder'
import EmptySearchResult from './empty-search-result' import EmptySearchResult from './empty-search-result'
import Loading from '@/app/components/base/loading' import Loading from '@/app/components/base/loading'
import { RiLoader2Line } from '@remixicon/react' import { RiLoader2Line } from '@remixicon/react'
import { useFileSupportTypes } from '@/service/use-common'
import { isFile } from '../../utils'
import { getFileExtension } from './utils'
type FileListProps = { type FileListProps = {
fileList: OnlineDriveFile[] fileList: OnlineDriveFile[]
@ -30,6 +34,11 @@ const List = ({
const isPartLoading = isLoading && fileList.length > 0 const isPartLoading = isLoading && fileList.length > 0
const isEmptyFolder = !isLoading && fileList.length === 0 && keywords.length === 0 const isEmptyFolder = !isLoading && fileList.length === 0 && keywords.length === 0
const isSearchResultEmpty = !isLoading && fileList.length === 0 && keywords.length > 0 const isSearchResultEmpty = !isLoading && fileList.length === 0 && keywords.length > 0
const { data: supportFileTypesRes } = useFileSupportTypes()
const supportedFileTypes = useMemo(() => {
if (!supportFileTypesRes) return []
return Array.from(new Set(supportFileTypesRes.allowed_extensions.map(item => item.toLowerCase())))
}, [supportFileTypesRes])
return ( return (
<div className='grow overflow-hidden p-1 pt-0'> <div className='grow overflow-hidden p-1 pt-0'>
@ -53,11 +62,14 @@ const List = ({
{ {
fileList.map((file) => { fileList.map((file) => {
const isSelected = selectedFileList.includes(file.key) const isSelected = selectedFileList.includes(file.key)
const extension = getFileExtension(file.key)
const disabled = isFile(file.key) && !supportedFileTypes.includes(extension)
return ( return (
<Item <Item
key={file.key} key={file.key}
file={file} file={file}
isSelected={isSelected} isSelected={isSelected}
disabled={disabled}
onSelect={handleSelectFile} onSelect={handleSelectFile}
onOpen={handleOpenFolder} onOpen={handleOpenFolder}
isMultipleChoice={!isInPipeline} isMultipleChoice={!isInPipeline}
@ -78,4 +90,4 @@ const List = ({
) )
} }
export default List export default React.memo(List)

View File

@ -51,15 +51,26 @@ const Item = ({
onClick={handleClickItem} onClick={handleClickItem}
> >
{!isBucket && isMultipleChoice && ( {!isBucket && isMultipleChoice && (
<Checkbox className='shrink-0' id={file.key} checked={isSelected} onCheck={handleSelect} /> <Checkbox
className='shrink-0'
disabled={disabled}
id={file.key}
checked={isSelected}
onCheck={handleSelect}
/>
)} )}
{!isBucket && !isMultipleChoice && ( {!isBucket && !isMultipleChoice && (
<Radio className='shrink-0' isChecked={isSelected} onCheck={handleSelect} /> <Radio
className='shrink-0'
disabled={disabled}
isChecked={isSelected}
onCheck={handleSelect}
/>
)} )}
<Wrapper <Wrapper
popupContent={t('datasetPipeline.onlineDrive.notSupportedFileType')} popupContent={t('datasetPipeline.onlineDrive.notSupportedFileType')}
position='top-end' position='top-end'
offset={{ mainAxis: 4, crossAxis: 104 }} offset={{ mainAxis: 4, crossAxis: -104 }}
> >
<div <div
className={cn( className={cn(