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

xiaoyu 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 ebbf239a fix namespace bugs (#507)
ebbf239a is described below

commit ebbf239a311ca15fb2d5fad2d70cffb3fcb7f22f
Author: aias00 <rok...@163.com>
AuthorDate: Mon Nov 25 14:33:33 2024 +0800

    fix namespace bugs (#507)
    
    * fix namespace bugs
    
    * change uri
---
 src/components/GlobalHeader/ExportModal.js |  3 +-
 src/components/GlobalHeader/ImportModal.js |  3 +-
 src/components/GlobalHeader/index.js       | 10 +++-
 src/models/global.js                       | 29 ++++++++----
 src/models/login.js                        |  8 +++-
 src/routes/Home/index.js                   | 16 ++++---
 src/services/api.js                        | 75 +++++++++++++++++++++---------
 7 files changed, 101 insertions(+), 43 deletions(-)

diff --git a/src/components/GlobalHeader/ExportModal.js 
b/src/components/GlobalHeader/ExportModal.js
index 802c3575..3d26ef52 100644
--- a/src/components/GlobalHeader/ExportModal.js
+++ b/src/components/GlobalHeader/ExportModal.js
@@ -24,7 +24,8 @@ import { defaultNamespaceId } from "../_utils/utils";
 const FormItem = Form.Item;
 
 const NamespaceSelector = forwardRef(
-  ({ onChange, currentNamespaceId, namespaces }) => {
+  // eslint-disable-next-line no-unused-vars
+  ({ onChange, currentNamespaceId, namespaces }, ref) => {
     const handleNamespaceChange = (value) => {
       onChange(value.key);
     };
diff --git a/src/components/GlobalHeader/ImportModal.js 
b/src/components/GlobalHeader/ImportModal.js
index 9f38da8a..15c5daab 100644
--- a/src/components/GlobalHeader/ImportModal.js
+++ b/src/components/GlobalHeader/ImportModal.js
@@ -48,7 +48,8 @@ const ChooseFile = forwardRef(({ onChange, file }, ref) => {
 });
 
 const NamespaceSelector = forwardRef(
-  ({ onChange, currentNamespaceId, namespaces }) => {
+  // eslint-disable-next-line no-unused-vars
+  ({ onChange, currentNamespaceId, namespaces }, ref) => {
     const handleNamespaceChange = (value) => {
       onChange(value.key);
     };
diff --git a/src/components/GlobalHeader/index.js 
b/src/components/GlobalHeader/index.js
index f5b219ed..2d4e0f22 100644
--- a/src/components/GlobalHeader/index.js
+++ b/src/components/GlobalHeader/index.js
@@ -161,7 +161,10 @@ class GlobalHeader extends PureComponent {
 
   handleNamespacesValueChange = (value) => {
     const { dispatch } = this.props;
-    const namespaceId = value?.key || defaultNamespaceId;
+    const namespaceId =
+      value?.key ||
+      window.sessionStorage.getItem("currentNamespaceId") ||
+      defaultNamespaceId;
     dispatch({
       type: "global/saveCurrentNamespaceId",
       payload: namespaceId,
@@ -169,6 +172,11 @@ class GlobalHeader extends PureComponent {
     if (namespaceId !== defaultNamespaceId) {
       
message.warn(getIntlContent("SHENYU.NAMESPACE.ALERTNAMESPACEID.CHANGED"));
     }
+    // Fetch plugins for the new namespace
+    dispatch({
+      type: "global/fetchPlugins",
+      payload: {},
+    });
     dispatch({
       type: "global/fetchPermission",
       payload: {
diff --git a/src/models/global.js b/src/models/global.js
index a43742a1..64ca7cb6 100644
--- a/src/models/global.js
+++ b/src/models/global.js
@@ -19,10 +19,10 @@ import { message } from "antd";
 import { routerRedux } from "dva/router";
 import {
   queryPlatform,
-  getAllPlugins,
+  getPluginsByNamespace,
   getNamespaceList,
   asyncByPluginAndNamespace,
-  getUserPermissionByToken,
+  getUserPermissionByNamespace,
 } from "../services/api";
 import { getIntlContent } from "../utils/IntlUtils";
 import { defaultNamespaceId } from "../components/_utils/utils";
@@ -38,7 +38,8 @@ export default {
     permissions: {},
     language: "",
     namespaces: [],
-    currentNamespaceId: defaultNamespaceId,
+    currentNamespaceId:
+      window.sessionStorage.getItem("currentNamespaceId") || 
defaultNamespaceId,
   },
 
   effects: {
@@ -60,13 +61,17 @@ export default {
         });
       }
     },
-    *fetchPlugins({ payload }, { call, put }) {
+    *fetchPlugins({ payload }, { call, put, select }) {
       const { callback } = payload ?? {};
+      const namespaceId = yield select(
+        ({ global }) => global.currentNamespaceId,
+      );
       const params = {
+        namespaceId,
         currentPage: 1,
         pageSize: 50,
       };
-      const json = yield call(getAllPlugins, params);
+      const json = yield call(getPluginsByNamespace, params);
       if (json.code === 200) {
         let { dataList } = json.data;
 
@@ -99,7 +104,7 @@ export default {
       );
       if (token && namespaceId) {
         const params = { token, namespaceId };
-        const json = yield call(getUserPermissionByToken, params);
+        const json = yield call(getUserPermissionByNamespace, params);
         if (json.code === 200) {
           let { menu, currentAuth } = json.data;
           permissions = { menu, button: currentAuth };
@@ -119,13 +124,16 @@ export default {
       });
       callback(permissions);
     },
-    *refreshPermission({ payload }, { call, put }) {
+    *refreshPermission({ payload }, { call, put, select }) {
       const { callback } = payload ?? {};
       let permissions = { menu: [], button: [] };
       const token = window.sessionStorage.getItem("token");
-      if (token) {
-        const params = { token };
-        const json = yield call(getUserPermissionByToken, params);
+      const namespaceId = yield select(
+        ({ global }) => global.currentNamespaceId,
+      );
+      if (token && namespaceId) {
+        const params = { token, namespaceId };
+        const json = yield call(getUserPermissionByNamespace, params);
         if (json.code === 200) {
           let { menu, currentAuth } = json.data;
           permissions = { menu, button: currentAuth };
@@ -176,6 +184,7 @@ export default {
       };
     },
     saveCurrentNamespaceId(state, { payload }) {
+      window.sessionStorage.setItem("currentNamespaceId", payload);
       return {
         ...state,
         currentNamespaceId: payload,
diff --git a/src/models/login.js b/src/models/login.js
index 49f1e4b6..e5e5b846 100644
--- a/src/models/login.js
+++ b/src/models/login.js
@@ -19,7 +19,7 @@ import { routerRedux } from "dva/router";
 // import { stringify } from "qs";
 import { message } from "antd";
 import { queryLogin } from "../services/api";
-// import { getPageQuery } from "../utils/utils";
+import { defaultNamespaceId } from "../components/_utils/utils";
 
 export default {
   namespace: "login",
@@ -52,6 +52,11 @@ export default {
             type: "global/fetchNamespaces",
           });
         }
+        // Reset namespace to default on login
+        yield put({
+          type: "global/saveCurrentNamespaceId",
+          payload: defaultNamespaceId,
+        });
         /* const urlParams = new URL(window.location.href);
          const params = getPageQuery();
          let { redirect } = params;
@@ -89,6 +94,7 @@ export default {
       window.sessionStorage.removeItem("token");
       window.sessionStorage.removeItem("userName");
       window.sessionStorage.removeItem("userId");
+      window.sessionStorage.removeItem("currentNamespaceId");
       yield put(
         routerRedux.push({
           pathname: "/user/login",
diff --git a/src/routes/Home/index.js b/src/routes/Home/index.js
index 3b284c91..c50f267b 100644
--- a/src/routes/Home/index.js
+++ b/src/routes/Home/index.js
@@ -36,7 +36,7 @@ import { routerRedux } from "dva/router";
 import styles from "./home.less";
 import { getIntlContent } from "../../utils/IntlUtils";
 import {
-  activePluginSnapshot,
+  activePluginSnapshotByNamespace,
   getNewEventRecodLogList,
 } from "../../services/api";
 
@@ -66,11 +66,15 @@ export default class Home extends Component {
         type: "global/fetchPlatform",
       });
     }
-    activePluginSnapshot().then((res) => {
-      if (res) {
-        this.setState({ activePluginSnapshot: res.data || [] });
-      }
-    });
+    const currentNamespaceId =
+      window.sessionStorage.getItem("currentNamespaceId");
+    activePluginSnapshotByNamespace({ namespaceId: currentNamespaceId }).then(
+      (res) => {
+        if (res) {
+          this.setState({ activePluginSnapshot: res.data || [] });
+        }
+      },
+    );
     getNewEventRecodLogList().then((res) => {
       if (res) {
         this.setState({ activeLog: res.data || [] });
diff --git a/src/services/api.js b/src/services/api.js
index 6de72a7f..17312bf0 100644
--- a/src/services/api.js
+++ b/src/services/api.js
@@ -189,7 +189,7 @@ export async function addPlugin(params) {
       formData.append("file", base64Data);
     }
   }
-  return request(`${baseUrl}/plugin`, {
+  return request(`${baseUrl}/plugin-template`, {
     method: `POST`,
     body: formData,
   });
@@ -197,7 +197,7 @@ export async function addPlugin(params) {
 
 /* generatePlugin */
 export async function generatePlugin({ pluginId, namespaceId }) {
-  return request(`${baseUrl}/namespacePlugin/${namespaceId}/${pluginId}`, {
+  return request(`${baseUrl}/namespace-plugin/${namespaceId}/${pluginId}`, {
     method: `PUT`,
   });
 }
@@ -221,7 +221,7 @@ function readFileAsBase64(file) {
 
 /* deletePlugin */
 export async function deletePlugin(params) {
-  return request(`${baseUrl}/plugin/batch`, {
+  return request(`${baseUrl}/plugin-template/batch`, {
     method: `DELETE`,
     body: [...params.list],
   });
@@ -244,7 +244,7 @@ export async function updatePlugin(params) {
       formData.append("file", base64Data);
     }
   }
-  return request(`${baseUrl}/plugin/${params.id}`, {
+  return request(`${baseUrl}/plugin-template/${params.id}`, {
     method: `PUT`,
     body: formData,
   });
@@ -252,28 +252,45 @@ export async function updatePlugin(params) {
 
 /* getAllPlugins */
 export async function getAllPlugins(params) {
-  return request(`${baseUrl}/plugin?${stringify(params)}`, {
+  return request(`${baseUrl}/plugin-template?${stringify(params)}`, {
+    method: `GET`,
+  });
+}
+
+/* getPluginsByNamespace */
+export async function getPluginsByNamespace(params) {
+  return request(`${baseUrl}/namespace-plugin?${stringify(params)}`, {
     method: `GET`,
   });
 }
 
 /* get Plugins snapshot */
 export function activePluginSnapshot() {
-  return request(`${baseUrl}/plugin/snapshot/active`, {
+  return request(`${baseUrl}/plugin-template/snapshot/active`, {
     method: `GET`,
   });
 }
 
+/* get Plugins snapshot By namespace */
+export function activePluginSnapshotByNamespace(params) {
+  return request(
+    
`${baseUrl}/namespace-plugin/snapshot/active?namespaceId=${params.namespaceId}`,
+    {
+      method: `GET`,
+    },
+  );
+}
+
 /* findPlugin */
 export async function findPlugin(params) {
-  return request(`${baseUrl}/plugin/${params.id}`, {
+  return request(`${baseUrl}/plugin-template/${params.id}`, {
     method: `GET`,
   });
 }
 
 /* updatepluginEnabled */
 export async function updatepluginEnabled(params) {
-  return request(`${baseUrl}/plugin/enabled`, {
+  return request(`${baseUrl}/plugin-template/enabled`, {
     method: `POST`,
     body: {
       ids: params.list,
@@ -569,7 +586,7 @@ export async function asyncConfigImport(params) {
 
 // sync on plugin
 export async function asyncOnePlugin(params) {
-  return request(`${baseUrl}/namespacePlugin/syncPluginData?id=${params.id}`, {
+  return request(`${baseUrl}/namespace-plugin/syncPluginData?id=${params.id}`, 
{
     method: `PUT`,
   });
 }
@@ -577,7 +594,7 @@ export async function asyncOnePlugin(params) {
 // sync by plugin and namespace
 export async function asyncByPluginAndNamespace(params) {
   return request(
-    
`${baseUrl}/namespacePlugin/syncPluginData?id=${params.id}&namespaceId=${params.namespaceId}`,
+    
`${baseUrl}/namespace-plugin/syncPluginData?id=${params.id}&namespaceId=${params.namespaceId}`,
     {
       method: `PUT`,
     },
@@ -586,7 +603,7 @@ export async function asyncByPluginAndNamespace(params) {
 
 // get plugin dropdown list
 export async function getPluginDropDownList() {
-  return request(`${baseUrl}/plugin/all`, {
+  return request(`${baseUrl}/plugin-template/all`, {
     method: `GET`,
   });
 }
@@ -594,7 +611,7 @@ export async function getPluginDropDownList() {
 // get plugin dropdown list by namespace
 export async function getPluginDropDownListByNamespace(params) {
   return request(
-    `${baseUrl}/plugin/listByNamespace?namespace=${params.namespace}`,
+    `${baseUrl}/plugin-template/listByNamespace?namespace=${params.namespace}`,
     {
       method: `GET`,
     },
@@ -654,10 +671,13 @@ export function fetchPluginHandleByPluginId(params) {
 
 // create plugin resource
 export function addPluginResource(params) {
-  return request(`${baseUrl}/plugin/createPluginResource/${params.id}`, {
-    method: `PUT`,
-    body: params,
-  });
+  return request(
+    `${baseUrl}/plugin-template/createPluginResource/${params.id}`,
+    {
+      method: `PUT`,
+      body: params,
+    },
+  );
 }
 
 // fetch dict list
@@ -845,6 +865,15 @@ export async function getUserPermissionByToken(params) {
   );
 }
 
+// get userPermission by namespace
+export async function getUserPermissionByNamespace(params) {
+  return request(
+    
`${baseUrl}/permission/getUserPermissionByNamespace?namespaceId=${params.namespaceId}`,
+    {
+      method: `GET`,
+    },
+  );
+}
 /* get dataPermision's selectors by page */
 export async function getDataPermisionSelectors(params) {
   return request(`${baseUrl}/data-permission/selector?${stringify(params)}`, {
@@ -1265,21 +1294,21 @@ export async function deleteNamespace(params) {
 
 /* findNamespacePlugin */
 export async function findNamespacePlugin(params) {
-  return request(`${baseUrl}/namespacePlugin/${params.id}`, {
+  return request(`${baseUrl}/namespace-plugin/${params.id}`, {
     method: `GET`,
   });
 }
 
 /* getAllNamespacePlugins */
 export async function getAllNamespacePlugins(params) {
-  return request(`${baseUrl}/namespacePlugin?${stringify(params)}`, {
+  return request(`${baseUrl}/namespace-plugin?${stringify(params)}`, {
     method: `GET`,
   });
 }
 
 /* updatepluginEnabled */
 export async function updateNamespacePluginEnabled(params) {
-  return request(`${baseUrl}/namespacePlugin/enabled`, {
+  return request(`${baseUrl}/namespace-plugin/enabled`, {
     method: `POST`,
     body: {
       ids: params.list,
@@ -1289,7 +1318,7 @@ export async function 
updateNamespacePluginEnabled(params) {
 }
 /* updateNamespacePluginEnabledByNamespace */
 export async function updateNamespacePluginEnabledByNamespace(params) {
-  return request(`${baseUrl}/namespacePlugin/enabledByNamespace`, {
+  return request(`${baseUrl}/namespace-plugin/enabledByNamespace`, {
     method: `POST`,
     body: {
       ids: params.list,
@@ -1301,7 +1330,7 @@ export async function 
updateNamespacePluginEnabledByNamespace(params) {
 
 /* updateNamespacePlugin */
 export async function updateNamespacePlugin(params) {
-  return request(`${baseUrl}/namespacePlugin/${params.id}`, {
+  return request(`${baseUrl}/namespace-plugin/${params.id}`, {
     method: `PUT`,
     body: params,
   });
@@ -1309,7 +1338,7 @@ export async function updateNamespacePlugin(params) {
 
 /* deletePlugin */
 export async function deleteNamespacePlugin(params) {
-  return request(`${baseUrl}/namespacePlugin/batch`, {
+  return request(`${baseUrl}/namespace-plugin/batch`, {
     method: `DELETE`,
     body: {
       ids: [...params.list],
@@ -1320,7 +1349,7 @@ export async function deleteNamespacePlugin(params) {
 
 // sync all plugin
 export async function asyncNamespacePlugin() {
-  return request(`${baseUrl}/namespacePlugin/syncPluginAll`, {
+  return request(`${baseUrl}/namespace-plugin/syncPluginAll`, {
     method: `POST`,
   });
 }

Reply via email to