-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
527 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
react/src/components/ComputeSessionNodeItems/SessionOccupiedSlot.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { convertBinarySizeUnit } from '../../helper'; | ||
import { useResourceSlotsDetails } from '../../hooks/backendai'; | ||
import { SessionOccupiedSlotFragment$key } from './__generated__/SessionOccupiedSlotFragment.graphql'; | ||
import { Divider, Typography } from 'antd'; | ||
import graphql from 'babel-plugin-relay/macro'; | ||
import _ from 'lodash'; | ||
import React from 'react'; | ||
import { useFragment } from 'react-relay'; | ||
|
||
interface OccupiedSlotViewProps { | ||
sessionFrgmt: SessionOccupiedSlotFragment$key; | ||
type: 'cpu' | 'mem' | 'accelerator'; | ||
} | ||
const SessionOccupiedSlot: React.FC<OccupiedSlotViewProps> = ({ | ||
type, | ||
sessionFrgmt, | ||
}) => { | ||
const { deviceMetadata } = useResourceSlotsDetails(); | ||
const session = useFragment( | ||
graphql` | ||
fragment SessionOccupiedSlotFragment on ComputeSessionNode { | ||
id | ||
occupied_slots | ||
} | ||
`, | ||
sessionFrgmt, | ||
); | ||
|
||
const occupiedSlots = JSON.parse(session.occupied_slots || '{}'); | ||
|
||
if (type === 'cpu') { | ||
return occupiedSlots.cpu ?? '-'; | ||
} else if (type === 'mem') { | ||
const mem = occupiedSlots.mem ?? '-'; | ||
return mem === '-' ? mem : convertBinarySizeUnit(mem, 'G')?.number + ' GiB'; | ||
} else if (type === 'accelerator') { | ||
const occupiedAccelerators = _.omit(occupiedSlots, ['cpu', 'mem']); | ||
return _.isEmpty(occupiedAccelerators) | ||
? '-' | ||
: _.map(occupiedAccelerators, (value, key) => { | ||
return ( | ||
<> | ||
<Typography.Text>{value}</Typography.Text> | ||
<Divider type="vertical" /> | ||
<Typography.Text> | ||
{deviceMetadata?.[key]?.human_readable_name} | ||
</Typography.Text> | ||
</> | ||
); | ||
}); | ||
} | ||
}; | ||
|
||
export default SessionOccupiedSlot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.