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

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


The following commit(s) were added to refs/heads/master by this push:
     new a63b5e81 fix: preserve springCloud selector handle fields (#693)
a63b5e81 is described below

commit a63b5e81457b6a5c785221d5ae695688b7c7bb1f
Author: Efe <[email protected]>
AuthorDate: Mon Sep 28 06:34:07 2026 +0300

    fix: preserve springCloud selector handle fields (#693)
    
    Signed-off-by: Efe Gökdemir <[email protected]>
---
 src/routes/Plugin/Common/Selector.js       | 32 ++-------------------
 src/routes/Plugin/Common/Selector.test.js  | 29 +++++++++++++++++++
 src/routes/Plugin/Common/selectorHandle.js | 46 ++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 30 deletions(-)

diff --git a/src/routes/Plugin/Common/Selector.js 
b/src/routes/Plugin/Common/Selector.js
index c9bbd5c9..9e13b422 100644
--- a/src/routes/Plugin/Common/Selector.js
+++ b/src/routes/Plugin/Common/Selector.js
@@ -50,6 +50,7 @@ import {
 } from "../../../utils/utils";
 import DiscoveryImportModal from "../Discovery/DiscoveryImportModal";
 import EditableFormTable from "../Discovery/DiscoveryUpstreamTable.js";
+import { buildHandle } from "./selectorHandle";
 
 const { Item } = Form;
 const { TabPane } = Tabs;
@@ -264,7 +265,6 @@ class AddModal extends Component {
       upstreams,
       importedDiscoveryId,
     } = this.state;
-    let handle = [];
 
     form.validateFieldsAndScroll((err, values) => {
       if (!err) {
@@ -308,35 +308,7 @@ class AddModal extends Component {
               importedDiscoveryId,
             });
           } else {
-            pluginHandleList.forEach((handleList, index) => {
-              handle[index] = {};
-              handleList.forEach((item) => {
-                if (isDivideUpstreamsRequiresForPlugin(pluginId)) {
-                  const { keys, divideUpstreams } = values;
-                  const data = {
-                    [item.field]: values[item.field],
-                    gray: values.gray,
-                  };
-
-                  if (
-                    Array.isArray(divideUpstreams) &&
-                    divideUpstreams.length
-                  ) {
-                    data.divideUpstreams = keys.map(
-                      (key) => divideUpstreams[key],
-                    );
-                  }
-                  handle[index] = data;
-                  delete values[item.field];
-                  delete values.divideUpstreams;
-                  delete values.gray;
-                  delete values.key;
-                } else {
-                  handle[index][item.field] = values[item.field + index];
-                  delete values[item.field + index];
-                }
-              });
-            });
+            const handle = buildHandle(pluginHandleList, values, pluginId);
             handleOk({
               ...values,
               handle: multiSelectorHandle
diff --git a/src/routes/Plugin/Common/Selector.test.js 
b/src/routes/Plugin/Common/Selector.test.js
new file mode 100644
index 00000000..e441267a
--- /dev/null
+++ b/src/routes/Plugin/Common/Selector.test.js
@@ -0,0 +1,29 @@
+import { buildHandle } from "./selectorHandle";
+
+describe("buildHandle", () => {
+  it("preserves every springCloud handle field", () => {
+    const values = {
+      serviceId: "orders",
+      protocol: "http",
+      keys: [0],
+      divideUpstreams: [{ upstreamUrl: "http://orders"; }],
+      gray: true,
+    };
+
+    expect(
+      buildHandle(
+        [[{ field: "serviceId" }, { field: "protocol" }]],
+        values,
+        "8",
+      ),
+    ).toEqual([
+      {
+        serviceId: "orders",
+        protocol: "http",
+        divideUpstreams: [{ upstreamUrl: "http://orders"; }],
+        gray: true,
+      },
+    ]);
+    expect(values).not.toHaveProperty("keys");
+  });
+});
diff --git a/src/routes/Plugin/Common/selectorHandle.js 
b/src/routes/Plugin/Common/selectorHandle.js
new file mode 100644
index 00000000..a364cfab
--- /dev/null
+++ b/src/routes/Plugin/Common/selectorHandle.js
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+const isDivideUpstreamsRequiresForPlugin = (pluginId) =>
+  ["8"].includes(pluginId);
+
+export const buildHandle = (pluginHandleList, values, pluginId) => {
+  const handle = [];
+  pluginHandleList.forEach((handleList, index) => {
+    handle[index] = {};
+    const { keys, divideUpstreams, gray } = values;
+    handleList.forEach((item) => {
+      if (isDivideUpstreamsRequiresForPlugin(pluginId)) {
+        if (Array.isArray(divideUpstreams) && divideUpstreams.length) {
+          handle[index].divideUpstreams = keys.map(
+            (key) => divideUpstreams[key],
+          );
+        }
+        handle[index][item.field] = values[item.field];
+        handle[index].gray = gray;
+        delete values[item.field];
+        delete values.divideUpstreams;
+        delete values.gray;
+        delete values.keys;
+      } else {
+        handle[index][item.field] = values[item.field + index];
+        delete values[item.field + index];
+      }
+    });
+  });
+  return handle;
+};

Reply via email to