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 a1154c01 fix: scope discovery import to active namespace (#685)
a1154c01 is described below
commit a1154c017ab2f1f087b415e14efa8c1c72bc66b6
Author: Carlos Acosta <[email protected]>
AuthorDate: Sun Sep 27 00:31:41 2026 -0500
fix: scope discovery import to active namespace (#685)
Co-authored-by: Aeontra <aeontra@localhost>
---
.../Plugin/Discovery/DiscoveryImportModal.js | 7 ++-
.../Plugin/Discovery/DiscoveryImportModal.test.js | 62 ++++++++++++++++++++++
2 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/src/routes/Plugin/Discovery/DiscoveryImportModal.js
b/src/routes/Plugin/Discovery/DiscoveryImportModal.js
index e48b5980..a4002e4d 100644
--- a/src/routes/Plugin/Discovery/DiscoveryImportModal.js
+++ b/src/routes/Plugin/Discovery/DiscoveryImportModal.js
@@ -20,9 +20,12 @@ import { Modal } from "antd";
import { connect } from "dva";
import { getIntlContent } from "../../../utils/IntlUtils";
-@connect(({ discovery }) => ({
+export const mapStateToProps = ({ discovery, global }) => ({
discovery,
-}))
+ currentNamespaceId: global.currentNamespaceId,
+});
+
+@connect(mapStateToProps)
class DiscoveryImportModal extends Component {
constructor(props) {
super(props);
diff --git a/src/routes/Plugin/Discovery/DiscoveryImportModal.test.js
b/src/routes/Plugin/Discovery/DiscoveryImportModal.test.js
new file mode 100644
index 00000000..05afae09
--- /dev/null
+++ b/src/routes/Plugin/Discovery/DiscoveryImportModal.test.js
@@ -0,0 +1,62 @@
+/*
+ * 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 ConnectedDiscoveryImportModal, {
+ mapStateToProps,
+} from "./DiscoveryImportModal";
+
+jest.mock("../../../utils/IntlUtils", () => ({
+ getIntlContent: (key) => key,
+}));
+
+const DiscoveryImportModal = ConnectedDiscoveryImportModal.WrappedComponent;
+
+it("maps the active namespace from global state", () => {
+ expect(
+ mapStateToProps({
+ discovery: { list: [] },
+ global: { currentNamespaceId: "namespace-1" },
+ }),
+ ).toEqual({
+ discovery: { list: [] },
+ currentNamespaceId: "namespace-1",
+ });
+});
+
+it("fetches discovery config in the active namespace", () => {
+ const dispatch = jest.fn();
+ const component = new DiscoveryImportModal({
+ dispatch,
+ pluginName: "divide",
+ currentNamespaceId: "namespace-1",
+ });
+ component.setState = jest.fn();
+
+ component.componentDidMount();
+
+ expect(dispatch).toHaveBeenCalledWith(
+ expect.objectContaining({
+ type: "discovery/fetchDiscovery",
+ payload: {
+ pluginName: "divide",
+ level: "1",
+ namespaceId: "namespace-1",
+ },
+ callback: expect.any(Function),
+ }),
+ );
+});