Skip to content

Commit cac523e

Browse files
authored
feat(FR-1785): move Admin Settings to top menu and apply admin primary colors (#4816)
1 parent 44aad0f commit cac523e

3 files changed

Lines changed: 71 additions & 60 deletions

File tree

react/src/components/MainLayout/MainLayout.tsx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { DRAWER_WIDTH } from '../WEBUINotificationDrawer';
1515
import WebUIBreadcrumb from '../WebUIBreadcrumb';
1616
import WebUIHeader from './WebUIHeader';
1717
import WebUISider from './WebUISider';
18-
import { App, Layout, LayoutProps, theme } from 'antd';
18+
import { App, ConfigProvider, Layout, LayoutProps, theme } from 'antd';
1919
import { createStyles } from 'antd-style';
2020
import { BAIFlex } from 'backend.ai-ui';
2121
import { atom, useSetAtom } from 'jotai';
@@ -29,6 +29,8 @@ import {
2929
useState,
3030
} from 'react';
3131
import { useNavigate, Outlet, useMatches, useLocation } from 'react-router-dom';
32+
import usePrimaryColors from 'src/hooks/usePrimaryColors';
33+
import { useWebUIMenuItems } from 'src/hooks/useWebUIMenuItems';
3234
import { useSetupWebUIPluginEffect } from 'src/hooks/useWebUIPluginState';
3335

3436
export const HEADER_Z_INDEX_IN_MAIN_LAYOUT = 6;
@@ -211,7 +213,9 @@ function MainLayout() {
211213
align="stretch"
212214
className={styles.alertWrapper}
213215
>
214-
<ThemePreviewModeAlert />
216+
<ErrorBoundaryWithNullFallback>
217+
<ThemePreviewModeAlert />
218+
</ErrorBoundaryWithNullFallback>
215219
<ErrorBoundaryWithNullFallback>
216220
<NoResourceGroupAlert />
217221
</ErrorBoundaryWithNullFallback>
@@ -251,7 +255,9 @@ function MainLayout() {
251255
)}
252256
</ErrorBoundaryWithNullFallback>
253257
<BAIErrorBoundary>
254-
<Outlet />
258+
<AutoAdminPrimaryColorProvider>
259+
<Outlet />
260+
</AutoAdminPrimaryColorProvider>
255261
</BAIErrorBoundary>
256262
</Suspense>
257263
{/* @ts-ignore */}
@@ -264,6 +270,32 @@ function MainLayout() {
264270
);
265271
}
266272

