Skip to content

Commit 3da27b7

Browse files
authored
Add sled policy data to sled page (#2838)
* Add sled provision data to sled page * prefetchQuery -> fetchQuery for affected files * Update attribute name to policy kind
1 parent 99120cd commit 3da27b7

File tree

3 files changed

+56
-45
lines changed

3 files changed

+56
-45
lines changed

app/pages/system/inventory/SledsTab.tsx

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,20 @@
77
*/
88
import { createColumnHelper } from '@tanstack/react-table'
99

10-
import {
11-
getListQFn,
12-
queryClient,
13-
type Sled,
14-
type SledPolicy,
15-
type SledState,
16-
} from '@oxide/api'
10+
import { getListQFn, queryClient, type Sled } from '@oxide/api'
1711
import { Servers24Icon } from '@oxide/design-system/icons/react'
1812

19-
import { EmptyCell } from '~/table/cells/EmptyCell'
2013
import { makeLinkCell } from '~/table/cells/LinkCell'
2114
import { useQueryTable } from '~/table/QueryTable'
22-
import { Badge, type BadgeColor } from '~/ui/lib/Badge'
2315
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
2416
import { pb } from '~/util/path-builder'
2517

26-
const STATE_BADGE_COLORS: Record<SledState, BadgeColor> = {
27-
active: 'default',
28-
decommissioned: 'neutral',
29-
}
18+
import { ProvisionPolicyBadge, SledKindBadge, SledStateBadge } from './sled/SledBadges'
3019

3120
const sledList = getListQFn('sledList', {})
3221

3322
export async function clientLoader() {
34-
await queryClient.prefetchQuery(sledList.optionsFn())
23+
await queryClient.fetchQuery(sledList.optionsFn())
3524
return null
3625
}
3726

@@ -58,35 +47,16 @@ const staticCols = [
5847
columns: [
5948
colHelper.accessor('policy', {
6049
header: 'Kind',
61-
cell: (info) => {
62-
// need to cast because inference is broken inside groups
63-
// https://github.com/TanStack/table/issues/5065
64-
const policy: SledPolicy = info.getValue()
65-
return policy.kind === 'expunged' ? (
66-
<Badge color="neutral">Expunged</Badge>
67-
) : (
68-
<Badge>In service</Badge>
69-
)
70-
},
50+
cell: (info) => <SledKindBadge policy={info.getValue()} />,
7151
}),
7252
colHelper.accessor('policy', {
7353
header: 'Provision policy',
74-
cell: (info) => {
75-
const policy: SledPolicy = info.getValue()
76-
if (policy.kind === 'expunged') return <EmptyCell />
77-
return policy.provisionPolicy === 'provisionable' ? (
78-
<Badge>Provisionable</Badge>
79-
) : (
80-
<Badge color="neutral">Not provisionable</Badge>
81-
)
82-
},
54+
cell: (info) => <ProvisionPolicyBadge policy={info.getValue()} />,
8355
}),
8456
],
8557
}),
8658
colHelper.accessor('state', {
87-
cell: (info) => (
88-
<Badge color={STATE_BADGE_COLORS[info.getValue()]}>{info.getValue()}</Badge>
89-
),
59+
cell: (info) => <SledStateBadge state={info.getValue()} />,
9060
}),
9161
]
9262

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 { SledPolicy, SledState } from '~/api'
9+
import { EmptyCell } from '~/table/cells/EmptyCell'
10+
import { Badge, type BadgeColor } from '~/ui/lib/Badge'
11+
12+
export const SledKindBadge = ({ policy }: { policy: SledPolicy }) =>
13+
policy.kind === 'expunged' ? (
14+
<Badge color="neutral">Expunged</Badge>
15+
) : (
16+
<Badge>In service</Badge>
17+
)
18+
19+
export const ProvisionPolicyBadge = ({ policy }: { policy: SledPolicy }) => {
20+
if (policy.kind === 'expunged') return <EmptyCell />
21+
return policy.provisionPolicy === 'provisionable' ? (
22+
<Badge>Provisionable</Badge>
23+
) : (
24+
<Badge color="neutral">Not provisionable</Badge>
25+
)
26+
}
27+
28+
const STATE_BADGE_COLORS: Record<SledState, BadgeColor> = {
29+
active: 'default',
30+
decommissioned: 'neutral',
31+
}
32+
33+
export const SledStateBadge = ({ state }: { state: SledState }) => (
34+
<Badge color={STATE_BADGE_COLORS[state]}>{state}</Badge>
35+
)

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import { PropertiesTable } from '~/ui/lib/PropertiesTable'
1919
import { truncate } from '~/ui/lib/Truncate'
2020
import { pb } from '~/util/path-builder'
2121

22+
import { ProvisionPolicyBadge, SledKindBadge, SledStateBadge } from './SledBadges'
23+
2224
export async function clientLoader({ params }: LoaderFunctionArgs) {
2325
const { sledId } = requireSledParams(params)
24-
await apiQueryClient.prefetchQuery('sledView', {
25-
path: { sledId },
26-
})
26+
await apiQueryClient.fetchQuery('sledView', { path: { sledId } })
2727
return null
2828
}
2929
export const handle = makeCrumb(
@@ -47,24 +47,30 @@ export default function SledPage() {
4747
<PropertiesTable.Row label="sled id">
4848
<span className="text-default">{sled.id}</span>
4949
</PropertiesTable.Row>
50+
<PropertiesTable.Row label="policy kind">
51+
<SledKindBadge policy={sled.policy} />
52+
</PropertiesTable.Row>
5053
<PropertiesTable.Row label="part">
5154
<span className="text-default">{sled.baseboard.part}</span>
5255
</PropertiesTable.Row>
56+
<PropertiesTable.Row label="provision policy">
57+
<ProvisionPolicyBadge policy={sled.policy} />
58+
</PropertiesTable.Row>
5359
<PropertiesTable.Row label="serial">
5460
<span className="text-default">{sled.baseboard.serial}</span>
5561
</PropertiesTable.Row>
62+
<PropertiesTable.Row label="state">
63+
<SledStateBadge state={sled.state} />
64+
</PropertiesTable.Row>
5665
<PropertiesTable.Row label="revision">
5766
<span className="text-default">{sled.baseboard.revision}</span>
5867
</PropertiesTable.Row>
59-
<PropertiesTable.Row label="rack id">
60-
<span className="text-default">{sled.rackId}</span>
61-
</PropertiesTable.Row>
62-
<PropertiesTable.Row label="location">
63-
<span className="text-disabled">Coming soon</span>
64-
</PropertiesTable.Row>
6568
<PropertiesTable.Row label="usable hardware threads">
6669
<span className="text-default">{sled.usableHardwareThreads}</span>
6770
</PropertiesTable.Row>
71+
<PropertiesTable.Row label="rack id">
72+
<span className="text-default">{sled.rackId}</span>
73+
</PropertiesTable.Row>
6874
<PropertiesTable.Row label="usable physical ram">
6975
<span className="pr-0.5 text-default">{ram.value}</span>
7076
<span className="text-tertiary">{ram.unit}</span>

0 commit comments

Comments
 (0)