Skip to content

Commit

Permalink
fix namespace bugs (#507)
Browse files Browse the repository at this point in the history
* fix namespace bugs

* change uri
  • Loading branch information
Aias00 authored Nov 25, 2024
1 parent 475f794 commit ebbf239
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 43 deletions.
3 changes: 2 additions & 1 deletion src/components/GlobalHeader/ExportModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/GlobalHeader/ImportModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
10 changes: 9 additions & 1 deletion src/components/GlobalHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,22 @@ 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,
});
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: {
Expand Down
29 changes: 19 additions & 10 deletions src/models/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -38,7 +38,8 @@ export default {
permissions: {},
language: "",
namespaces: [],
currentNamespaceId: defaultNamespaceId,
currentNamespaceId:
window.sessionStorage.getItem("currentNamespaceId") || defaultNamespaceId,
},

effects: {
Expand All @@ -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;

Expand Down Expand Up @@ -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 };
Expand All @@ -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 };
Expand Down Expand Up @@ -176,6 +184,7 @@ export default {
};
},
saveCurrentNamespaceId(state, { payload }) {
window.sessionStorage.setItem("currentNamespaceId", payload);
return {
...state,
currentNamespaceId: payload,
Expand Down
8 changes: 7 additions & 1 deletion src/models/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 10 additions & 6 deletions src/routes/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 || [] });
Expand Down
Loading

0 comments on commit ebbf239

Please sign in to comment.