Skip to content

Commit 9de9e5a

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

1 file changed

Lines changed: 16 additions & 1 deletion

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: {

0 commit comments

Comments
 (0)