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 9bb33231 fix: preserve namespace page state on cancel (#688)
9bb33231 is described below
commit 9bb33231a2150bcd9e1313115ce999433ffed01b
Author: Carlos Acosta <[email protected]>
AuthorDate: Sun Sep 27 00:32:40 2026 -0500
fix: preserve namespace page state on cancel (#688)
Co-authored-by: Aeontra <aeontra@localhost>
---
src/routes/System/Namespace/deleteBehavior.test.js | 100 +++++++++++++++++++++
src/routes/System/Namespace/index.js | 14 ++-
2 files changed, 105 insertions(+), 9 deletions(-)
diff --git a/src/routes/System/Namespace/deleteBehavior.test.js
b/src/routes/System/Namespace/deleteBehavior.test.js
new file mode 100644
index 00000000..85f45eb5
--- /dev/null
+++ b/src/routes/System/Namespace/deleteBehavior.test.js
@@ -0,0 +1,100 @@
+/*
+ * 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 ConnectedNamespace from "./index";
+
+jest.mock("./AddModal", () => () => null);
+jest.mock(
+ "../../../utils/AuthButton",
+ () =>
+ ({ children }) =>
+ children,
+);
+jest.mock("../../../utils/IntlUtils", () => ({
+ getCurrentLocale: jest.fn(),
+ getIntlContent: (key) => key,
+}));
+jest.mock("../../../utils/AuthRoute", () => ({
+ refreshAuthMenus: jest.fn(),
+}));
+jest.mock("../../../components/_utils/utils", () => ({
+ defaultNamespaceId: "default",
+}));
+
+const Namespace = ConnectedNamespace.WrappedComponent;
+
+const makeComponent = (props = {}) => {
+ const component = new Namespace(props);
+ component.setState = (update, callback) => {
+ const next =
+ typeof update === "function"
+ ? update(component.state, component.props)
+ : update;
+ component.state = { ...component.state, ...next };
+ if (callback) callback();
+ };
+ return component;
+};
+
+it("closes a cancelled modal without changing the current page", () => {
+ const component = makeComponent({});
+ component.state = {
+ ...component.state,
+ popup: "modal",
+ currentPage: 4,
+ };
+
+ component.closeModal();
+
+ expect(component.state.popup).toBe("");
+ expect(component.state.currentPage).toBe(4);
+});
+
+it("deletes only the clicked namespace without mutating bulk selection", () =>
{
+ const dispatch = jest.fn();
+ const component = makeComponent({
+ dispatch,
+ currentNamespaceId: "active-namespace",
+ namespace: {
+ namespaceList: [
+ { id: "row-1", namespaceId: "active-namespace" },
+ { id: "bulk-1", namespaceId: "other-namespace" },
+ ],
+ },
+ });
+ component.state = {
+ ...component.state,
+ selectedRowKeys: ["bulk-1"],
+ currentPage: 2,
+ pageSize: 20,
+ };
+
+ component.deleteClick({ id: "row-1" });
+
+ expect(component.state.selectedRowKeys).toEqual(["bulk-1"]);
+ const action = dispatch.mock.calls[0][0];
+ expect(action.type).toBe("namespace/delete");
+ expect(action.payload.list).toEqual(["row-1"]);
+
+ action.callback();
+
+ expect(dispatch).toHaveBeenCalledWith({
+ type: "global/saveCurrentNamespaceId",
+ payload: "default",
+ });
+ expect(component.state.selectedRowKeys).toEqual([]);
+});
diff --git a/src/routes/System/Namespace/index.js
b/src/routes/System/Namespace/index.js
index c153daba..55a4fffd 100644
--- a/src/routes/System/Namespace/index.js
+++ b/src/routes/System/Namespace/index.js
@@ -115,7 +115,7 @@ export default class Namespace extends Component {
this.setState({ popup: "", currentPage: 1 }, this.query);
return;
}
- this.setState({ popup: "", currentPage: 1 });
+ this.setState({ popup: "" });
};
editClick = (record) => {
@@ -177,14 +177,12 @@ export default class Namespace extends Component {
namespace: { namespaceList },
} = this.props;
const { selectedRowKeys } = this.state;
- if (record) {
- selectedRowKeys.push(record.id);
- }
- if (selectedRowKeys && selectedRowKeys.length > 0) {
+ const deleteKeys = record ? [record.id] : selectedRowKeys;
+ if (deleteKeys && deleteKeys.length > 0) {
dispatch({
type: "namespace/delete",
payload: {
- list: selectedRowKeys,
+ list: deleteKeys,
},
fetchValue: this.currentQueryPayload({
pageSize: 12,
@@ -194,9 +192,7 @@ export default class Namespace extends Component {
refreshAuthMenus({ dispatch });
let deletedCurrentNamespace =
namespaceList.find((namespace) =>
- selectedRowKeys.some(
- (namespaceId) => namespaceId === namespace.id,
- ),
+ deleteKeys.some((namespaceId) => namespaceId === namespace.id),
)?.namespaceId === currentNamespaceId;
if (deletedCurrentNamespace) {
dispatch({