Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions app/pages/system/inventory/SledsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,42 @@
*
* Copyright Oxide Computer Company
*/
import { createColumnHelper } from '@tanstack/react-table'
import { createColumnHelper, getCoreRowModel, useReactTable } from '@tanstack/react-table'
import { useMemo } from 'react'
import * as R from 'remeda'

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

import { EmptyCell } from '~/table/cells/EmptyCell'
import { LinkCell } from '~/table/cells/LinkCell'
import { useQueryTable } from '~/table/QueryTable'
import { Table } from '~/table/Table'
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
import { TableEmptyBox } from '~/ui/lib/Table'
import { Truncate } from '~/ui/lib/Truncate'
import { ALL_ISH } from '~/util/consts'
import { pb } from '~/util/path-builder'

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

const sledList = getListQFn(api.sledList, {})
const sledList = q(api.sledList, { query: { limit: ALL_ISH } })

export async function clientLoader() {
await queryClient.fetchQuery(sledList.optionsFn())
await queryClient.fetchQuery(sledList)
return null
}

export const handle = { crumb: 'Sleds' }

const colHelper = createColumnHelper<Sled>()
const staticCols = [
colHelper.accessor('slot', {
cell: (info) => (
<div className="w-[2.5ch] text-right tabular-nums">
{info.getValue() ?? <EmptyCell />}
</div>
),
}),
colHelper.accessor('id', {
cell: (info) => (
<LinkCell to={pb.sledInstances({ sledId: info.getValue() })}>
Expand All @@ -51,10 +63,12 @@ const staticCols = [
header: 'Policy',
columns: [
colHelper.accessor('policy', {
id: 'policyKind',
header: 'Kind',
cell: (info) => <SledKindBadge policy={info.getValue()} />,
}),
colHelper.accessor('policy', {
id: 'provisionPolicy',
header: 'Provision policy',
cell: (info) => <ProvisionPolicyBadge policy={info.getValue()} />,
}),
Expand All @@ -66,7 +80,28 @@ const staticCols = [
]

export default function SledsTab() {
const emptyState = <EmptyMessage icon={<Servers24Icon />} title="No sleds found" />
const { table } = useQueryTable({ query: sledList, columns: staticCols, emptyState })
return table
const { data } = usePrefetchedQuery(sledList)
const sleds = useMemo(
() =>
R.sortBy(
data.items,
(sled) => sled.slot == null,
(sled) => sled.slot ?? 0
),
[data]
)
const table = useReactTable({
columns: staticCols,
data: sleds,
getRowId: (sled) => sled.id,
getCoreRowModel: getCoreRowModel(),
})
if (sleds.length === 0) {
return (
<TableEmptyBox>
<EmptyMessage icon={<Servers24Icon />} title="No sleds found" />
</TableEmptyBox>
)
}
return <Table table={table} />
}
5 changes: 5 additions & 0 deletions app/pages/system/inventory/sled/SledPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Servers24Icon } from '@oxide/design-system/icons/react'
import { RouteTabs, Tab } from '~/components/RouteTabs'
import { makeCrumb } from '~/hooks/use-crumbs'
import { useSledParams } from '~/hooks/use-params'
import { EmptyCell } from '~/table/cells/EmptyCell'
import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
import { PropertiesTable } from '~/ui/lib/PropertiesTable'
import { truncate } from '~/ui/lib/Truncate'
Expand Down Expand Up @@ -71,6 +72,10 @@ export default function SledPage() {
label="usable physical ram"
bytes={sled.usablePhysicalRam}
/>
<PropertiesTable.Row label="slot">
<span className="text-default">{sled.slot ?? <EmptyCell />}</span>
</PropertiesTable.Row>
<PropertiesTable.DateRow label="Created" date={sled.timeCreated} />
</PropertiesTable>

<RouteTabs fullWidth>
Expand Down
4 changes: 4 additions & 0 deletions mock-api/sled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const sleds: Json<Sled[]> = [
serial: 'BRM02222869',
revision: 0,
},
slot: 0,
usable_hardware_threads: 254,
usable_physical_ram: 1_099_511_627_776,
},
Expand All @@ -43,6 +44,7 @@ export const sleds: Json<Sled[]> = [
serial: 'BRM02222870',
revision: 0,
},
slot: 15,
usable_hardware_threads: 254,
usable_physical_ram: 1_099_511_627_776,
},
Expand All @@ -60,6 +62,7 @@ export const sleds: Json<Sled[]> = [
serial: 'BRM02222868',
revision: 0,
},
slot: 2,
usable_hardware_threads: 254,
usable_physical_ram: 1_099_511_627_776,
},
Expand All @@ -77,6 +80,7 @@ export const sleds: Json<Sled[]> = [
serial: 'BRM02222867',
revision: 0,
},
slot: null,
usable_hardware_threads: 254,
usable_physical_ram: 1_099_511_627_776,
},
Expand Down
11 changes: 9 additions & 2 deletions test/e2e/inventory.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test('Sled inventory page', async ({ page }) => {
// grouping, hence the slightly weird column names
await expectRowVisible(sledsTable, {
id: expect.stringContaining(sleds[0].id),
slot: '0',
'serial number': sleds[0].baseboard.serial,
Kind: 'In service',
'Provision policy': 'Provisionable',
Expand All @@ -45,17 +46,23 @@ test('Sled inventory page', async ({ page }) => {
})
await expectRowVisible(sledsTable, {
id: expect.stringContaining(sleds[3].id),
slot: '—',
'serial number': sleds[3].baseboard.serial,
Kind: 'Expunged',
'Provision policy': '—',
state: 'decommissioned',
})

// Visit the sled detail page of the first sled
await sledsTable.getByRole('link').first().click()
// rows are in slot order, with the sled without a slot last
const slotCells = sledsTable.locator('tbody tr td:first-child')
await expect(slotCells).toHaveText(['0', '2', '15', '—'])

// Visit the sled detail page of the slot 0 sled
await sledsTable.getByRole('link', { name: sleds[0].id }).click()

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

const instancesTab = page.getByRole('tab', { name: 'Instances' })
await expect(instancesTab).toBeVisible()
Expand Down
Loading