From 789cada297f29b3854d56214f75985b9855cb546 Mon Sep 17 00:00:00 2001 From: yyh <92089059+lyzno1@users.noreply.github.com> Date: Mon, 7 Sep 2026 04:15:40 +0000 Subject: [PATCH] refactor(web): migrate workflow error default inputs (#41900) --- oxlint-suppressions.json | 8 ---- .../error-handle/__tests__/index.spec.tsx | 29 ++++++++++-- .../components/error-handle/default-value.tsx | 46 ++++++++----------- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json index f5a87615ccb..9d6abf0a5b4 100644 --- a/oxlint-suppressions.json +++ b/oxlint-suppressions.json @@ -3260,14 +3260,6 @@ "count": 1 } }, - "web/app/components/workflow/nodes/_base/components/error-handle/default-value.tsx": { - "no-restricted-imports": { - "count": 1 - }, - "typescript/no-explicit-any": { - "count": 1 - } - }, "web/app/components/workflow/nodes/_base/components/error-handle/types.ts": { "erasable-syntax-only/enums": { "count": 1 diff --git a/web/app/components/workflow/nodes/_base/components/error-handle/__tests__/index.spec.tsx b/web/app/components/workflow/nodes/_base/components/error-handle/__tests__/index.spec.tsx index 7aafc97d05d..bccbc325c6e 100644 --- a/web/app/components/workflow/nodes/_base/components/error-handle/__tests__/index.spec.tsx +++ b/web/app/components/workflow/nodes/_base/components/error-handle/__tests__/index.spec.tsx @@ -123,7 +123,8 @@ describe('error-handle path', () => { ) }) - it('should render string forms and surface array forms in the default value editor', () => { + it('should edit a labeled string default and preserve the array editor', async () => { + const user = userEvent.setup() const onFormChange = vi.fn() render( { />, ) - fireEvent.change(screen.getByDisplayValue('hello'), { target: { value: 'updated' } }) + const input = screen.getByRole('textbox', { name: 'message' }) + await user.click(screen.getByText('message')) + expect(input).toHaveFocus() + await user.type(input, '!') expect(onFormChange).toHaveBeenCalledWith({ key: 'message', type: VarType.string, - value: 'updated', + value: 'hello!', }) expect(screen.getByText('items')).toBeInTheDocument() }) + it('should report a numeric default as a string to the workflow owner', async () => { + const user = userEvent.setup() + const onFormChange = vi.fn() + render( + , + ) + + await user.type(screen.getByRole('spinbutton', { name: 'count' }), '3') + + expect(onFormChange).toHaveBeenLastCalledWith({ + key: 'count', + type: VarType.number, + value: '123', + }) + }) + it('should toggle the selector popup and report the selected strategy', async () => { const user = userEvent.setup() const onSelected = vi.fn() diff --git a/web/app/components/workflow/nodes/_base/components/error-handle/default-value.tsx b/web/app/components/workflow/nodes/_base/components/error-handle/default-value.tsx index eff1e6e7f9e..ab8c5102fed 100644 --- a/web/app/components/workflow/nodes/_base/components/error-handle/default-value.tsx +++ b/web/app/components/workflow/nodes/_base/components/error-handle/default-value.tsx @@ -1,7 +1,7 @@ import type { DefaultValueForm } from './types' -import { useCallback } from 'react' +import { Input } from '@langgenius/dify-ui/input' +import { useId } from 'react' import { useTranslation } from 'react-i18next' -import Input from '@/app/components/base/input' import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor' import { CodeLanguage } from '@/app/components/workflow/nodes/code/types' import { VarType } from '@/app/components/workflow/types' @@ -12,27 +12,7 @@ type DefaultValueProps = { } const DefaultValue = ({ forms, onFormChange }: DefaultValueProps) => { const { t } = useTranslation() - const getFormChangeHandler = useCallback( - ({ key, type }: DefaultValueForm) => { - return (payload: any) => { - let value - if (type === VarType.string || type === VarType.number) value = payload.target.value - - if ( - type === VarType.array || - type === VarType.arrayNumber || - type === VarType.arrayString || - type === VarType.arrayObject || - type === VarType.arrayFile || - type === VarType.object - ) - value = payload - - onFormChange({ key, type, value }) - } - }, - [onFormChange], - ) + const id = useId() return (
@@ -42,17 +22,27 @@ const DefaultValue = ({ forms, onFormChange }: DefaultValueProps) => {
{forms.map((form, index) => { + const isInput = form.type === VarType.string || form.type === VarType.number + const inputId = `${id}-${index}` return (
-
{form.key}
+ {isInput ? ( + + ) : ( +
{form.key}
+ )}
{form.type}
- {(form.type === VarType.string || form.type === VarType.number) && ( + {isInput && ( $['placeholder.input'], { ns: 'common' })} value={form.value || (form.type === VarType.string ? '' : 0)} - onChange={getFormChangeHandler({ key: form.key, type: form.type })} + onValueChange={(value) => onFormChange({ key: form.key, type: form.type, value })} /> )} {(form.type === VarType.array || @@ -63,7 +53,7 @@ const DefaultValue = ({ forms, onFormChange }: DefaultValueProps) => { onFormChange({ key: form.key, type: form.type, value })} /> )}