Skip to content

Commit

Permalink
refactor: split user/admin menu for applying different style
Browse files Browse the repository at this point in the history
  • Loading branch information
lizable authored and agatha197 committed Aug 30, 2024
1 parent 49ce037 commit d9442f1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
32 changes: 8 additions & 24 deletions react/src/components/BAIMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,11 @@ import { ConfigProvider, Menu, MenuProps, theme } from 'antd';
import _ from 'lodash';
import React from 'react';

interface BAIMenuProps extends MenuProps {}

// workaround for style change in user / admin menu
const administratorMenu = [
'system_overview',
'credential',
'environment',
'resource-policy',
'agent',
'settings',
'maintenance',
'information',
];

interface BAIMenuProps extends MenuProps {
isAdminMenu?: boolean;
}
const BAIMenu: React.FC<BAIMenuProps> = ({ ...props }) => {
const { token } = theme.useToken();
const isAdminMenu = () => {
return _.some(props?.selectedKeys, (element) =>
_.includes(administratorMenu, element),
);
};
return (
<>
<style>
Expand All @@ -49,19 +33,19 @@ const BAIMenu: React.FC<BAIMenuProps> = ({ ...props }) => {
Menu: {
itemBorderRadius: 20,
itemMarginInline: 0,
colorPrimaryBorder: isAdminMenu()
colorPrimaryBorder: props.isAdminMenu
? token.colorSuccess
: token.colorInfoHover,
itemHoverBg: isAdminMenu()
itemHoverBg: props.isAdminMenu
? token.colorSuccessBgHover
: token.colorInfoHover,
itemHoverColor: isAdminMenu()
itemHoverColor: props.isAdminMenu
? token.colorSuccessHover
: token.colorPrimaryBg,
itemSelectedBg: isAdminMenu()
itemSelectedBg: props.isAdminMenu
? token.colorSuccessBgHover
: token.colorInfoHover,
itemSelectedColor: isAdminMenu()
itemSelectedColor: props.isAdminMenu
? token.colorSuccessHover
: token.colorPrimaryBg,
},
Expand Down
28 changes: 26 additions & 2 deletions react/src/components/MainLayout/WebUISider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,31 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
{...props}
>
<BAIMenu
isAdminMenu={false}
selectedKeys={[
location.pathname.split('/')[1] || 'start',
// TODO: After matching first path of 'storage-settings' and 'agent', remove this code
location.pathname.split('/')[1] === 'storage-settings' ? 'agent' : '',
// TODO: After 'SessionListPage' is completed and used as the main page, remove this code
// and change 'job' key to 'session'
location.pathname.split('/')[1] === 'session' ? 'job' : '',
]}
items={[...generalMenu]}
/**
* Etc menu
*/
// {
// label: '404',
// icon: <QuestionOutlined />,
// key: '404',
// },
// ]}
onClick={({ key, keyPath }) => {
webuiNavigate('/' + keyPath.join('/'));
}}
/>
<BAIMenu
isAdminMenu={true}
selectedKeys={[
location.pathname.split('/')[1] || 'summary',
// TODO: After matching first path of 'storage-settings' and 'agent', remove this code
Expand All @@ -394,7 +419,6 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
// TODO: add plugin menu
currentUserRole === 'superadmin'
? [
...generalMenu,
{
type: 'group',
label: (
Expand Down Expand Up @@ -430,7 +454,7 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
children: [...adminMenu],
},
]
: [...generalMenu]
: []
}
/**
* Etc menu
Expand Down

0 comments on commit d9442f1

Please sign in to comment.