Skip to content

Commit 5640bf9

Browse files
authored
refactor: don't use QueryTable for instance disks table (#2454)
refactor: don't use QueryTable for instance disks table
1 parent e3d4245 commit 5640bf9

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

app/pages/project/instances/instance/tabs/StorageTab.tsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright Oxide Computer Company
77
*/
8-
import { createColumnHelper } from '@tanstack/react-table'
8+
import { createColumnHelper, getCoreRowModel, useReactTable } from '@tanstack/react-table'
99
import { useCallback, useMemo, useState } from 'react'
1010
import type { LoaderFunctionArgs } from 'react-router-dom'
1111

@@ -28,25 +28,34 @@ import { getInstanceSelector, useInstanceSelector } from '~/hooks/use-params'
2828
import { addToast } from '~/stores/toast'
2929
import { useColsWithActions, type MenuAction } from '~/table/columns/action-col'
3030
import { Columns } from '~/table/columns/common'
31-
import { PAGE_SIZE, useQueryTable } from '~/table/QueryTable'
31+
import { Table } from '~/table/Table'
3232
import { Button } from '~/ui/lib/Button'
3333
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
34+
import { TableEmptyBox } from '~/ui/lib/Table'
3435

3536
import { fancifyStates } from './common'
3637

38+
const EmptyState = () => (
39+
<TableEmptyBox>
40+
<EmptyMessage
41+
icon={<Storage24Icon />}
42+
title="No disks"
43+
body="Attach a disk to this instance to see it here"
44+
/>
45+
</TableEmptyBox>
46+
)
47+
3748
StorageTab.loader = async ({ params }: LoaderFunctionArgs) => {
3849
const { project, instance } = getInstanceSelector(params)
50+
const selector = { path: { instance }, query: { project } }
3951
await Promise.all([
40-
apiQueryClient.prefetchQuery('instanceDiskList', {
41-
path: { instance },
42-
query: { project, limit: PAGE_SIZE },
43-
}),
52+
// don't bother with page size because this will never paginate. max disks
53+
// per instance is 8
54+
// https://github.com/oxidecomputer/omicron/blob/40fc3835/nexus/db-queries/src/db/queries/disk.rs#L16-L21
55+
apiQueryClient.prefetchQuery('instanceDiskList', selector),
4456
// This is covered by the InstancePage loader but there's no downside to
4557
// being redundant. If it were removed there, we'd still want it here.
46-
apiQueryClient.prefetchQuery('instanceView', {
47-
path: { instance },
48-
query: { project },
49-
}),
58+
apiQueryClient.prefetchQuery('instanceView', selector),
5059
])
5160
return null
5261
}
@@ -158,21 +167,17 @@ export function StorageTab() {
158167
},
159168
})
160169

161-
const { Table } = useQueryTable('instanceDiskList', instancePathQuery)
162-
163-
const emptyState = (
164-
<EmptyMessage
165-
icon={<Storage24Icon />}
166-
title="No disks"
167-
body="Attach a disk to this instance to see it here"
168-
/>
169-
)
170+
const { data: disks } = usePrefetchedApiQuery('instanceDiskList', instancePathQuery)
170171

171-
const columns = useColsWithActions(staticCols, makeActions)
172+
const table = useReactTable({
173+
columns: useColsWithActions(staticCols, makeActions),
174+
data: disks.items,
175+
getCoreRowModel: getCoreRowModel(),
176+
})
172177

173178
return (
174179
<>
175-
<Table emptyState={emptyState} columns={columns} />
180+
{disks.items.length > 0 ? <Table table={table} /> : <EmptyState />}
176181
<div className="mt-4 flex flex-col gap-3">
177182
<div className="flex gap-3">
178183
<Button

0 commit comments

Comments
 (0)