You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by le...@apache.org on 2022/08/12 08:36:59 UTC

[inlong] branch master updated: [INLONG-5523][Dashboard] Support menu permission control (#5524)

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

leezng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new cc8cbc71d [INLONG-5523][Dashboard] Support menu permission control (#5524)
cc8cbc71d is described below

commit cc8cbc71df30086098b7fcce90ab1bfa1122e548
Author: Daniel <le...@apache.org>
AuthorDate: Fri Aug 12 16:36:54 2022 +0800

    [INLONG-5523][Dashboard] Support menu permission control (#5524)
---
 inlong-dashboard/src/components/Layout/index.tsx | 11 +++++++++--
 inlong-dashboard/src/configs/menus/index.ts      |  6 ++----
 inlong-dashboard/src/i18n.ts                     |  2 --
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/inlong-dashboard/src/components/Layout/index.tsx b/inlong-dashboard/src/components/Layout/index.tsx
index 1be0ff1e0..735ee9288 100644
--- a/inlong-dashboard/src/components/Layout/index.tsx
+++ b/inlong-dashboard/src/components/Layout/index.tsx
@@ -20,7 +20,7 @@
 import { config } from '@/configs/default';
 import menus from '@/configs/menus';
 import defaultSettings from '@/defaultSettings';
-import { useLocation } from '@/hooks';
+import { useLocation, useSelector } from '@/hooks';
 import { isDevelopEnv } from '@/utils';
 import ProBasicLayout, {
   getMenuData,
@@ -31,6 +31,7 @@ import ProBasicLayout, {
 import React, { useCallback, useEffect, useMemo, useState } from 'react';
 import { Link } from 'react-router-dom';
 import type { MenuProps } from 'antd/es/menu';
+import { State } from '@/models';
 import NavWidget from './NavWidget';
 import './index.css';
 
@@ -47,7 +48,13 @@ const BasicLayout: React.FC = props => {
   const [selectedKeys, setSelectedKeys] = useState<string[]>(['/']);
   const isDev = isDevelopEnv();
   const { pathname } = location;
-  const { breadcrumbMap, menuData } = useMemo(() => getMenuData(menus), []); // TODO: Need refactor.
+  const roles = useSelector<State, State['roles']>(state => state.roles);
+  const { breadcrumbMap, menuData } = useMemo(() => {
+    const _menus = menus.filter(
+      item => (item.isAdmin && roles?.includes('ADMIN')) || !item.isAdmin,
+    );
+    return getMenuData(_menus);
+  }, [roles]);
 
   useEffect(() => {
     const firstPathname = `/${pathname.slice(1).split('/')?.[0]}`;
diff --git a/inlong-dashboard/src/configs/menus/index.ts b/inlong-dashboard/src/configs/menus/index.ts
index abbdcf9a8..162bbc435 100644
--- a/inlong-dashboard/src/configs/menus/index.ts
+++ b/inlong-dashboard/src/configs/menus/index.ts
@@ -23,6 +23,7 @@ export interface MenuItemType {
   name: string;
   children?: MenuItemType[];
   path?: string;
+  isAdmin?: boolean;
 }
 
 const menus: MenuItemType[] = [
@@ -51,12 +52,9 @@ const menus: MenuItemType[] = [
     path: '/process',
     name: i18n.t('configs.menus.ApprovalManagement'),
   },
-  // {
-  //   path: '/datasources',
-  //   name: i18n.t('configs.menus.Datasources'),
-  // },
   {
     name: i18n.t('configs.menus.SystemManagement'),
+    isAdmin: true,
     children: [
       {
         path: '/user',
diff --git a/inlong-dashboard/src/i18n.ts b/inlong-dashboard/src/i18n.ts
index 2e479af90..a06cb1972 100644
--- a/inlong-dashboard/src/i18n.ts
+++ b/inlong-dashboard/src/i18n.ts
@@ -68,9 +68,7 @@ i18n
     },
 
     react: {
-      wait: true,
       useSuspense: false,
-      bindI18n: 'languageChanged loaded',
     },
   });