Skip to content

Commit b548693

Browse files
committed
fix(FR-750): improve resource slot display in SessionSlotCell component (#3438)
Resolves #3437 (FR-750) # Enhance Resource Slot Display in Session Slot Cell This PR improves the display of resource slots in the SessionSlotCell component: 1. Replaces `deviceMetadata` with `mergedResourceSlots` from the `useResourceSlotsDetails` hook 2. Enhances memory display with fixed decimal precision (3 digits) 3. Filters out accelerators with zero or invalid values 4. Uses `display_unit` from resource slots data instead of `human_readable_name` 5. Modifies the `useResourceSlotsDetails` hook to: - Accept empty resource group name to fetch all resource slots - Handle URL parameter construction more robustly - Return an empty object instead of undefined when manager version is incompatible Before 1: New accelerator type and 0 accelerator type ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/XqC2uNFuj0wg8I60sMUh/de7e2885-84c3-4a95-92db-b4f48ef4f10f.png) After 1: New accelerator type and 0 accelerator type ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/XqC2uNFuj0wg8I60sMUh/79ab4346-73bd-471e-a7a0-8e3208665608.png) Before 2: ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/XqC2uNFuj0wg8I60sMUh/6dbce4d2-a2cf-439e-a834-4970375cebe5.png) After 2: ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/XqC2uNFuj0wg8I60sMUh/36cdf161-fb89-43d6-afbf-13586c97a745.png)
1 parent 116dc89 commit b548693

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

react/src/components/ComputeSessionNodeItems/SessionSlotCell.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const SessionSlotCell: React.FC<OccupiedSlotViewProps> = ({
1717
sessionFrgmt,
1818
mode = 'requested',
1919
}) => {
20-
const { deviceMetadata } = useResourceSlotsDetails();
20+
const { mergedResourceSlots } = useResourceSlotsDetails('');
2121
const session = useFragment(
2222
graphql`
2323
fragment SessionSlotCellFragment on ComputeSessionNode {
@@ -38,18 +38,25 @@ const SessionSlotCell: React.FC<OccupiedSlotViewProps> = ({
3838
return slots.cpu ?? '-';
3939
} else if (type === 'mem') {
4040
const mem = slots.mem ?? '-';
41-
return mem === '-' ? mem : convertBinarySizeUnit(mem, 'G')?.number + ' GiB';
41+
return mem === '-'
42+
? mem
43+
: convertBinarySizeUnit(mem, 'G', 3)?.numberFixed + ' GiB';
4244
} else if (type === 'accelerator') {
4345
const occupiedAccelerators = _.omit(slots, ['cpu', 'mem']);
44-
return _.isEmpty(occupiedAccelerators)
46+
47+
const filteredAccelerators = _.omitBy(
48+
occupiedAccelerators,
49+
(value) => _.toNumber(value) <= 0 || _.isNaN(_.toNumber(value)),
50+
);
51+
return _.every(filteredAccelerators, (value) => value === 0)
4552
? '-'
46-
: _.map(occupiedAccelerators, (value, key) => {
53+
: _.map(filteredAccelerators, (value, key) => {
4754
return (
4855
<Fragment key={key}>
4956
<Typography.Text>{value}</Typography.Text>
5057
<Divider type="vertical" />
5158
<Typography.Text>
52-
{deviceMetadata?.[key]?.human_readable_name}
59+
{mergedResourceSlots?.[key]?.display_unit}
5360
</Typography.Text>
5461
</Fragment>
5562
);

react/src/hooks/backendai.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,18 @@ export const useResourceSlotsDetails = (resourceGroupName?: string) => {
8686
}>({
8787
queryKey: ['useResourceSlots', resourceGroupName, key],
8888
queryFn: () => {
89-
// return baiClient.get_resource_slots();
90-
if (
91-
!resourceGroupName ||
92-
!baiClient.isManagerVersionCompatibleWith('23.09.0')
93-
) {
94-
return undefined;
89+
if (!baiClient.isManagerVersionCompatibleWith('23.09.0')) {
90+
return {};
9591
} else {
9692
// `/resource-slots/details` is available since 23.09
9793
// https://github.com/lablup/backend.ai/issues/1589
9894
const search = new URLSearchParams();
99-
search.set('sgroup', resourceGroupName);
95+
resourceGroupName && search.set('sgroup', resourceGroupName);
96+
const searchParamString = search.toString();
10097
return baiRequestWithPromise({
10198
method: 'GET',
102-
url: `/config/resource-slots/details?${search.toString()}`,
99+
// if `sgroup` is not provided, it will return all resource slots of all resource groups
100+
url: `/config/resource-slots/details${searchParamString ? '?' + search.toString() : ''}`,
103101
});
104102
}
105103
},

0 commit comments

Comments
 (0)