Skip to content

Commit 99a4b2b

Browse files
committed
feat(FR-833): Improve metric label formatting in user session history page
1 parent 99a2905 commit 99a4b2b

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

react/src/components/SessionMetricGraph.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
convertBinarySizeUnit,
33
toFixedFloorWithoutTrailingZeros,
44
} from '../helper';
5+
import { useResourceSlotsDetails } from '../hooks/backendai';
56
import BAICard from './BAICard';
67
import {
78
SessionMetricGraphQuery,
@@ -68,6 +69,7 @@ const SessionMetricGraph: React.FC<PrometheusMetricGraphProps> = ({
6869
}) => {
6970
const { token } = theme.useToken();
7071
const { styles } = useStyle();
72+
const { mergedResourceSlots } = useResourceSlotsDetails();
7173

7274
const { capacity_metric, current_metric } =
7375
useLazyLoadQuery<SessionMetricGraphQuery>(
@@ -142,9 +144,22 @@ const SessionMetricGraph: React.FC<PrometheusMetricGraphProps> = ({
142144
dayDiff < 7 ? '5m' : dayDiff < 30 ? '1h' : '1d',
143145
);
144146

147+
const getMetricTitle = () => {
148+
const [key, ...rest] = _.split(metricName, '_');
149+
const restLabel = _.startCase(rest.join(' '));
150+
151+
if (_.has(mergedResourceSlots, key)) {
152+
return `${mergedResourceSlots[key]?.human_readable_name} ${restLabel}`;
153+
}
154+
if (_.includes(metricName, 'io')) {
155+
return `${_.upperCase(key)} ${restLabel}`;
156+
}
157+
return `${_.startCase(metricName.replaceAll('_', ' '))}`;
158+
};
159+
145160
return (
146161
<BAICard
147-
title={_.startCase(metricName.replaceAll('_', ' '))}
162+
title={getMetricTitle()}
148163
type="inner"
149164
styles={{
150165
body: {

react/src/pages/StatisticsPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React, { Suspense } from 'react';
88
import { useTranslation } from 'react-i18next';
99
import { StringParam, useQueryParam, withDefault } from 'use-query-params';
1010

11-
type TabKey = 'allocation-history' | 'prometheus-metrics';
11+
type TabKey = 'allocation-history' | 'user-session-history';
1212

1313
interface ResourcesPageProps {}
1414

@@ -26,14 +26,14 @@ const ResourcesPage: React.FC<ResourcesPageProps> = (props) => {
2626
return (
2727
<BAICard
2828
activeTabKey={curTabKey}
29-
onTabChange={(key) => setCurTabKey(key as TabKey)}
29+
onTabChange={(key) => setCurTabKey(key)}
3030
tabList={filterEmptyItem([
3131
{
3232
key: 'allocation-history',
3333
tab: t('webui.menu.UsageHistory'),
3434
},
3535
baiClient?.supports('user-metrics') && {
36-
key: 'prometheus-metrics',
36+
key: 'user-session-history',
3737
tab: t('webui.menu.UserSessionHistory'),
3838
},
3939
])}
@@ -57,7 +57,7 @@ const ResourcesPage: React.FC<ResourcesPageProps> = (props) => {
5757
<AllocationHistory />
5858
</Suspense>
5959
) : null}
60-
{curTabKey === 'prometheus-metrics' ? (
60+
{curTabKey === 'user-session-history' ? (
6161
<Suspense
6262
fallback={
6363
<Skeleton

0 commit comments

Comments
 (0)