Add constant select options editor

This commit is contained in:
JzoNg 2026-04-22 07:46:47 +08:00
parent 022d73d0ed
commit 00f0f6d040
2 changed files with 67 additions and 0 deletions

View File

@ -38,6 +38,15 @@ vi.mock('@/app/components/app/configuration/config-var/config-modal/type-select'
),
}))
vi.mock('@/app/components/app/configuration/config-var/config-select', () => ({
__esModule: true,
default: ({ onChange }: { onChange: (options: string[]) => void }) => (
<button type="button" onClick={() => onChange(['alpha', 'beta'])}>
config-select
</button>
),
}))
const createPayload = (overrides?: Partial<FormInputItem>): FormInputItem => ({
type: InputVarType.paragraph,
output_variable_name: 'valid_name',
@ -346,4 +355,34 @@ describe('InputField', () => {
await user.click(screen.getByRole('button', { name: 'select-paragraph' }))
expect(screen.getByText(/workflow\.nodes\.humanInput\.insertInputField\.prePopulateField/i)).toBeInTheDocument()
})
it('should save constant select options', async () => {
const user = userEvent.setup()
const onChange = vi.fn()
render(
<InputField
nodeId="node-9"
isEdit={false}
payload={createPayload()}
onChange={onChange}
onCancel={vi.fn()}
/>,
)
await user.click(screen.getByRole('button', { name: 'select-select' }))
await user.click(screen.getByRole('button', { name: 'config-select' }))
await user.click(screen.getByRole('button', { name: /workflow\.nodes\.humanInput\.insertInputField\.insert/i }))
expect(onChange).toHaveBeenCalledTimes(1)
expect(onChange.mock.calls[0]![0]).toEqual({
type: InputVarType.select,
output_variable_name: 'valid_name',
option_source: {
type: 'constant',
selector: [],
value: ['alpha', 'beta'],
},
})
})
})

View File

@ -7,11 +7,13 @@ import * as React from 'react'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import TypeSelector from '@/app/components/app/configuration/config-var/config-modal/type-select'
import ConfigSelect from '@/app/components/app/configuration/config-var/config-select'
import Input from '@/app/components/base/input'
import {
createDefaultFormInputByType,
createDefaultParagraphFormInput,
isParagraphFormInput,
isSelectFormInput,
} from '@/app/components/workflow/nodes/human-input/types'
import { InputVarType } from '@/app/components/workflow/types'
import { getKeyboardKeyNameBySystem } from '@/app/components/workflow/utils'
@ -99,6 +101,21 @@ const InputField: React.FC<InputFieldProps> = ({
setTempPayload(nextValue)
}
}, [paragraphPayload])
const handleSelectOptionsChange = useCallback((options: string[]) => {
setTempPayload((prev) => {
if (!isSelectFormInput(prev))
return prev
return {
...prev,
option_source: {
...prev.option_source,
type: 'constant',
value: options,
},
}
})
}, [])
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
@ -166,6 +183,17 @@ const InputField: React.FC<InputFieldProps> = ({
/>
</div>
)}
{isSelectFormInput(tempPayload) && (
<div className="mt-4">
<div className="mb-1.5 system-xs-medium text-text-secondary">
{t('variableConfig.options', { ns: 'appDebug' })}
</div>
<ConfigSelect
options={tempPayload.option_source.value}
onChange={handleSelectOptionsChange}
/>
</div>
)}
<div className="mt-4 flex justify-end space-x-2">
<Button data-testid="hitl-input-cancel-btn" onClick={onCancel}>{t('operation.cancel', { ns: 'common' })}</Button>
{isEdit