273+
const AutoAdminPrimaryColorProvider = ({
274+
children,
275+
}: {
276+
children: React.ReactNode;
277+
}) => {
278+
'use memo';
279+
280+
const primaryColors = usePrimaryColors();
281+
const { isSelectedAdminCategoryMenu } = useWebUIMenuItems();
282+
if (isSelectedAdminCategoryMenu) {
283+
return (
284+
<ConfigProvider
285+
theme={{
286+
token: {
287+
colorPrimary: primaryColors.admin,
288+
},
289+
}}
290+
>
291+
{children}
292+
</ConfigProvider>
293+
);
294+
}
295+
296+
return children;
297+
};
298+
267299
const LayoutWithPageTestId: React.FC<LayoutProps> = (props) => {
268300
const location = useLocation();
269301
const pageTest = useMemo(() => {

react/src/components/MainLayout/WebUISider.tsx

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
4646
config.theme?.algorithm === theme.darkAlgorithm ? 'dark' : 'light';
4747

4848
const currentUserRole = useCurrentUserRole();
49+
const hasAdminCategoryRole =
50+
currentUserRole === 'superadmin' || currentUserRole === 'admin';
4951
const webuiNavigate = useWebUINavigate();
5052
const location = useLocation();
5153
const baiClient = useSuspendedBackendaiClient();
@@ -111,6 +113,7 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
111113
height: 40,
112114
width: 42,
113115
marginLeft: token.margin,
116+
marginBottom: 4,
114117
}}
115118
/>
116119
</Tooltip>
@@ -203,67 +206,44 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
203206
]}
204207
// @ts-ignore
205208
items={filterOutEmpty([
206-
...groupedGeneralMenu,
207-
(currentUserRole === 'superadmin' ||
208-
currentUserRole === 'admin') && {
209+
hasAdminCategoryRole && {
209210
// Go to first page of admin setting pages.
210-
type: 'group',
211211
label: (
212-
<BAIFlex
213-
style={{
214-
borderBottom: `1px solid ${token.colorBorder}`,
215-
}}
216-
>
217-
{!props.collapsed && (
218-
<Typography.Text type="secondary" ellipsis>
219-
{t('webui.menu.Administration')}
220-
</Typography.Text>
221-
)}
222-
</BAIFlex>
212+
<WebUILink to="/credential">
213+
{t('webui.menu.AdminSettings')}
214+
</WebUILink>
223215
),
224-
children: [
225-
{
226-
label: (
227-
<WebUILink
228-
to="/credential"
229-
state={{ goBack: location.pathname }}
230-
>
231-
{t('webui.menu.AdminSettings')}
232-
</WebUILink>
233-
),
234-
icon: <SettingsIcon style={{ color: token.colorInfo }} />,
235-
key: 'admin-settings',
236-
},
237-
],
216+
icon: <SettingsIcon style={{ color: token.colorInfo }} />,
217+
key: 'admin-settings',
238218
},
219+
...groupedGeneralMenu,
239220
])}
240221
/>
241222
)}
242-
{(currentUserRole === 'superadmin' || currentUserRole === 'admin') &&
243-
isSelectedAdminCategoryMenu && (
244-
<ConfigProvider
245-
theme={{
246-
token: {
247-
colorPrimary: primaryColors.admin,
248-
},
249-
}}
250-
>
251-
{adminHeader}
252-
<BAIMenu
253-
collapsed={props.collapsed}
254-
selectedKeys={[
255-
// TODO: After matching first path of 'storage-settings' and 'agent', remove this code
256-
location.pathname.split('/')[1] === 'storage-settings'
257-
? 'agent'
258-
: location.pathname.split('/')[1],
259-
]}
260-
items={[
261-
...adminMenu,
262-
...(currentUserRole === 'superadmin' ? superAdminMenu : []),
263-
]}
264-
/>
265-
</ConfigProvider>
266-
)}
223+
{hasAdminCategoryRole && isSelectedAdminCategoryMenu && (
224+
<ConfigProvider
225+
theme={{
226+
token: {
227+
colorPrimary: primaryColors.admin,
228+
},
229+
}}
230+
>
231+
{adminHeader}
232+
<BAIMenu
233+
collapsed={props.collapsed}
234+
selectedKeys={[
235+
// TODO: After matching first path of 'storage-settings' and 'agent', remove this code
236+
location.pathname.split('/')[1] === 'storage-settings'
237+
? 'agent'
238+
: location.pathname.split('/')[1],
239+
]}
240+
items={[
241+
...adminMenu,
242+
...(currentUserRole === 'superadmin' ? superAdminMenu : []),
243+
]}
244+
/>
245+
</ConfigProvider>
246+
)}
267247
</BAIFlex>
268248
{props.collapsed ? null : (
269249
<BAIFlex

react/src/hooks/useWebUIMenuItems.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,10 @@ export interface UseWebUIMenuItemsProps {
9393
hideGroupName?: boolean;
9494
}
9595

96-
export const useWebUIMenuItems = ({
97-
hideGroupName,
98-
}: UseWebUIMenuItemsProps) => {
96+
export const useWebUIMenuItems = (props?: UseWebUIMenuItemsProps) => {
9997
'use memo';
10098

99+
const { hideGroupName = false } = props || {};
101100
const plugins = useWebUIPluginValue();
102101

103102
const location = useLocation();

0 commit comments

Comments
 (0)