Skip to content

Commit aab30d0

Browse files
committed
use beautiful column grouping
1 parent 1b44e4c commit aab30d0

File tree

3 files changed

+71
-33
lines changed

3 files changed

+71
-33
lines changed

app/pages/system/UtilizationPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function UsageTab() {
162162
<Table className="w-full">
163163
<Table.Header>
164164
<Table.HeaderRow>
165-
<Table.HeadCell>Silo</Table.HeadCell>
165+
<Table.HeadCell data-test-ignore></Table.HeadCell>
166166
{/* data-test-ignore makes the row asserts work in the e2e tests */}
167167
<Table.HeadCell colSpan={3} data-test-ignore>
168168
Provisioned / Quota
@@ -173,7 +173,7 @@ function UsageTab() {
173173
<Table.HeadCell data-test-ignore></Table.HeadCell>
174174
</Table.HeaderRow>
175175
<Table.HeaderRow>
176-
<Table.HeadCell data-test-ignore></Table.HeadCell>
176+
<Table.HeadCell>Silo</Table.HeadCell>
177177
<Table.HeadCell>CPU</Table.HeadCell>
178178
<Table.HeadCell>Memory</Table.HeadCell>
179179
<Table.HeadCell>Storage</Table.HeadCell>

app/pages/system/inventory/SledsTab.tsx

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ import { createColumnHelper } from '@tanstack/react-table'
1010
import {
1111
getListQFn,
1212
queryClient,
13+
SledPolicy,
1314
type Sled,
1415
type SledProvisionPolicy,
1516
type SledState,
1617
} from '@oxide/api'
17-
import { Servers24Icon } from '@oxide/design-system/icons/react'
18+
import {
19+
Checkmark12Icon,
20+
Close12Icon,
21+
Servers24Icon,
22+
} from '@oxide/design-system/icons/react'
1823

1924
import { makeLinkCell } from '~/table/cells/LinkCell'
2025
import { useQueryTable } from '~/table/QueryTable'
@@ -45,24 +50,45 @@ const staticCols = [
4550
cell: makeLinkCell((sledId) => pb.sled({ sledId })),
4651
}),
4752
// TODO: colHelper.accessor('baseboard.serviceAddress', { header: 'service address' }),
48-
colHelper.accessor('baseboard.part', { header: 'part number' }),
49-
colHelper.accessor('baseboard.serial', { header: 'serial number' }),
50-
colHelper.accessor('baseboard.revision', { header: 'revision' }),
51-
colHelper.accessor('policy', {
52-
header: 'policy',
53-
cell: (info) => {
54-
const policy = info.getValue()
55-
if (policy.kind === 'expunged') return <Badge color="neutral">Expunged</Badge>
56-
const [label, color] = PROV_POLICY_DISP[policy.provisionPolicy]
57-
return (
58-
<div className="space-x-0.5">
59-
<Badge>In service</Badge>
60-
<Badge variant="solid" color={color}>
61-
{label}
62-
</Badge>
63-
</div>
64-
)
65-
},
53+
colHelper.group({
54+
id: 'baseboard',
55+
header: 'Baseboard',
56+
columns: [
57+
colHelper.accessor('baseboard.part', { header: 'part number' }),
58+
colHelper.accessor('baseboard.serial', { header: 'serial number' }),
59+
colHelper.accessor('baseboard.revision', { header: 'revision' }),
60+
],
61+
}),
62+
colHelper.group({
63+
id: 'policy',
64+
header: 'Policy',
65+
columns: [
66+
colHelper.accessor('policy', {
67+
header: 'Kind',
68+
cell: (info) => {
69+
// need to cast because inference is broken inside groups
70+
// https://github.com/TanStack/table/issues/5065
71+
const policy: SledPolicy = info.getValue()
72+
return policy.kind === 'expunged' ? (
73+
<Badge color="neutral">Expunged</Badge>
74+
) : (
75+
<Badge>In service</Badge>
76+
)
77+
},
78+
}),
79+
colHelper.accessor('policy', {
80+
header: 'Provisionable',
81+
cell: (info) => {
82+
const policy: SledPolicy = info.getValue()
83+
if (policy.kind === 'expunged') return <Close12Icon />
84+
return policy.provisionPolicy === 'provisionable' ? (
85+
<Checkmark12Icon className="text-accent" />
86+
) : (
87+
<Close12Icon />
88+
)
89+
},
90+
}),
91+
],
6692
}),
6793
colHelper.accessor('state', {
6894
cell: (info) => (

app/table/Table.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,30 @@ export const Table = <TData,>({
2929
}: TableProps<TData>) => (
3030
<UITable {...tableProps}>
3131
<UITable.Header>
32-
{table.getHeaderGroups().map((headerGroup) => (
33-
<UITable.HeaderRow key={headerGroup.id}>
34-
{headerGroup.headers.map((header) => (
35-
<UITable.HeadCell
36-
key={header.id}
37-
className={header.column.columnDef.meta?.thClassName}
38-
>
39-
{flexRender(header.column.columnDef.header, header.getContext())}
40-
</UITable.HeadCell>
41-
))}
42-
</UITable.HeaderRow>
43-
))}
32+
{table.getHeaderGroups().map((headerGroup) => {
33+
console.log(headerGroup)
34+
return (
35+
<UITable.HeaderRow key={headerGroup.id}>
36+
{headerGroup.headers.map((header) => (
37+
<UITable.HeadCell
38+
key={header.id}
39+
className={header.column.columnDef.meta?.thClassName}
40+
colSpan={header.colSpan}
41+
>
42+
{
43+
// Placeholder concept is for when grouped columns are
44+
// combined with regular columns. The regular column only
45+
// needs one entry in the stack of header cells, so the others
46+
// have isPlacholder=true. See sleds table for an example.
47+
header.isPlaceholder
48+
? null
49+
: flexRender(header.column.columnDef.header, header.getContext())
50+
}
51+
</UITable.HeadCell>
52+
))}
53+
</UITable.HeaderRow>
54+
)
55+
})}
4456
</UITable.Header>
4557
<UITable.Body>
4658
{table.getRowModel().rows.map((row) => {

0 commit comments

Comments
 (0)