Skip to content

Commit 11486f8

Browse files
authored
Add switches tab to system inventory (#2620)
* Add switches tab * Add basic test * Update path snapshots * Drop Rack ID for now * womp womp test update
1 parent ada302c commit 11486f8

File tree

11 files changed

+110
-2
lines changed

11 files changed

+110
-2
lines changed

app/pages/system/inventory/InventoryPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function InventoryPage() {
4343
<RouteTabs fullWidth>
4444
<Tab to={pb.sledInventory()}>Sleds</Tab>
4545
<Tab to={pb.diskInventory()}>Disks</Tab>
46+
<Tab to={pb.switchInventory()}>Switches</Tab>
4647
</RouteTabs>
4748
</>
4849
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright Oxide Computer Company
7+
*/
8+
import { createColumnHelper } from '@tanstack/react-table'
9+
10+
import { getListQFn, queryClient, type Switch } from '@oxide/api'
11+
import { Servers24Icon } from '@oxide/design-system/icons/react'
12+
13+
import { useQueryTable } from '~/table/QueryTable'
14+
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
15+
16+
const EmptyState = () => (
17+
<EmptyMessage
18+
icon={<Servers24Icon />}
19+
title="Something went wrong"
20+
body="We expected some switches here, but none were found"
21+
/>
22+
)
23+
24+
const switchList = getListQFn('switchList', {})
25+
26+
export async function loader() {
27+
await queryClient.prefetchQuery(switchList.optionsFn())
28+
return null
29+
}
30+
31+
const colHelper = createColumnHelper<Switch>()
32+
const staticCols = [
33+
colHelper.accessor('id', {}),
34+
colHelper.accessor('baseboard.part', { header: 'part number' }),
35+
colHelper.accessor('baseboard.serial', { header: 'serial number' }),
36+
colHelper.accessor('baseboard.revision', { header: 'revision' }),
37+
]
38+
39+
Component.displayName = 'SwitchesTab'
40+
export function Component() {
41+
const emptyState = <EmptyState />
42+
const { table } = useQueryTable({ query: switchList, columns: staticCols, emptyState })
43+
return table
44+
}

app/routes.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import { InventoryPage } from './pages/system/inventory/InventoryPage'
8383
import * as SledInstances from './pages/system/inventory/sled/SledInstancesTab'
8484
import * as SledPage from './pages/system/inventory/sled/SledPage'
8585
import * as SledsTab from './pages/system/inventory/SledsTab'
86+
import * as SwitchesTab from './pages/system/inventory/SwitchesTab'
8687
import * as IpPool from './pages/system/networking/IpPoolPage'
8788
import * as IpPools from './pages/system/networking/IpPoolsPage'
8889
import * as SiloImages from './pages/system/SiloImagesPage'
@@ -164,6 +165,7 @@ export const routes = createRoutesFromElements(
164165
<Route index element={<Navigate to="sleds" replace />} loader={SledsTab.loader} />
165166
<Route path="sleds" {...SledsTab} handle={{ crumb: 'Sleds' }} />
166167
<Route path="disks" {...DisksTab} handle={{ crumb: 'Disks' }} />
168+
<Route path="switches" {...SwitchesTab} handle={{ crumb: 'Switches' }} />
167169
</Route>
168170
<Route path="inventory" handle={{ crumb: 'Inventory' }}>
169171
<Route path="sleds" handle={{ crumb: 'Sleds' }}>

app/util/__snapshots__/path-builder.spec.ts.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,16 @@ exports[`breadcrumbs 2`] = `
581581
"path": "/settings/ssh-keys",
582582
},
583583
],
584+
"switchInventory (/system/inventory/switches)": [
585+
{
586+
"label": "Inventory",
587+
"path": "/system/inventory/sleds",
588+
},
589+
{
590+
"label": "Switches",
591+
"path": "/system/inventory/switches",
592+
},
593+
],
584594
"systemUtilization (/system/utilization)": [
585595
{
586596
"label": "Utilization",

app/util/path-builder.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ test('path builder', () => {
8787
"sshKeyEdit": "/settings/ssh-keys/ss/edit",
8888
"sshKeys": "/settings/ssh-keys",
8989
"sshKeysNew": "/settings/ssh-keys-new",
90+
"switchInventory": "/system/inventory/switches",
9091
"systemUtilization": "/system/utilization",
9192
"vpc": "/projects/p/vpcs/v/firewall-rules",
9293
"vpcEdit": "/projects/p/vpcs/v/edit",

app/util/path-builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export const pb = {
104104

105105
sledInventory: () => '/system/inventory/sleds',
106106
diskInventory: () => '/system/inventory/disks',
107+
switchInventory: () => '/system/inventory/switches',
107108
sled: ({ sledId }: PP.Sled) => `/system/inventory/sleds/${sledId}/instances`,
108109
sledInstances: ({ sledId }: PP.Sled) => `/system/inventory/sleds/${sledId}/instances`,
109110

mock-api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export * from './silo'
2222
export * from './sled'
2323
export * from './snapshot'
2424
export * from './sshKeys'
25+
export * from './switch'
2526
export * from './user'
2627
export * from './user-group'
2728
export * from './user'

mock-api/msw/db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ const initDb = {
461461
siloProvisioned: [...mock.siloProvisioned],
462462
identityProviders: [...mock.identityProviders],
463463
sleds: [...mock.sleds],
464+
switches: [...mock.switches],
464465
snapshots: [...mock.snapshots],
465466
sshKeys: [...mock.sshKeys],
466467
users: [...mock.users],

mock-api/msw/handlers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,11 @@ export const handlers = makeHandlers({
15211521
return paginated(query, db.users)
15221522
},
15231523

1524+
switchList: ({ query, cookies }) => {
1525+
requireFleetViewer(cookies)
1526+
return paginated(query, db.switches)
1527+
},
1528+
15241529
systemPolicyView({ cookies }) {
15251530
requireFleetViewer(cookies)
15261531

@@ -1603,7 +1608,6 @@ export const handlers = makeHandlers({
16031608
sledAdd: NotImplemented,
16041609
sledListUninitialized: NotImplemented,
16051610
sledSetProvisionPolicy: NotImplemented,
1606-
switchList: NotImplemented,
16071611
switchView: NotImplemented,
16081612
systemPolicyUpdate: NotImplemented,
16091613
systemQuotasList: NotImplemented,

mock-api/switch.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright Oxide Computer Company
7+
*/
8+
import type { Switch } from '@oxide/api'
9+
10+
import type { Json } from './json-type'
11+
import { rack } from './rack'
12+
13+
export const switches: Json<Switch[]> = [
14+
{
15+
baseboard: {
16+
part: '832-0431906',
17+
serial: 'BDS02141689',
18+
revision: 1,
19+
},
20+
id: 'ed66617e-4955-465e-b810-0d0dc55d4511',
21+
rack_id: rack.id,
22+
time_created: rack.time_created,
23+
time_modified: rack.time_modified,
24+
},
25+
]

0 commit comments

Comments
 (0)