Skip to content

Commit 5f7377b

Browse files
authored
Add slot column to sleds tab on inventory page (#3416)
This PR adds a slot number to the Sleds tab on the Inventory page. It also sorts the sled rows based on the slot number, as the standard API response order is just ID, which doesn't have any inherent meaning.
1 parent 0f508ce commit 5f7377b

4 files changed

Lines changed: 61 additions & 10 deletions

File tree

‎app/pages/system/inventory/SledsTab.tsx‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,42 @@
55
*
66
* Copyright Oxide Computer Company
77
*/
8-
import { createColumnHelper } from '@tanstack/react-table'
8+
import { createColumnHelper, getCoreRowModel, useReactTable } from '@tanstack/react-table'
9+
import { useMemo } from 'react'
10+
import * as R from 'remeda'
911

10-
import { api, getListQFn, queryClient, type Sled } from '@oxide/api'
12+
import { api, q, queryClient, usePrefetchedQuery, type Sled } from '@oxide/api'
1113
import { Servers24Icon } from '@oxide/design-system/icons/react'
1214

15+
import { EmptyCell } from '~/table/cells/EmptyCell'
1316
import { LinkCell } from '~/table/cells/LinkCell'
14-
import { useQueryTable } from '~/table/QueryTable'
17+
import { Table } from '~/table/Table'
1518
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
19+
import { TableEmptyBox } from '~/ui/lib/Table'
1620
import { Truncate } from '~/ui/lib/Truncate'
21+
import { ALL_ISH } from '~/util/consts'
1722
import { pb } from '~/util/path-builder'
1823

1924
import { ProvisionPolicyBadge, SledKindBadge, SledStateBadge } from './sled/SledBadges'
2025

21-
const sledList = getListQFn(api.sledList, {})
26+
const sledList = q(api.sledList, { query: { limit: ALL_ISH } })
2227

2328
export async function clientLoader() {
24-
await queryClient.fetchQuery(sledList.optionsFn())
29+
await queryClient.fetchQuery(sledList)
2530
return null
2631
}
2732

2833
export const handle = { crumb: 'Sleds' }
2934

3035
const colHelper = createColumnHelper<Sled>()
3136
const staticCols = [
37+
colHelper.accessor('slot', {
38+
cell: (info) => (
39+
<div className="w-[2.5ch] text-right tabular-nums">
40+
{info.getValue() ?? <EmptyCell />}
41+
</div>
42+
),
43+
}),
3244
colHelper.accessor('id', {
3345
cell: (info) => (
3446
<LinkCell to={pb.sledInstances({ sledId: info.getValue() })}>
@@ -51,10 +63,12 @@ const staticCols = [
5163
header: 'Policy',
5264
columns: [
5365
colHelper.accessor('policy', {
66+
id: 'policyKind',
5467
header: 'Kind',
5568
cell: (info) => <SledKindBadge policy={info.getValue()} />,
5669
}),
5770
colHelper.accessor('policy', {
71+
id: 'provisionPolicy',
5872
header: 'Provision policy',
5973
cell: (info) => <ProvisionPolicyBadge policy={info.getValue()} />,
6074
}),
@@ -66,7 +80,28 @@ const staticCols = [
6680
]
6781

6882
export default function SledsTab() {
69-
const emptyState = <EmptyMessage icon={<Servers24Icon />} title="No sleds found" />
70-
const { table } = useQueryTable({ query: sledList, columns: staticCols, emptyState })
71-
return table
83+
const { data } = usePrefetchedQuery(sledList)
84+
const sleds = useMemo(
85+
() =>
86+
R.sortBy(
87+
data.items,
88+
(sled) => sled.slot == null,
89+
(sled) => sled.slot ?? 0
90+
),
91+
[data]
92+
)
93+
const table = useReactTable({
94+
columns: staticCols,
95+
data: sleds,
96+
getRowId: (sled) => sled.id,
97+
getCoreRowModel: getCoreRowModel(),
98+
})
99+
if (sleds.length === 0) {
100+
return (
101+
<TableEmptyBox>
102+
<EmptyMessage icon={<Servers24Icon />} title="No sleds found" />
103+
</TableEmptyBox>
104+
)
105+
}
106+
return <Table table={table} />
72107
}

‎app/pages/system/inventory/sled/SledPage.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Servers24Icon } from '@oxide/design-system/icons/react'
1212
import { RouteTabs, Tab } from '~/components/RouteTabs'
1313
import { makeCrumb } from '~/hooks/use-crumbs'
1414
import { useSledParams } from '~/hooks/use-params'
15+
import { EmptyCell } from '~/table/cells/EmptyCell'
1516
import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
1617
import { PropertiesTable } from '~/ui/lib/PropertiesTable'
1718
import { truncate } from '~/ui/lib/Truncate'
@@ -71,6 +72,10 @@ export default function SledPage() {
7172
label="usable physical ram"
7273
bytes={sled.usablePhysicalRam}
7374
/>
75+
<PropertiesTable.Row label="slot">
76+
<span className="text-default">{sled.slot ?? <EmptyCell />}</span>
77+
</PropertiesTable.Row>
78+
<PropertiesTable.DateRow label="Created" date={sled.timeCreated} />
7479
</PropertiesTable>
7580

7681
<RouteTabs fullWidth>

‎mock-api/sled.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const sleds: Json<Sled[]> = [
2525
serial: 'BRM02222869',
2626
revision: 0,
2727
},
28+
slot: 0,
2829
usable_hardware_threads: 254,
2930
usable_physical_ram: 1_099_511_627_776,
3031
},
@@ -43,6 +44,7 @@ export const sleds: Json<Sled[]> = [
4344
serial: 'BRM02222870',
4445
revision: 0,
4546
},
47+
slot: 15,
4648
usable_hardware_threads: 254,
4749
usable_physical_ram: 1_099_511_627_776,
4850
},
@@ -60,6 +62,7 @@ export const sleds: Json<Sled[]> = [
6062
serial: 'BRM02222868',
6163
revision: 0,
6264
},
65+
slot: 2,
6366
usable_hardware_threads: 254,
6467
usable_physical_ram: 1_099_511_627_776,
6568
},
@@ -77,6 +80,7 @@ export const sleds: Json<Sled[]> = [
7780
serial: 'BRM02222867',
7881
revision: 0,
7982
},
83+
slot: null,
8084
usable_hardware_threads: 254,
8185
usable_physical_ram: 1_099_511_627_776,
8286
},

‎test/e2e/inventory.e2e.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test('Sled inventory page', async ({ page }) => {
2424
// grouping, hence the slightly weird column names
2525
await expectRowVisible(sledsTable, {
2626
id: expect.stringContaining(sleds[0].id),
27+
slot: '0',
2728
'serial number': sleds[0].baseboard.serial,
2829
Kind: 'In service',
2930
'Provision policy': 'Provisionable',
@@ -45,17 +46,23 @@ test('Sled inventory page', async ({ page }) => {
4546
})
4647
await expectRowVisible(sledsTable, {
4748
id: expect.stringContaining(sleds[3].id),
49+
slot: '—',
4850
'serial number': sleds[3].baseboard.serial,
4951
Kind: 'Expunged',
5052
'Provision policy': '—',
5153
state: 'decommissioned',
5254
})
5355

54-
// Visit the sled detail page of the first sled
55-
await sledsTable.getByRole('link').first().click()
56+
// rows are in slot order, with the sled without a slot last
57+
const slotCells = sledsTable.locator('tbody tr td:first-child')
58+
await expect(slotCells).toHaveText(['0', '2', '15', '—'])
59+
60+
// Visit the sled detail page of the slot 0 sled
61+
await sledsTable.getByRole('link', { name: sleds[0].id }).click()
5662

5763
await expectVisible(page, ['role=heading[name*="Sled"]'])
5864
await expect(page.getByText('serialBRM02222869')).toBeVisible()
65+
await expect(page.getByText('slot0')).toBeVisible()
5966

6067
const instancesTab = page.getByRole('tab', { name: 'Instances' })
6168
await expect(instancesTab).toBeVisible()

0 commit comments

Comments
 (0)