| @@ -1,19 +1,9 @@ | |||
| import { useMemo } from 'react' | |||
| import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types' | |||
| import { usePublishedPipelineProcessingParams } from '@/service/use-pipeline' | |||
| import { PipelineInputVarType } from '@/models/pipeline' | |||
| import { VAR_TYPE_MAP } from '@/models/pipeline' | |||
| import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail' | |||
| const VAR_TYPE_MAP: Record<PipelineInputVarType, BaseFieldType> = { | |||
| [PipelineInputVarType.textInput]: BaseFieldType.textInput, | |||
| [PipelineInputVarType.paragraph]: BaseFieldType.paragraph, | |||
| [PipelineInputVarType.select]: BaseFieldType.select, | |||
| [PipelineInputVarType.singleFile]: BaseFieldType.file, | |||
| [PipelineInputVarType.multiFiles]: BaseFieldType.fileList, | |||
| [PipelineInputVarType.number]: BaseFieldType.numberInput, | |||
| [PipelineInputVarType.checkbox]: BaseFieldType.checkbox, | |||
| } | |||
| export const useConfigurations = (datasourceNodeId: string) => { | |||
| const pipelineId = useDatasetDetailContextWithSelector(state => state.dataset?.pipeline_id) | |||
| const { data: paramsConfig, isFetching: isFetchingParams } = usePublishedPipelineProcessingParams({ | |||
| @@ -1,21 +1,22 @@ | |||
| import type { BaseConfiguration, BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types' | |||
| import { PipelineInputVarType, type RAGPipelineVariables } from '@/models/pipeline' | |||
| import type { BaseConfiguration } from '@/app/components/base/form/form-scenarios/base/types' | |||
| import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types' | |||
| import { type RAGPipelineVariables, VAR_TYPE_MAP } from '@/models/pipeline' | |||
| import { useMemo } from 'react' | |||
| export const useInitialData = (variables: RAGPipelineVariables) => { | |||
| const initialData = useMemo(() => { | |||
| const initialData: Record<string, any> = {} | |||
| variables.forEach((item) => { | |||
| if ([PipelineInputVarType.textInput, PipelineInputVarType.paragraph, PipelineInputVarType.select].includes(item.type)) | |||
| initialData[item.variable] = item.default_value || '' | |||
| if (item.type === PipelineInputVarType.number) | |||
| initialData[item.variable] = item.default_value || 0 | |||
| if ([PipelineInputVarType.singleFile, PipelineInputVarType.multiFiles].includes(item.type)) | |||
| initialData[item.variable] = [] | |||
| if (item.type === PipelineInputVarType.checkbox) | |||
| initialData[item.variable] = item.default_value || true | |||
| }) | |||
| return initialData | |||
| return variables.reduce((acc, item) => { | |||
| const type = VAR_TYPE_MAP[item.type] | |||
| if ([BaseFieldType.textInput, BaseFieldType.paragraph, BaseFieldType.select].includes(type)) | |||
| acc[item.variable] = item.default_value ?? '' | |||
| if (type === BaseFieldType.numberInput) | |||
| acc[item.variable] = item.default_value ?? 0 | |||
| if (type === BaseFieldType.checkbox) | |||
| acc[item.variable] = true | |||
| if ([BaseFieldType.file, BaseFieldType.fileList].includes(type)) | |||
| acc[item.variable] = [] | |||
| return acc | |||
| }, {} as Record<string, any>) | |||
| }, [variables]) | |||
| return initialData | |||
| @@ -26,21 +27,22 @@ export const useConfigurations = (variables: RAGPipelineVariables) => { | |||
| const configurations: BaseConfiguration[] = [] | |||
| variables.forEach((item) => { | |||
| configurations.push({ | |||
| type: item.type as unknown as BaseFieldType, | |||
| type: VAR_TYPE_MAP[item.type], | |||
| variable: item.variable, | |||
| label: item.label, | |||
| required: item.required, | |||
| placeholder: item.placeholder, | |||
| tooltip: item.tooltips, | |||
| maxLength: item.max_length, | |||
| options: item.options?.map(option => ({ | |||
| label: option, | |||
| value: option, | |||
| })), | |||
| maxLength: item.max_length, | |||
| showConditions: [], | |||
| allowedFileUploadMethods: item.allowed_file_upload_methods, | |||
| placeholder: item.placeholder, | |||
| tooltip: item.tooltips, | |||
| unit: item.unit, | |||
| allowedFileTypes: item.allowed_file_types, | |||
| allowedFileExtensions: item.allowed_file_extensions, | |||
| allowedFileUploadMethods: item.allowed_file_upload_methods, | |||
| }) | |||
| }) | |||
| return configurations | |||
| @@ -3,17 +3,7 @@ import type { BaseConfiguration } from '@/app/components/base/form/form-scenario | |||
| import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types' | |||
| import { useStore } from '@/app/components/workflow/store' | |||
| import { useDraftPipelineProcessingParams } from '@/service/use-pipeline' | |||
| import { PipelineInputVarType } from '@/models/pipeline' | |||
| const VAR_TYPE_MAP: Record<PipelineInputVarType, BaseFieldType> = { | |||
| [PipelineInputVarType.textInput]: BaseFieldType.textInput, | |||
| [PipelineInputVarType.paragraph]: BaseFieldType.paragraph, | |||
| [PipelineInputVarType.select]: BaseFieldType.select, | |||
| [PipelineInputVarType.singleFile]: BaseFieldType.file, | |||
| [PipelineInputVarType.multiFiles]: BaseFieldType.fileList, | |||
| [PipelineInputVarType.number]: BaseFieldType.numberInput, | |||
| [PipelineInputVarType.checkbox]: BaseFieldType.checkbox, | |||
| } | |||
| import { VAR_TYPE_MAP } from '@/models/pipeline' | |||
| export const useConfigurations = (datasourceNodeId: string) => { | |||
| const pipelineId = useStore(state => state.pipelineId) | |||
| @@ -5,6 +5,7 @@ import type { Dependency } from '@/app/components/plugins/types' | |||
| import type { AppIconSelection } from '@/app/components/base/app-icon-picker' | |||
| import type { Viewport } from 'reactflow' | |||
| import type { TransferMethod } from '@/types/app' | |||
| import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types' | |||
| export enum DatasourceType { | |||
| localFile = 'local_file', | |||
| @@ -119,6 +120,16 @@ export enum PipelineInputVarType { | |||
| checkbox = 'checkbox', | |||
| } | |||
| export const VAR_TYPE_MAP: Record<PipelineInputVarType, BaseFieldType> = { | |||
| [PipelineInputVarType.textInput]: BaseFieldType.textInput, | |||
| [PipelineInputVarType.paragraph]: BaseFieldType.paragraph, | |||
| [PipelineInputVarType.select]: BaseFieldType.select, | |||
| [PipelineInputVarType.singleFile]: BaseFieldType.file, | |||
| [PipelineInputVarType.multiFiles]: BaseFieldType.fileList, | |||
| [PipelineInputVarType.number]: BaseFieldType.numberInput, | |||
| [PipelineInputVarType.checkbox]: BaseFieldType.checkbox, | |||
| } | |||
| export type RAGPipelineVariable = { | |||
| belong_to_node_id: string // indicates belong to which node or 'shared' | |||
| type: PipelineInputVarType | |||