Skip to content

Commit de8b846

Browse files
committed
feat(FR-1575): merge admin dashboard into user dashboard (#4425)
Resolves #4424 ([FR-1575](https://lablup.atlassian.net/browse/FR-1575)) # Disable Admin Dashboard Menu Item and Enhance Dashboard Page for Superadmins This PR temporarily disables the Admin Dashboard menu item with a TODO comment to re-enable it when the page is ready. It also enhances the Dashboard page for superadmins by: 1. Renaming "My Sessions" to "Active Sessions" for superadmins 2. Adding Agent Stats component for superadmins when supported by the backend 3. Adding Active Agents component for superadmins These changes provide superadmins with a more comprehensive view of system activity directly from the dashboard. **Checklist:** - [ ] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after [FR-1575]: https://lablup.atlassian.net/browse/FR-1575?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 4f287da commit de8b846

File tree

2 files changed

+77
-11
lines changed

2 files changed

+77
-11
lines changed

react/src/components/MainLayout/WebUISider.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,19 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
260260
]);
261261

262262
const adminMenu: MenuProps['items'] = filterOutEmpty([
263+
// TODO: Enable the menu item when the page is ready.
263264
// WARN: Currently only superadmins can access AdminDashboardPage.
264265
// To place the Admin Dashboard menu item at the top of adminMenu,
265266
// add it to adminMenu instead of superAdminMenu:
266-
currentUserRole === 'superadmin' && {
267-
label: (
268-
<WebUILink to="/admin-dashboard">
269-
{t('webui.menu.AdminDashboard')}
270-
</WebUILink>
271-
),
272-
icon: <DashboardOutlined style={{ color: token.colorInfo }} />,
273-
key: 'admin-dashboard',
274-
},
267+
// currentUserRole === 'superadmin' && {
268+
// label: (
269+
// <WebUILink to="/admin-dashboard">
270+
// {t('webui.menu.AdminDashboard')}
271+
// </WebUILink>
272+
// ),
273+
// icon: <DashboardOutlined style={{ color: token.colorInfo }} />,
274+
// key: 'admin-dashboard',
275+
// },
275276
{
276277
label: <WebUILink to="/credential">{t('webui.menu.Users')}</WebUILink>,
277278
icon: <UserOutlined style={{ color: token.colorInfo }} />,

react/src/pages/DashboardPage.tsx

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import SessionCountDashboardItem from '../components/SessionCountDashboardItem';
77
import TotalResourceWithinResourceGroup, {
88
useIsAvailableTotalResourceWithinResourceGroup,
99
} from '../components/TotalResourceWithinResourceGroup';
10-
import { INITIAL_FETCH_KEY, useFetchKey } from '../hooks';
10+
import {
11+
INITIAL_FETCH_KEY,
12+
useFetchKey,
13+
useSuspendedBackendaiClient,
14+
} from '../hooks';
1115
import { useBAISettingUserState } from '../hooks/useBAISetting';
1216
import {
1317
useCurrentProjectValue,
@@ -20,6 +24,8 @@ import _ from 'lodash';
2024
import { Suspense, useTransition } from 'react';
2125
import { useTranslation } from 'react-i18next';
2226
import { graphql, useLazyLoadQuery } from 'react-relay';
27+
import ActiveAgents from 'src/components/ActiveAgents';
28+
import AgentStats from 'src/components/AgentStats';
2329
import { useCurrentUserRole } from 'src/hooks/backendai';
2430

2531
const DashboardPage: React.FC = () => {
@@ -29,6 +35,7 @@ const DashboardPage: React.FC = () => {
2935
const currentProject = useCurrentProjectValue();
3036
const currentResourceGroup = useCurrentResourceGroupValue();
3137
const userRole = useCurrentUserRole();
38+
const baiClient = useSuspendedBackendaiClient();
3239

3340
const [fetchKey, updateFetchKey] = useFetchKey();
3441
const [isPendingIntervalRefetch, startIntervalRefetchTransition] =
@@ -40,6 +47,8 @@ const DashboardPage: React.FC = () => {
4047
const isAvailableTotalResourcePanel =
4148
useIsAvailableTotalResourceWithinResourceGroup();
4249

50+
const isAgentStatsSupported = baiClient.supports('agent-stats');
51+
4352
const queryRef = useLazyLoadQuery<DashboardPageQuery>(
4453
graphql`
4554
query DashboardPageQuery(
@@ -59,6 +68,7 @@ const DashboardPage: React.FC = () => {
5968
isSuperAdmin: $isSuperAdmin
6069
agentNodeFilter: $agentNodeFilter
6170
)
71+
...AgentStatsFragment @include(if: $isSuperAdmin) @alias
6272
}
6373
`,
6474
{
@@ -98,9 +108,13 @@ const DashboardPage: React.FC = () => {
98108
}
99109
>
100110
<SessionCountDashboardItem
101-
title={t('session.MySessions')}
102111
queryRef={queryRef}
103112
isRefetching={isPendingIntervalRefetch}
113+
title={
114+
_.isEqual(userRole, 'superadmin')
115+
? t('session.ActiveSessions')
116+
: t('session.MySessions')
117+
}
104118
/>
105119
</Suspense>
106120
),
@@ -157,6 +171,57 @@ const DashboardPage: React.FC = () => {
157171
),
158172
},
159173
},
174+
_.isEqual(userRole, 'superadmin') &&
175+
isAgentStatsSupported &&
176+
queryRef.AgentStatsFragment && {
177+
id: 'agentStats',
178+
rowSpan: 2,
179+
columnSpan: 2,
180+
definition: {
181+
minRowSpan: 2,
182+
minColumnSpan: 2,
183+
},
184+
data: {
185+
content: (
186+
<Suspense
187+
fallback={
188+
<Skeleton
189+
active
190+
style={{ padding: `0px ${token.marginMD}px` }}
191+
/>
192+
}
193+
>
194+
<AgentStats
195+
queryRef={queryRef.AgentStatsFragment}
196+
isRefetching={isPendingIntervalRefetch}
197+
/>
198+
</Suspense>
199+
),
200+
},
201+
},
202+
_.isEqual(userRole, 'superadmin') && {
203+
id: 'activeAgents',
204+
rowSpan: 4,
205+
columnSpan: 4,
206+
definition: {
207+
minRowSpan: 3,
208+
minColumnSpan: 4,
209+
},
210+
data: {
211+
content: (
212+
<Suspense
213+
fallback={
214+
<Skeleton active style={{ padding: `0px ${token.marginMD}px` }} />
215+
}
216+
>
217+
<ActiveAgents
218+
fetchKey={fetchKey}
219+
onChangeFetchKey={() => updateFetchKey()}
220+
/>
221+
</Suspense>
222+
),
223+
},
224+
},
160225
{
161226
id: 'recentlyCreatedSession',
162227
rowSpan: 3,

0 commit comments

Comments
 (0)