diff --git a/app/pages/system/inventory/SledsTab.tsx b/app/pages/system/inventory/SledsTab.tsx index 6c2df8561..1cde91543 100644 --- a/app/pages/system/inventory/SledsTab.tsx +++ b/app/pages/system/inventory/SledsTab.tsx @@ -5,23 +5,28 @@ * * 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 } @@ -29,6 +34,13 @@ export const handle = { crumb: 'Sleds' } const colHelper = createColumnHelper() const staticCols = [ + colHelper.accessor('slot', { + cell: (info) => ( +
+ {info.getValue() ?? } +
+ ), + }), colHelper.accessor('id', { cell: (info) => ( @@ -51,10 +63,12 @@ const staticCols = [ header: 'Policy', columns: [ colHelper.accessor('policy', { + id: 'policyKind', header: 'Kind', cell: (info) => , }), colHelper.accessor('policy', { + id: 'provisionPolicy', header: 'Provision policy', cell: (info) => , }), @@ -66,7 +80,28 @@ const staticCols = [ ] export default function SledsTab() { - const emptyState = } 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 ( + + } title="No sleds found" /> + + ) + } + return } diff --git a/app/pages/system/inventory/sled/SledPage.tsx b/app/pages/system/inventory/sled/SledPage.tsx index 332424c21..dbe262372 100644 --- a/app/pages/system/inventory/sled/SledPage.tsx +++ b/app/pages/system/inventory/sled/SledPage.tsx @@ -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' @@ -71,6 +72,10 @@ export default function SledPage() { label="usable physical ram" bytes={sled.usablePhysicalRam} /> + + {sled.slot ?? } + + diff --git a/mock-api/sled.ts b/mock-api/sled.ts index 0c6ecf92b..5f6bda829 100644 --- a/mock-api/sled.ts +++ b/mock-api/sled.ts @@ -25,6 +25,7 @@ export const sleds: Json = [ serial: 'BRM02222869', revision: 0, }, + slot: 0, usable_hardware_threads: 254, usable_physical_ram: 1_099_511_627_776, }, @@ -43,6 +44,7 @@ export const sleds: Json = [ serial: 'BRM02222870', revision: 0, }, + slot: 15, usable_hardware_threads: 254, usable_physical_ram: 1_099_511_627_776, }, @@ -60,6 +62,7 @@ export const sleds: Json = [ serial: 'BRM02222868', revision: 0, }, + slot: 2, usable_hardware_threads: 254, usable_physical_ram: 1_099_511_627_776, }, @@ -77,6 +80,7 @@ export const sleds: Json = [ serial: 'BRM02222867', revision: 0, }, + slot: null, usable_hardware_threads: 254, usable_physical_ram: 1_099_511_627_776, }, diff --git a/test/e2e/inventory.e2e.ts b/test/e2e/inventory.e2e.ts index 3a7753062..824ce3570 100644 --- a/test/e2e/inventory.e2e.ts +++ b/test/e2e/inventory.e2e.ts @@ -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', @@ -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()