refactor: Remove unused variables and simplify next button logic in TestRunPanel

This commit is contained in:
twwu 2025-06-30 17:54:33 +08:00
parent 310102bebd
commit ff511c6f31
2 changed files with 4 additions and 17 deletions

View File

@ -84,8 +84,6 @@ export const useDatasourceOptions = () => {
export const useLocalFile = () => {
const [fileList, setFileList] = useState<FileItem[]>([])
const allFileLoaded = useMemo(() => (fileList.length > 0 && fileList.every(file => file.file.id)), [fileList])
const updateFile = (fileItem: FileItem, progress: number, list: FileItem[]) => {
const newList = produce(list, (draft) => {
const targetIndex = draft.findIndex(file => file.fileID === fileItem.fileID)
@ -103,7 +101,6 @@ export const useLocalFile = () => {
return {
fileList,
allFileLoaded,
updateFile,
updateFileList,
}

View File

@ -3,9 +3,7 @@ import { useCallback, useMemo, useState } from 'react'
import { useLocalFile, useOnlineDocuments, useTestRunSteps, useWebsiteCrawl } from './hooks'
import DataSourceOptions from './data-source-options'
import LocalFile from './data-source/local-file'
import { useProviderContextSelector } from '@/context/provider-context'
import OnlineDocuments from './data-source/online-documents'
import VectorSpaceFull from '@/app/components/billing/vector-space-full'
import WebsiteCrawl from './data-source/website-crawl'
import Actions from './data-source/actions'
import DocumentProcessing from './document-processing'
@ -20,8 +18,6 @@ import OnlineDrive from './data-source/online-drive'
const TestRunPanel = () => {
const setShowDebugAndPreviewPanel = useWorkflowStoreWithSelector(state => state.setShowDebugAndPreviewPanel)
const plan = useProviderContextSelector(state => state.plan)
const enableBilling = useProviderContextSelector(state => state.enableBilling)
const [datasource, setDatasource] = useState<Datasource>()
const {
@ -32,7 +28,6 @@ const TestRunPanel = () => {
} = useTestRunSteps()
const {
fileList,
allFileLoaded,
updateFile,
updateFileList,
} = useLocalFile()
@ -50,20 +45,18 @@ const TestRunPanel = () => {
} = useWebsiteCrawl()
const { handleRun } = useWorkflowRun()
const isVectorSpaceFull = plan.usage.vectorSpace >= plan.total.vectorSpace
const isShowVectorSpaceFull = allFileLoaded && isVectorSpaceFull && enableBilling
const datasourceType = datasource?.nodeData.provider_type
const nextBtnDisabled = useMemo(() => {
if (!datasource) return true
if (datasourceType === DatasourceType.localFile)
return isShowVectorSpaceFull || !fileList.length || fileList.some(file => !file.file.id)
return !fileList.length || fileList.some(file => !file.file.id)
if (datasourceType === DatasourceType.onlineDocument)
return isShowVectorSpaceFull || !onlineDocuments.length
return !onlineDocuments.length
if (datasourceType === DatasourceType.websiteCrawl)
return isShowVectorSpaceFull || !websitePages.length
return !websitePages.length
return false
}, [datasource, datasourceType, isShowVectorSpaceFull, fileList, onlineDocuments.length, websitePages.length])
}, [datasource, datasourceType, fileList, onlineDocuments.length, websitePages.length])
const handleClose = () => {
setShowDebugAndPreviewPanel(false)
@ -158,9 +151,6 @@ const TestRunPanel = () => {
/>
)
}
{isShowVectorSpaceFull && (
<VectorSpaceFull />
)}
</div>
<Actions disabled={nextBtnDisabled} handleNextStep={handleNextStep} />
<FooterTips />