feat: refactor input variable handling and configurations in pipeline processing components
parent
261b7cabc8
commit
c6ae9628af
@ -1,58 +1,15 @@
|
|||||||
import { useMemo } from 'react'
|
|
||||||
import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types'
|
|
||||||
import { usePublishedPipelineProcessingParams } from '@/service/use-pipeline'
|
import { usePublishedPipelineProcessingParams } from '@/service/use-pipeline'
|
||||||
import { VAR_TYPE_MAP } from '@/models/pipeline'
|
|
||||||
import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail'
|
import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail'
|
||||||
|
|
||||||
export const useConfigurations = (datasourceNodeId: string) => {
|
export const useInputVariables = (datasourceNodeId: string) => {
|
||||||
const pipelineId = useDatasetDetailContextWithSelector(state => state.dataset?.pipeline_id)
|
const pipelineId = useDatasetDetailContextWithSelector(state => state.dataset?.pipeline_id)
|
||||||
const { data: paramsConfig, isFetching: isFetchingParams } = usePublishedPipelineProcessingParams({
|
const { data: paramsConfig, isFetching: isFetchingParams } = usePublishedPipelineProcessingParams({
|
||||||
pipeline_id: pipelineId!,
|
pipeline_id: pipelineId!,
|
||||||
node_id: datasourceNodeId,
|
node_id: datasourceNodeId,
|
||||||
})
|
})
|
||||||
|
|
||||||
const initialData = useMemo(() => {
|
|
||||||
const variables = paramsConfig?.variables || []
|
|
||||||
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>)
|
|
||||||
}, [paramsConfig])
|
|
||||||
|
|
||||||
const configurations = useMemo(() => {
|
|
||||||
const variables = paramsConfig?.variables || []
|
|
||||||
const configs = variables.map(item => ({
|
|
||||||
type: VAR_TYPE_MAP[item.type],
|
|
||||||
variable: item.variable,
|
|
||||||
label: item.label,
|
|
||||||
required: item.required,
|
|
||||||
maxLength: item.max_length,
|
|
||||||
options: item.options?.map(option => ({
|
|
||||||
label: option,
|
|
||||||
value: option,
|
|
||||||
})),
|
|
||||||
showConditions: [],
|
|
||||||
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 configs
|
|
||||||
}, [paramsConfig])
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
paramsConfig,
|
||||||
isFetchingParams,
|
isFetchingParams,
|
||||||
initialData,
|
|
||||||
configurations,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,59 +1,15 @@
|
|||||||
import { useMemo } from 'react'
|
|
||||||
import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail'
|
import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail'
|
||||||
import { usePublishedPipelineProcessingParams } from '@/service/use-pipeline'
|
import { usePublishedPipelineProcessingParams } from '@/service/use-pipeline'
|
||||||
import { VAR_TYPE_MAP } from '@/models/pipeline'
|
|
||||||
import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types'
|
|
||||||
|
|
||||||
export const useConfigurations = (lastRunInputData: Record<string, any>, datasourceNodeId: string) => {
|
export const useInputVariables = (datasourceNodeId: string) => {
|
||||||
const pipelineId = useDatasetDetailContextWithSelector(state => state.dataset?.pipeline_id)
|
const pipelineId = useDatasetDetailContextWithSelector(state => state.dataset?.pipeline_id)
|
||||||
const { data: paramsConfig, isFetching: isFetchingParams } = usePublishedPipelineProcessingParams({
|
const { data: paramsConfig, isFetching: isFetchingParams } = usePublishedPipelineProcessingParams({
|
||||||
pipeline_id: pipelineId!,
|
pipeline_id: pipelineId!,
|
||||||
node_id: datasourceNodeId,
|
node_id: datasourceNodeId,
|
||||||
})
|
})
|
||||||
|
|
||||||
const initialData = useMemo(() => {
|
|
||||||
const variables = paramsConfig?.variables || []
|
|
||||||
return variables.reduce((acc, item) => {
|
|
||||||
const type = VAR_TYPE_MAP[item.type]
|
|
||||||
const variableName = item.variable
|
|
||||||
if ([BaseFieldType.textInput, BaseFieldType.paragraph, BaseFieldType.select].includes(type))
|
|
||||||
acc[item.variable] = lastRunInputData[variableName] ?? ''
|
|
||||||
if (type === BaseFieldType.numberInput)
|
|
||||||
acc[item.variable] = lastRunInputData[variableName] ?? 0
|
|
||||||
if (type === BaseFieldType.checkbox)
|
|
||||||
acc[item.variable] = lastRunInputData[variableName]
|
|
||||||
if ([BaseFieldType.file, BaseFieldType.fileList].includes(type))
|
|
||||||
acc[item.variable] = lastRunInputData[variableName]
|
|
||||||
return acc
|
|
||||||
}, {} as Record<string, any>)
|
|
||||||
}, [lastRunInputData, paramsConfig?.variables])
|
|
||||||
|
|
||||||
const configurations = useMemo(() => {
|
|
||||||
const variables = paramsConfig?.variables || []
|
|
||||||
const configs = variables.map(item => ({
|
|
||||||
type: VAR_TYPE_MAP[item.type],
|
|
||||||
variable: item.variable,
|
|
||||||
label: item.label,
|
|
||||||
required: item.required,
|
|
||||||
maxLength: item.max_length,
|
|
||||||
options: item.options?.map(option => ({
|
|
||||||
label: option,
|
|
||||||
value: option,
|
|
||||||
})),
|
|
||||||
showConditions: [],
|
|
||||||
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 configs
|
|
||||||
}, [paramsConfig])
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
paramsConfig,
|
||||||
isFetchingParams,
|
isFetchingParams,
|
||||||
initialData,
|
|
||||||
configurations,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,59 +1,15 @@
|
|||||||
import { useMemo } from 'react'
|
|
||||||
import type { BaseConfiguration } from '@/app/components/base/form/form-scenarios/base/types'
|
|
||||||
import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types'
|
|
||||||
import { useStore } from '@/app/components/workflow/store'
|
import { useStore } from '@/app/components/workflow/store'
|
||||||
import { useDraftPipelineProcessingParams } from '@/service/use-pipeline'
|
import { useDraftPipelineProcessingParams } from '@/service/use-pipeline'
|
||||||
import { VAR_TYPE_MAP } from '@/models/pipeline'
|
|
||||||
|
|
||||||
export const useConfigurations = (datasourceNodeId: string) => {
|
export const useInputVariables = (datasourceNodeId: string) => {
|
||||||
const pipelineId = useStore(state => state.pipelineId)
|
const pipelineId = useStore(state => state.pipelineId)
|
||||||
const { data: paramsConfig, isFetching: isFetchingParams } = useDraftPipelineProcessingParams({
|
const { data: paramsConfig, isFetching: isFetchingParams } = useDraftPipelineProcessingParams({
|
||||||
pipeline_id: pipelineId!,
|
pipeline_id: pipelineId!,
|
||||||
node_id: datasourceNodeId,
|
node_id: datasourceNodeId,
|
||||||
})
|
})
|
||||||
|
|
||||||
const initialData = useMemo(() => {
|
|
||||||
const variables = paramsConfig?.variables || []
|
|
||||||
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>)
|
|
||||||
}, [paramsConfig])
|
|
||||||
|
|
||||||
const configurations = useMemo(() => {
|
|
||||||
const variables = paramsConfig?.variables || []
|
|
||||||
const configs: BaseConfiguration[] = variables.map(item => ({
|
|
||||||
type: VAR_TYPE_MAP[item.type],
|
|
||||||
variable: item.variable,
|
|
||||||
label: item.label,
|
|
||||||
required: item.required,
|
|
||||||
maxLength: item.max_length,
|
|
||||||
options: item.options?.map(option => ({
|
|
||||||
label: option,
|
|
||||||
value: option,
|
|
||||||
})),
|
|
||||||
showConditions: [],
|
|
||||||
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 configs
|
|
||||||
}, [paramsConfig])
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isFetchingParams,
|
isFetchingParams,
|
||||||
initialData,
|
paramsConfig,
|
||||||
configurations,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,23 +1,25 @@
|
|||||||
|
import { useMemo } from 'react'
|
||||||
import type { BaseConfiguration } from '@/app/components/base/form/form-scenarios/base/types'
|
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 { type RAGPipelineVariables, VAR_TYPE_MAP } from '@/models/pipeline'
|
||||||
import { useMemo } from 'react'
|
import { BaseFieldType } from '@/app/components/base/form/form-scenarios/base/types'
|
||||||
|
|
||||||
export const useInitialData = (variables: RAGPipelineVariables) => {
|
export const useInitialData = (variables: RAGPipelineVariables, lastRunInputData?: Record<string, any>) => {
|
||||||
const initialData = useMemo(() => {
|
const initialData = useMemo(() => {
|
||||||
return variables.reduce((acc, item) => {
|
return variables.reduce((acc, item) => {
|
||||||
const type = VAR_TYPE_MAP[item.type]
|
const type = VAR_TYPE_MAP[item.type]
|
||||||
|
const variableName = item.variable
|
||||||
|
const defaultValue = lastRunInputData?.[variableName] || item.default_value
|
||||||
if ([BaseFieldType.textInput, BaseFieldType.paragraph, BaseFieldType.select].includes(type))
|
if ([BaseFieldType.textInput, BaseFieldType.paragraph, BaseFieldType.select].includes(type))
|
||||||
acc[item.variable] = item.default_value ?? ''
|
acc[variableName] = defaultValue ?? ''
|
||||||
if (type === BaseFieldType.numberInput)
|
if (type === BaseFieldType.numberInput)
|
||||||
acc[item.variable] = item.default_value ?? 0
|
acc[variableName] = defaultValue ?? 0
|
||||||
if (type === BaseFieldType.checkbox)
|
if (type === BaseFieldType.checkbox)
|
||||||
acc[item.variable] = true
|
acc[variableName] = defaultValue ?? false
|
||||||
if ([BaseFieldType.file, BaseFieldType.fileList].includes(type))
|
if ([BaseFieldType.file, BaseFieldType.fileList].includes(type))
|
||||||
acc[item.variable] = []
|
acc[variableName] = defaultValue ?? []
|
||||||
return acc
|
return acc
|
||||||
}, {} as Record<string, any>)
|
}, {} as Record<string, any>)
|
||||||
}, [variables])
|
}, [lastRunInputData, variables])
|
||||||
|
|
||||||
return initialData
|
return initialData
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue