| {!isPending && currentDocForm === ChunkingMode.qa && estimateData?.qa_preview && ( | {!isPending && currentDocForm === ChunkingMode.qa && estimateData?.qa_preview && ( | ||||
| estimateData?.qa_preview.map((item, index) => ( | estimateData?.qa_preview.map((item, index) => ( | ||||
| <ChunkContainer | <ChunkContainer | ||||
| key={item.question} | |||||
| key={`${item.question}-${index}`} | |||||
| label={`Chunk-${index + 1}`} | label={`Chunk-${index + 1}`} | ||||
| characterCount={item.question.length + item.answer.length} | characterCount={item.question.length + item.answer.length} | ||||
| > | > | ||||
| {!isPending && currentDocForm === ChunkingMode.text && estimateData?.preview && ( | {!isPending && currentDocForm === ChunkingMode.text && estimateData?.preview && ( | ||||
| estimateData?.preview.map((item, index) => ( | estimateData?.preview.map((item, index) => ( | ||||
| <ChunkContainer | <ChunkContainer | ||||
| key={item.content} | |||||
| key={`${item.content}-${index}`} | |||||
| label={`Chunk-${index + 1}`} | label={`Chunk-${index + 1}`} | ||||
| characterCount={item.content.length} | characterCount={item.content.length} | ||||
| > | > | ||||
| const indexForLabel = index + 1 | const indexForLabel = index + 1 | ||||
| return ( | return ( | ||||
| <ChunkContainer | <ChunkContainer | ||||
| key={item.content} | |||||
| key={`${item.content}-${index}`} | |||||
| label={`Chunk-${indexForLabel}`} | label={`Chunk-${indexForLabel}`} | ||||
| characterCount={item.content.length} | characterCount={item.content.length} | ||||
| > | > |
| const Preparation = () => { | const Preparation = () => { | ||||
| const { | const { | ||||
| localFileList: fileList, | |||||
| localFileList, | |||||
| onlineDocuments, | onlineDocuments, | ||||
| websitePages, | websitePages, | ||||
| selectedFileIds, | selectedFileIds, | ||||
| const nextBtnDisabled = useMemo(() => { | const nextBtnDisabled = useMemo(() => { | ||||
| if (!datasource) return true | if (!datasource) return true | ||||
| if (datasourceType === DatasourceType.localFile) | if (datasourceType === DatasourceType.localFile) | ||||
| return !fileList.length || fileList.some(file => !file.file.id) | |||||
| return !localFileList.length || localFileList.some(file => !file.file.id) | |||||
| if (datasourceType === DatasourceType.onlineDocument) | if (datasourceType === DatasourceType.onlineDocument) | ||||
| return !onlineDocuments.length | return !onlineDocuments.length | ||||
| if (datasourceType === DatasourceType.websiteCrawl) | if (datasourceType === DatasourceType.websiteCrawl) | ||||
| if (datasourceType === DatasourceType.onlineDrive) | if (datasourceType === DatasourceType.onlineDrive) | ||||
| return !selectedFileIds.length | return !selectedFileIds.length | ||||
| return false | return false | ||||
| }, [datasource, datasourceType, fileList, onlineDocuments.length, selectedFileIds.length, websitePages.length]) | |||||
| }, [datasource, datasourceType, localFileList, onlineDocuments.length, selectedFileIds.length, websitePages.length]) | |||||
| const { handleRun } = useWorkflowRun() | const { handleRun } = useWorkflowRun() | ||||
| handleRunWithSyncDraft, | handleRunWithSyncDraft, | ||||
| datasourceType, | datasourceType, | ||||
| datasourceNodeData, | datasourceNodeData, | ||||
| startRunBtnDisabled, | |||||
| } = useBeforeRunForm(props) | } = useBeforeRunForm(props) | ||||
| const { clearOnlineDocumentData } = useOnlineDocument() | const { clearOnlineDocumentData } = useOnlineDocument() | ||||
| onClick={handleRunWithSyncDraft} | onClick={handleRunWithSyncDraft} | ||||
| variant='primary' | variant='primary' | ||||
| loading={isPending} | loading={isPending} | ||||
| disabled={isPending} | |||||
| disabled={isPending || startRunBtnDisabled} | |||||
| > | > | ||||
| {t('workflow.singleRun.startRun')} | {t('workflow.singleRun.startRun')} | ||||
| </Button> | </Button> |
| import { useStoreApi } from 'reactflow' | import { useStoreApi } from 'reactflow' | ||||
| import type { CustomRunFormProps, DataSourceNodeType } from '../types' | import type { CustomRunFormProps, DataSourceNodeType } from '../types' | ||||
| import { useEffect, useRef } from 'react' | |||||
| import { useEffect, useMemo, useRef } from 'react' | |||||
| import { useNodeDataUpdate, useNodesSyncDraft } from '../../../hooks' | import { useNodeDataUpdate, useNodesSyncDraft } from '../../../hooks' | ||||
| import { NodeRunningStatus } from '../../../types' | import { NodeRunningStatus } from '../../../types' | ||||
| import { useInvalidLastRun } from '@/service/use-workflow' | import { useInvalidLastRun } from '@/service/use-workflow' | ||||
| import { fetchNodeInspectVars } from '@/service/workflow' | import { fetchNodeInspectVars } from '@/service/workflow' | ||||
| import { FlowType } from '@/types/common' | import { FlowType } from '@/types/common' | ||||
| import { useDatasourceSingleRun } from '@/service/use-pipeline' | import { useDatasourceSingleRun } from '@/service/use-pipeline' | ||||
| import { useDataSourceStore } from '@/app/components/datasets/documents/create-from-pipeline/data-source/store' | |||||
| import { useDataSourceStore, useDataSourceStoreWithSelector } from '@/app/components/datasets/documents/create-from-pipeline/data-source/store' | |||||
| import { DatasourceType } from '@/models/pipeline' | import { DatasourceType } from '@/models/pipeline' | ||||
| import { TransferMethod } from '@/types/app' | import { TransferMethod } from '@/types/app' | ||||
| import { useShallow } from 'zustand/react/shallow' | |||||
| const useBeforeRunForm = ({ | const useBeforeRunForm = ({ | ||||
| nodeId, | nodeId, | ||||
| const datasourceType = payload.provider_type as DatasourceType | const datasourceType = payload.provider_type as DatasourceType | ||||
| const datasourceNodeData = payload as DataSourceNodeType | const datasourceNodeData = payload as DataSourceNodeType | ||||
| const { | |||||
| localFileList, | |||||
| onlineDocuments, | |||||
| websitePages, | |||||
| selectedFileIds, | |||||
| } = useDataSourceStoreWithSelector(useShallow(state => ({ | |||||
| localFileList: state.localFileList, | |||||
| onlineDocuments: state.onlineDocuments, | |||||
| websitePages: state.websitePages, | |||||
| selectedFileIds: state.selectedFileIds, | |||||
| }))) | |||||
| const startRunBtnDisabled = useMemo(() => { | |||||
| if (!datasourceNodeData) return false | |||||
| if (datasourceType === DatasourceType.localFile) | |||||
| return !localFileList.length || localFileList.some(file => !file.file.id) | |||||
| if (datasourceType === DatasourceType.onlineDocument) | |||||
| return !onlineDocuments.length | |||||
| if (datasourceType === DatasourceType.websiteCrawl) | |||||
| return !websitePages.length | |||||
| if (datasourceType === DatasourceType.onlineDrive) | |||||
| return !selectedFileIds.length | |||||
| return false | |||||
| }, [datasourceNodeData, datasourceType, localFileList, onlineDocuments.length, selectedFileIds.length, websitePages.length]) | |||||
| useEffect(() => { | useEffect(() => { | ||||
| isPausedRef.current = isPaused | isPausedRef.current = isPaused | ||||
| }, [isPaused]) | }, [isPaused]) | ||||
| handleRunWithSyncDraft, | handleRunWithSyncDraft, | ||||
| datasourceType, | datasourceType, | ||||
| datasourceNodeData, | datasourceNodeData, | ||||
| startRunBtnDisabled, | |||||
| } | } | ||||
| } | } | ||||