From cf0551433d945b7bbe8f1d46fb001e71f7ca90cb Mon Sep 17 00:00:00 2001 From: buua436 Date: Mon, 9 Nov 2026 14:34:29 +0800 Subject: [PATCH] fix: correct agent tool, schema, and save handling (#22089) --- .../schema-editor/types/array-editor.test.tsx | 37 ++++++++++++++ .../schema-editor/types/array-editor.tsx | 14 +++-- .../gobal-variable-sheet/hooks/use-form.tsx | 2 +- .../agent/gobal-variable-sheet/index.tsx | 2 +- .../use-agent-tool-initial-values.test.ts | 32 ++++++++++++ .../hooks/use-agent-tool-initial-values.ts | 3 +- .../agent/hooks/use-run-preflight.test.ts | 29 +++++++++++ web/src/pages/agent/hooks/use-save-graph.ts | 51 ++++++++++++------- web/src/pages/agent/index.tsx | 8 +-- 9 files changed, 147 insertions(+), 31 deletions(-) create mode 100644 web/src/components/jsonjoy-builder/components/schema-editor/types/array-editor.test.tsx diff --git a/web/src/components/jsonjoy-builder/components/schema-editor/types/array-editor.test.tsx b/web/src/components/jsonjoy-builder/components/schema-editor/types/array-editor.test.tsx new file mode 100644 index 0000000000..f3c705cf23 --- /dev/null +++ b/web/src/components/jsonjoy-builder/components/schema-editor/types/array-editor.test.tsx @@ -0,0 +1,37 @@ +import { + act, + fireEvent, + render, + screen, + waitFor, +} from '@testing-library/react'; +import ArrayEditor from './array-editor'; + +jest.mock('../type-editor', () => ({ + __esModule: true, + default: () => null, +})); + +describe('ArrayEditor', () => { + it('writes the latest uniqueItems switch value to the schema', async () => { + const onChange = jest.fn(); + + render( + , + ); + + await act(async () => { + fireEvent.click(screen.getByRole('switch')); + }); + + await waitFor(() => { + expect(onChange).toHaveBeenCalledWith( + expect.objectContaining({ uniqueItems: true }), + ); + }); + }); +}); diff --git a/web/src/components/jsonjoy-builder/components/schema-editor/types/array-editor.tsx b/web/src/components/jsonjoy-builder/components/schema-editor/types/array-editor.tsx index b50a2add3e..908f9ffb2f 100644 --- a/web/src/components/jsonjoy-builder/components/schema-editor/types/array-editor.tsx +++ b/web/src/components/jsonjoy-builder/components/schema-editor/types/array-editor.tsx @@ -43,13 +43,13 @@ const ArrayEditor: React.FC = ({ ); // Handle validation settings change - const handleValidationChange = () => { + const handleValidationChange = (nextUniqueItems = uniqueItems) => { const validationProps: ObjectJSONSchema = { type: 'array', ...(isBooleanSchema(schema) ? {} : schema), minItems: minItems, maxItems: maxItems, - uniqueItems: uniqueItems || undefined, + uniqueItems: nextUniqueItems || undefined, }; // Keep the items schema @@ -68,6 +68,10 @@ const ArrayEditor: React.FC = ({ onChange(propsToKeep as ObjectJSONSchema); }; + const handleValidationBlur = () => { + handleValidationChange(); + }; + // Handle item schema changes const handleItemSchemaChange = (updatedItemSchema: ObjectJSONSchema) => { const updatedSchema: ObjectJSONSchema = { @@ -125,7 +129,7 @@ const ArrayEditor: React.FC = ({ setMinItems(value); // Don't update immediately to avoid too many rerenders }} - onBlur={handleValidationChange} + onBlur={handleValidationBlur} placeholder={t.arrayMinimumPlaceholder} className={cn('h-8', !!minMaxError && 'border-destructive')} /> @@ -150,7 +154,7 @@ const ArrayEditor: React.FC = ({ setMaxItems(value); // Don't update immediately to avoid too many rerenders }} - onBlur={handleValidationChange} + onBlur={handleValidationBlur} placeholder={t.arrayMaximumPlaceholder} className={cn('h-8', !!minMaxError && 'border-destructive')} /> @@ -170,7 +174,7 @@ const ArrayEditor: React.FC = ({ checked={uniqueItems} onCheckedChange={(checked) => { setUniqueItems(checked); - setTimeout(handleValidationChange, 0); + handleValidationChange(checked); }} />