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 e176ccc4 fix: preserve namespace on discovery reloads (#686)
e176ccc4 is described below

commit e176ccc401dfdb264bffa1903fd198942f2e2acc
Author: Carlos Acosta <[email protected]>
AuthorDate: Sun Sep 27 00:30:42 2026 -0500

    fix: preserve namespace on discovery reloads (#686)
    
    Co-authored-by: Aeontra <aeontra@localhost>
---
 src/models/discovery.js                   |  4 +-
 src/models/discovery.test.js              | 55 +++++++++++++++++
 src/routes/Plugin/Discovery/index.js      |  4 +-
 src/routes/Plugin/Discovery/index.test.js | 99 +++++++++++++++++++++++++++++++
 4 files changed, 159 insertions(+), 3 deletions(-)

diff --git a/src/models/discovery.js b/src/models/discovery.js
index 81510c8d..307ce17c 100644
--- a/src/models/discovery.js
+++ b/src/models/discovery.js
@@ -114,8 +114,8 @@ export default {
 
     *reload(params, { put }) {
       const { fetchValue } = params;
-      const { name = "", currentPage, pageSize } = fetchValue;
-      const payload = { name, currentPage, pageSize };
+      const { name = "", currentPage, pageSize, namespaceId } = fetchValue;
+      const payload = { name, currentPage, pageSize, namespaceId };
       yield put({ type: "fetchProxySelectors", payload });
     },
 
diff --git a/src/models/discovery.test.js b/src/models/discovery.test.js
new file mode 100644
index 00000000..4d1ca0ae
--- /dev/null
+++ b/src/models/discovery.test.js
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+import model from "./discovery";
+
+jest.mock("../services/api", () => ({
+  addProxySelector: jest.fn(),
+  bindingSelector: jest.fn(),
+  deleteDiscovery: jest.fn(),
+  deleteProxySelector: jest.fn(),
+  fetchProxySelector: jest.fn(),
+  getDiscovery: jest.fn(),
+  getDiscoveryTypeEnums: jest.fn(),
+  postDiscoveryInsertOrUpdate: jest.fn(),
+  refreshProxySelector: jest.fn(),
+  updateDiscoveryUpstream: jest.fn(),
+  updateProxySelector: jest.fn(),
+}));
+jest.mock("../utils/IntlUtils", () => ({
+  getIntlContent: (key) => key,
+}));
+
+const put = (action) => ({ type: "put", action });
+
+it("preserves namespaceId when reloading proxy selectors", () => {
+  const fetchValue = {
+    name: "tcp-demo",
+    currentPage: 2,
+    pageSize: 20,
+    namespaceId: "namespace-1",
+  };
+  const generator = model.effects.reload({ fetchValue }, { put });
+
+  expect(generator.next().value).toEqual(
+    put({
+      type: "fetchProxySelectors",
+      payload: fetchValue,
+    }),
+  );
+  expect(generator.next().done).toBe(true);
+});
diff --git a/src/routes/Plugin/Discovery/index.js 
b/src/routes/Plugin/Discovery/index.js
index bfe514dd..3484a538 100644
--- a/src/routes/Plugin/Discovery/index.js
+++ b/src/routes/Plugin/Discovery/index.js
@@ -368,6 +368,7 @@ export default class DiscoveryProxy extends Component {
                   fetchValue: {
                     currentPage,
                     pageSize,
+                    namespaceId: currentNamespaceId,
                   },
                 });
               }}
@@ -489,7 +490,7 @@ export default class DiscoveryProxy extends Component {
   };
 
   handleDelete = (id) => {
-    const { currentPage, pageSize } = this.props;
+    const { currentPage, pageSize, currentNamespaceId } = this.props;
     this.props.dispatch({
       type: "discovery/delete",
       payload: {
@@ -498,6 +499,7 @@ export default class DiscoveryProxy extends Component {
       fetchValue: {
         currentPage,
         pageSize,
+        namespaceId: currentNamespaceId,
       },
     });
   };
diff --git a/src/routes/Plugin/Discovery/index.test.js 
b/src/routes/Plugin/Discovery/index.test.js
new file mode 100644
index 00000000..f1e82480
--- /dev/null
+++ b/src/routes/Plugin/Discovery/index.test.js
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+import ConnectedDiscoveryProxy from "./index";
+
+jest.mock("./ProxySelectorModal", () => () => null);
+jest.mock("./DiscoveryCard", () => () => null);
+jest.mock(
+  "../../../utils/AuthButton",
+  () =>
+    ({ children }) =>
+      children,
+);
+jest.mock("../../../utils/IntlUtils", () => ({
+  getCurrentLocale: jest.fn(),
+  getIntlContent: (key) => key,
+}));
+jest.mock("../../../utils/namespacePlugin", () => ({
+  getUpdateModal: jest.fn(),
+  updateNamespacePluginsEnabledByNamespace: jest.fn(),
+}));
+
+const DiscoveryProxy = ConnectedDiscoveryProxy.WrappedComponent;
+
+it("includes the active namespace when refreshing after delete", () => {
+  const dispatch = jest.fn();
+  const component = new DiscoveryProxy({
+    currentNamespaceId: "namespace-1",
+    currentPage: 3,
+    pageSize: 20,
+    dispatch,
+  });
+
+  component.handleDelete("selector-1");
+
+  expect(dispatch).toHaveBeenCalledWith({
+    type: "discovery/delete",
+    payload: {
+      list: ["selector-1"],
+    },
+    fetchValue: {
+      currentPage: 3,
+      pageSize: 20,
+      namespaceId: "namespace-1",
+    },
+  });
+});
+
+it("includes the active namespace when refreshing after add", () => {
+  const dispatch = jest.fn();
+  const component = new DiscoveryProxy({
+    currentNamespaceId: "namespace-1",
+    currentPage: 2,
+    pageSize: 12,
+    dispatch,
+    plugins: [{ name: "tcp", id: "plugin-1" }],
+    typeEnums: [],
+  });
+  component.setState = (update) => {
+    component.state = { ...component.state, ...update };
+  };
+
+  component.addSelector();
+
+  const fetchAction = dispatch.mock.calls[0][0];
+  fetchAction.callback(null);
+  component.state.popup.props.handleOk({
+    name: "selector",
+    forwardPort: 9000,
+    props: {},
+    listenerNode: "",
+    handler: {},
+    discoveryProps: "{}",
+    serverList: "",
+    selectedDiscoveryType: "local",
+    upstreams: [],
+  });
+
+  const addAction = dispatch.mock.calls[1][0];
+  expect(addAction.fetchValue).toEqual({
+    currentPage: 2,
+    pageSize: 12,
+    namespaceId: "namespace-1",
+  });
+});

Reply via email to