This is an automated email from the ASF dual-hosted git repository.

baoyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b0fd13d5 fix(route): allow empty optional vars editor (#3362) (#3363)
9b0fd13d5 is described below

commit 9b0fd13d5dbf56c83e1de715b004dd52f9cad26c
Author: Divyanshu Singh <[email protected]>
AuthorDate: Thu Apr 2 07:56:37 2026 +0530

    fix(route): allow empty optional vars editor (#3362) (#3363)
---
 e2e/tests/routes.crud-required-fields.spec.ts | 14 +++++++++++++-
 src/components/form/Editor.tsx                |  9 +++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/e2e/tests/routes.crud-required-fields.spec.ts 
b/e2e/tests/routes.crud-required-fields.spec.ts
index ba6639a9c..ff9c53720 100644
--- a/e2e/tests/routes.crud-required-fields.spec.ts
+++ b/e2e/tests/routes.crud-required-fields.spec.ts
@@ -18,7 +18,12 @@ import { routesPom } from '@e2e/pom/routes';
 import { randomId } from '@e2e/utils/common';
 import { e2eReq } from '@e2e/utils/req';
 import { test } from '@e2e/utils/test';
-import { uiHasToastMsg } from '@e2e/utils/ui';
+import {
+  uiClearMonacoEditor,
+  uiFillMonacoEditor,
+  uiGetMonacoEditor,
+  uiHasToastMsg,
+} from '@e2e/utils/ui';
 import { uiFillUpstreamRequiredFields } from '@e2e/utils/ui/upstreams';
 import { expect } from '@playwright/test';
 
@@ -99,6 +104,8 @@ test('should CRUD route with required fields', async ({ page 
}) => {
   });
 
   await test.step('edit and update route in detail page', async () => {
+    const varsSection = page.getByText('Vars').locator('..');
+
     // Click the Edit button in the detail page
     await page.getByRole('button', { name: 'Edit' }).click();
 
@@ -114,6 +121,11 @@ test('should CRUD route with required fields', async ({ 
page }) => {
     const uriField = page.getByLabel('URI', { exact: true });
     await uriField.fill(`${routeUri}-updated`);
 
+    // Vars is optional and should remain valid when user clears it
+    const varsEditor = await uiGetMonacoEditor(page, varsSection);
+    await uiFillMonacoEditor(page, varsEditor, '[["arg_name", "==", "tmp"]]');
+    await uiClearMonacoEditor(page);
+
     // Click the Save button to save changes
     const saveBtn = page.getByRole('button', { name: 'Save' });
     await saveBtn.click();
diff --git a/src/components/form/Editor.tsx b/src/components/form/Editor.tsx
index d236816ea..1139ca414 100644
--- a/src/components/form/Editor.tsx
+++ b/src/components/form/Editor.tsx
@@ -56,7 +56,8 @@ export const FormItemEditor = <T extends FieldValues>(
 ) => {
   const { t } = useTranslation();
   const { controllerProps, restProps } = genControllerProps(props, '');
-  const { customSchema, language, isLoading, ...wrapperProps } = restProps;
+  const { customSchema, language, isLoading, required, ...wrapperProps } =
+    restProps;
   const { trigger } = useFormContext();
   const monacoErrorRef = useRef<string | null>(null);
   const enhancedControllerProps = useMemo(() => {
@@ -65,6 +66,9 @@ export const FormItemEditor = <T extends FieldValues>(
       rules: {
         ...controllerProps.rules,
         validate: (value: string) => {
+          if (value.trim().length === 0 && !required) {
+            return true;
+          }
           // Check JSON syntax
           try {
             JSON.parse(value);
@@ -79,7 +83,7 @@ export const FormItemEditor = <T extends FieldValues>(
         },
       },
     };
-  }, [controllerProps, t, monacoErrorRef]);
+  }, [controllerProps, required, t, monacoErrorRef]);
 
   const {
     field: { value, onChange: fOnChange, ...restField },
@@ -113,6 +117,7 @@ export const FormItemEditor = <T extends FieldValues>(
     <InputWrapper
       error={fieldState.error?.message}
       id="#editor-wrapper"
+      required={required}
       {...wrapperProps}
     >
       <input name={restField.name} type="hidden" />

Reply via email to