|
|
|
|
@ -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
|
|
|
|
|
|