mirror of https://github.com/langgenius/dify.git
refactor: update input variable types and initial data handling in pipeline components
This commit is contained in:
parent
720ce79901
commit
c9bf99a1e2
|
|
@ -20,6 +20,7 @@ export type ShowCondition = {
|
|||
export type NumberConfiguration = {
|
||||
max?: number
|
||||
min?: number
|
||||
unit?: string
|
||||
}
|
||||
|
||||
export type SelectConfiguration = {
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ export const useHiddenConfigurations = (props: {
|
|||
}, {
|
||||
type: InputFieldType.textInput,
|
||||
label: t('appDebug.variableConfig.tooltips'),
|
||||
variable: 'hint',
|
||||
variable: 'tooltips',
|
||||
required: false,
|
||||
showConditions: [],
|
||||
showOptional: true,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export const useInitialData = (variables: RAGPipelineVariables) => {
|
|||
if (item.type === PipelineInputVarType.number)
|
||||
initialData[item.variable] = item.default_value || 0
|
||||
if ([PipelineInputVarType.singleFile, PipelineInputVarType.multiFiles].includes(item.type))
|
||||
initialData[item.variable] = item.default_value || []
|
||||
initialData[item.variable] = []
|
||||
if (item.type === PipelineInputVarType.checkbox)
|
||||
initialData[item.variable] = item.default_value || true
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
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 { useDraftPipelineProcessingParams } from '@/service/use-pipeline'
|
||||
import { PipelineInputVarType } from '@/models/pipeline'
|
||||
|
||||
type PartialInputVarType = PipelineInputVarType.textInput | PipelineInputVarType.number | PipelineInputVarType.select | PipelineInputVarType.checkbox
|
||||
|
||||
const VAR_TYPE_MAP: Record<PartialInputVarType, BaseFieldType> = {
|
||||
const VAR_TYPE_MAP: Record<PipelineInputVarType, BaseFieldType> = {
|
||||
[PipelineInputVarType.textInput]: BaseFieldType.textInput,
|
||||
[PipelineInputVarType.number]: BaseFieldType.numberInput,
|
||||
[PipelineInputVarType.paragraph]: BaseFieldType.textInput,
|
||||
[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 = useStore(state => state.pipelineId)
|
||||
const { data: paramsConfig } = useDraftPipelineProcessingParams({
|
||||
|
|
@ -23,23 +24,23 @@ export const useConfigurations = (datasourceNodeId: string) => {
|
|||
const initialData = useMemo(() => {
|
||||
const variables = paramsConfig?.variables || []
|
||||
return variables.reduce((acc, item) => {
|
||||
const type = VAR_TYPE_MAP[item.type as PartialInputVarType]
|
||||
if (type === BaseFieldType.textInput)
|
||||
acc[item.variable] = ''
|
||||
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] = 0
|
||||
if (type === BaseFieldType.select)
|
||||
acc[item.variable] = item.options?.[0] || ''
|
||||
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 as PartialInputVarType],
|
||||
const configs: BaseConfiguration[] = variables.map(item => ({
|
||||
type: VAR_TYPE_MAP[item.type],
|
||||
variable: item.variable,
|
||||
label: item.label,
|
||||
required: item.required,
|
||||
|
|
@ -50,6 +51,12 @@ export const useConfigurations = (datasourceNodeId: string) => {
|
|||
})),
|
||||
showConditions: [],
|
||||
default: item.default_value,
|
||||
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])
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ const Options = ({
|
|||
if (!result.success) {
|
||||
const issues = result.error.issues
|
||||
const firstIssue = issues[0]
|
||||
const errorMessage = `"${firstIssue.path.join('.')}" ${firstIssue.message}`
|
||||
const errorMessage = `Path: ${firstIssue.path.join('.')} Error: ${firstIssue.message}`
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
message: errorMessage,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ export const useDatasourceOptions = () => {
|
|||
const datasourceNodes = nodes.filter(node => node.data.type === BlockEnum.DataSource)
|
||||
return datasourceNodes.map((node) => {
|
||||
let type: DataSourceType | DataSourceProvider = DataSourceType.FILE
|
||||
// todo: distinguish datasource type via provider_type field
|
||||
switch (node.data.tool_name) {
|
||||
case 'file_upload':
|
||||
type = DataSourceType.FILE
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ const TestRunPanel = () => {
|
|||
}
|
||||
handleRun({
|
||||
inputs: data,
|
||||
start_node_id: datasource.nodeId,
|
||||
datasource_type,
|
||||
datasource_info: datasourceInfo,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -98,12 +98,12 @@ export type PipelineCheckDependenciesResponse = {
|
|||
}
|
||||
|
||||
export enum PipelineInputVarType {
|
||||
textInput = 'textInput',
|
||||
textInput = 'text-input',
|
||||
paragraph = 'paragraph',
|
||||
select = 'select',
|
||||
number = 'numberInput',
|
||||
number = 'number-input',
|
||||
singleFile = 'file',
|
||||
multiFiles = 'fileList',
|
||||
multiFiles = 'file-list',
|
||||
checkbox = 'checkbox',
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ export const useDraftPipelineProcessingParams = (params: PipelineProcessingParam
|
|||
},
|
||||
})
|
||||
},
|
||||
staleTime: 0,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue