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 2a50d7ae fix: reset rule pagination on selector change (#690)
2a50d7ae is described below

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

    fix: reset rule pagination on selector change (#690)
    
    Co-authored-by: Aeontra <aeontra@localhost>
---
 src/routes/Plugin/Common/index.js                  |  5 +-
 .../Plugin/Common/selectorPagination.test.js       | 68 +++++++++++++++++++++
 src/routes/Plugin/McpServer/index.js               |  5 +-
 .../Plugin/McpServer/selectorPagination.test.js    | 71 ++++++++++++++++++++++
 4 files changed, 145 insertions(+), 4 deletions(-)

diff --git a/src/routes/Plugin/Common/index.js 
b/src/routes/Plugin/Common/index.js
index 9266f85d..0de3bf95 100755
--- a/src/routes/Plugin/Common/index.js
+++ b/src/routes/Plugin/Common/index.js
@@ -769,7 +769,8 @@ export default class Common extends Component {
   rowClick = (record) => {
     const { id } = record;
     const { dispatch, currentNamespaceId } = this.props;
-    const { selectorPageSize } = this.state;
+    const { rulePageSize } = this.state;
+    this.setState({ rulePage: 1 });
     dispatch({
       type: "common/saveCurrentSelector",
       payload: { currentSelector: record },
@@ -778,7 +779,7 @@ export default class Common extends Component {
       type: "common/fetchRule",
       payload: {
         currentPage: 1,
-        pageSize: selectorPageSize,
+        pageSize: rulePageSize,
         selectorId: id,
         namespaceId: currentNamespaceId,
       },
diff --git a/src/routes/Plugin/Common/selectorPagination.test.js 
b/src/routes/Plugin/Common/selectorPagination.test.js
new file mode 100644
index 00000000..fe1b20de
--- /dev/null
+++ b/src/routes/Plugin/Common/selectorPagination.test.js
@@ -0,0 +1,68 @@
+/*
+ * 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 ConnectedCommon from "./index";
+
+jest.mock("./Selector", () => () => null);
+jest.mock("./Rule", () => () => null);
+jest.mock("../AiProxy/ApiKeys", () => () => 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 Common = ConnectedCommon.WrappedComponent;
+
+it("resets rule pagination and uses rule page size when selecting a selector", 
() => {
+  const dispatch = jest.fn();
+  const component = new Common({
+    dispatch,
+    currentNamespaceId: "namespace-1",
+  });
+  component.state = {
+    ...component.state,
+    selectorPageSize: 12,
+    rulePage: 3,
+    rulePageSize: 20,
+  };
+  component.setState = (update) => {
+    component.state = { ...component.state, ...update };
+  };
+
+  component.rowClick({ id: "selector-1" });
+
+  expect(component.state.rulePage).toBe(1);
+  expect(dispatch).toHaveBeenNthCalledWith(2, {
+    type: "common/fetchRule",
+    payload: {
+      currentPage: 1,
+      pageSize: 20,
+      selectorId: "selector-1",
+      namespaceId: "namespace-1",
+    },
+  });
+});
diff --git a/src/routes/Plugin/McpServer/index.js 
b/src/routes/Plugin/McpServer/index.js
index 5725df25..444c5df8 100755
--- a/src/routes/Plugin/McpServer/index.js
+++ b/src/routes/Plugin/McpServer/index.js
@@ -775,7 +775,8 @@ export default class McpServer extends Component {
   rowClick = (record) => {
     const { id } = record;
     const { dispatch, currentNamespaceId } = this.props;
-    const { selectorPageSize } = this.state;
+    const { toolPageSize } = this.state;
+    this.setState({ toolPage: 1 });
     dispatch({
       type: "common/saveCurrentSelector",
       payload: {
@@ -786,7 +787,7 @@ export default class McpServer extends Component {
       type: "common/fetchRule",
       payload: {
         currentPage: 1,
-        pageSize: selectorPageSize,
+        pageSize: toolPageSize,
         selectorId: id,
         namespaceId: currentNamespaceId,
       },
diff --git a/src/routes/Plugin/McpServer/selectorPagination.test.js 
b/src/routes/Plugin/McpServer/selectorPagination.test.js
new file mode 100644
index 00000000..6b5789d3
--- /dev/null
+++ b/src/routes/Plugin/McpServer/selectorPagination.test.js
@@ -0,0 +1,71 @@
+/*
+ * 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 ConnectedMcpServer from "./index";
+
+jest.mock("react-json-view", () => () => null);
+jest.mock("../Common/Selector", () => () => null);
+jest.mock("./ToolsModal", () => () => null);
+jest.mock("./JsonEditModal", () => () => null);
+jest.mock("./McpConfigModal", () => () => null);
+jest.mock("./SwaggerImportModal", () => () => 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 McpServer = ConnectedMcpServer.WrappedComponent;
+
+it("resets tool pagination and uses tool page size when selecting a selector", 
() => {
+  const dispatch = jest.fn();
+  const component = new McpServer({
+    dispatch,
+    currentNamespaceId: "namespace-1",
+  });
+  component.state = {
+    ...component.state,
+    selectorPageSize: 12,
+    toolPage: 3,
+    toolPageSize: 20,
+  };
+  component.setState = (update) => {
+    component.state = { ...component.state, ...update };
+  };
+
+  component.rowClick({ id: "selector-1" });
+
+  expect(component.state.toolPage).toBe(1);
+  expect(dispatch).toHaveBeenNthCalledWith(2, {
+    type: "common/fetchRule",
+    payload: {
+      currentPage: 1,
+      pageSize: 20,
+      selectorId: "selector-1",
+      namespaceId: "namespace-1",
+    },
+  });
+});

Reply via email to