This is an automated email from the ASF dual-hosted git repository.
liuhongyu 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 6d29be41 [type:improve] Optimize namespace (#491)
6d29be41 is described below
commit 6d29be41e70c61c406c947de517fb39d86fc0dcf
Author: VampireAchao <[email protected]>
AuthorDate: Mon Nov 4 17:06:14 2024 +0800
[type:improve] Optimize namespace (#491)
---
src/components/GlobalHeader/index.js | 19 ++++----
src/components/_utils/utils.ts | 81 +++++++++++++++++----------------
src/models/global.js | 12 ++---
src/routes/System/Namespace/index.js | 8 ++--
src/routes/System/User/DataPermModal.js | 3 +-
src/services/api.js | 10 ----
6 files changed, 64 insertions(+), 69 deletions(-)
diff --git a/src/components/GlobalHeader/index.js
b/src/components/GlobalHeader/index.js
index d0046979..57c5b6cb 100644
--- a/src/components/GlobalHeader/index.js
+++ b/src/components/GlobalHeader/index.js
@@ -35,6 +35,7 @@ import { getCurrentLocale, getIntlContent } from
"../../utils/IntlUtils";
import { checkUserPassword } from "../../services/api";
import { emit } from "../../utils/emit";
import { resetAuthMenuCache } from "../../utils/AuthRoute";
+import { defaultNamespaceId } from "../_utils/utils";
const TranslationOutlinedSvg = () => (
<svg
@@ -159,23 +160,23 @@ class GlobalHeader extends PureComponent {
handleNamespacesValueChange = (value) => {
const { dispatch } = this.props;
- const namespaceId = value?.key || "649330b6-c2d7-4edc-be8e-8a54df9eb385";
- window.sessionStorage.setItem("currentNamespaceId", namespaceId);
+ const namespaceId = value?.key || defaultNamespaceId;
+ dispatch({
+ type: "global/saveCurrentNamespaceId",
+ payload: namespaceId,
+ });
+ if (namespaceId !== defaultNamespaceId) {
+
message.warn(getIntlContent("SHENYU.NAMESPACE.ALERTNAMESPACEID.CHANGED"));
+ }
dispatch({
type: "global/fetchPermission",
payload: {
+ namespaceId,
callback: () => {
resetAuthMenuCache();
},
},
});
- dispatch({
- type: "global/saveCurrentNamespaceId",
- payload: value.key,
- });
- if (value.key !== "649330b6-c2d7-4edc-be8e-8a54df9eb385") {
-
message.warn(getIntlContent("SHENYU.NAMESPACE.ALERTNAMESPACEID.CHANGED"));
- }
};
importConfigClick = () => {
diff --git a/src/components/_utils/utils.ts b/src/components/_utils/utils.ts
index a8ac69d3..65cd4cff 100644
--- a/src/components/_utils/utils.ts
+++ b/src/components/_utils/utils.ts
@@ -15,52 +15,55 @@
* limitations under the License.
*/
+// 默认 namespaceId
+export const defaultNamespaceId = "649330b6-c2d7-4edc-be8e-8a54df9eb385";
+
// 随机数字
export function randomNum(m: number, n: number) {
- return Math.floor(Math.random() * (n - m + 1) + m);
+ return Math.floor(Math.random() * (n - m + 1) + m);
}
// 随机颜色
export function randomColor() {
- return `rgb(${randomNum(0, 255)}, ${randomNum(0, 255)}, ${randomNum(
- 0,
- 255
- )})`;
+ return `rgb(${randomNum(0, 255)}, ${randomNum(0, 255)}, ${randomNum(
+ 0,
+ 255,
+ )})`;
}
export const originalCharacter = [
- "1",
- "2",
- "3",
- "4",
- "5",
- "6",
- "7",
- "8",
- "9",
- "a",
- "b",
- "c",
- "d",
- "e",
- "f",
- "g",
- "h",
- "i",
- "j",
- "k",
- "l",
- "m",
- "n",
- "p",
- "q",
- "r",
- "s",
- "t",
- "u",
- "v",
- "w",
- "x",
- "y",
- "z"
+ "1",
+ "2",
+ "3",
+ "4",
+ "5",
+ "6",
+ "7",
+ "8",
+ "9",
+ "a",
+ "b",
+ "c",
+ "d",
+ "e",
+ "f",
+ "g",
+ "h",
+ "i",
+ "j",
+ "k",
+ "l",
+ "m",
+ "n",
+ "p",
+ "q",
+ "r",
+ "s",
+ "t",
+ "u",
+ "v",
+ "w",
+ "x",
+ "y",
+ "z",
];
diff --git a/src/models/global.js b/src/models/global.js
index 64874d56..7ea50eb4 100644
--- a/src/models/global.js
+++ b/src/models/global.js
@@ -25,6 +25,7 @@ import {
getUserPermissionByToken,
} from "../services/api";
import { getIntlContent } from "../utils/IntlUtils";
+import { defaultNamespaceId } from "../components/_utils/utils";
export default {
namespace: "global",
@@ -37,7 +38,7 @@ export default {
permissions: {},
language: "",
namespaces: [],
- currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
+ currentNamespaceId: defaultNamespaceId,
},
effects: {
@@ -57,9 +58,6 @@ export default {
type: "saveNamespaces",
payload: json.data,
});
- const namespaceId =
- json.data[0]?.namespaceId || "649330b6-c2d7-4edc-be8e-8a54df9eb385";
- window.sessionStorage.setItem("currentNamespaceId", namespaceId);
}
},
*fetchPlugins({ payload }, { call, put }) {
@@ -92,11 +90,13 @@ export default {
message.warn(json.message);
}
},
- *fetchPermission({ payload }, { call, put }) {
+ *fetchPermission({ payload }, { call, put, select }) {
const { callback } = payload;
let permissions = { menu: [], button: [] };
const token = window.sessionStorage.getItem("token");
- const namespaceId = window.sessionStorage.getItem("currentNamespaceId");
+ const namespaceId = yield select(
+ ({ global }) => global.currentNamespaceId,
+ );
if (namespaceId) {
const params = { token, namespaceId };
const json = yield call(getUserPermissionByToken, params);
diff --git a/src/routes/System/Namespace/index.js
b/src/routes/System/Namespace/index.js
index 90973bf8..3ffc8af8 100644
--- a/src/routes/System/Namespace/index.js
+++ b/src/routes/System/Namespace/index.js
@@ -23,6 +23,7 @@ import AddModal from "./AddModal";
import { getCurrentLocale, getIntlContent } from "../../../utils/IntlUtils";
import AuthButton from "../../../utils/AuthButton";
import { refreshAuthMenus } from "../../../utils/AuthRoute";
+import { defaultNamespaceId } from "../../../components/_utils/utils";
@connect(({ namespace, resource, loading, global }) => ({
namespace,
@@ -201,7 +202,7 @@ export default class Namespace extends Component {
if (deletedCurrentNamespace) {
dispatch({
type: "global/saveCurrentNamespaceId",
- payload: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
+ payload: defaultNamespaceId,
});
}
dispatch({ type: "global/fetchNamespaces" });
@@ -294,8 +295,7 @@ export default class Namespace extends Component {
width: 160,
fixed: "right",
render: (text, record) => {
- return record.namespaceId ===
- "649330b6-c2d7-4edc-be8e-8a54df9eb385" ? (
+ return record.namespaceId === defaultNamespaceId ? (
""
) : (
<div className="optionParts">
@@ -357,7 +357,7 @@ export default class Namespace extends Component {
selectedRowKeys,
onChange: this.onSelectChange,
getCheckboxProps: (record) => ({
- disabled: record.namespaceId ===
"649330b6-c2d7-4edc-be8e-8a54df9eb385",
+ disabled: record.namespaceId === defaultNamespaceId,
}),
};
const flatList = (map, list) => {
diff --git a/src/routes/System/User/DataPermModal.js
b/src/routes/System/User/DataPermModal.js
index b03b6fbb..827da468 100644
--- a/src/routes/System/User/DataPermModal.js
+++ b/src/routes/System/User/DataPermModal.js
@@ -33,6 +33,7 @@ import {
import { connect } from "dva";
import { getIntlContent } from "../../../utils/IntlUtils";
import { titleCase } from "../../../utils/utils";
+import { defaultNamespaceId } from "../../../components/_utils/utils";
const { TreeNode } = Tree;
const { Search } = Input;
@@ -57,7 +58,7 @@ export default class DataPermModal extends Component {
pageSize: 12,
ruleListMap: {},
searchValue: "",
- currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
+ currentNamespaceId: defaultNamespaceId,
selectorExpandedRowKeys: [],
};
}
diff --git a/src/services/api.js b/src/services/api.js
index b3723708..bc01a06d 100644
--- a/src/services/api.js
+++ b/src/services/api.js
@@ -814,16 +814,6 @@ export async function getUserPermissionByToken(params) {
);
}
-// get userPermission
-export async function getUserPermission(params) {
- return request(
-
`${baseUrl}/permission/getUserPermissionByToken?namespaceId=${params.namespaceId}`,
- {
- method: `GET`,
- },
- );
-}
-
/* get dataPermision's selectors by page */
export async function getDataPermisionSelectors(params) {
return request(`${baseUrl}/data-permission/selector?${stringify(params)}`, {