5
5
*
6
6
* Copyright Oxide Computer Company
7
7
*/
8
- import { createColumnHelper } from '@tanstack/react-table'
8
+ import { createColumnHelper , getCoreRowModel , useReactTable } from '@tanstack/react-table'
9
9
import { useCallback , useMemo , useState } from 'react'
10
10
import type { LoaderFunctionArgs } from 'react-router-dom'
11
11
@@ -28,25 +28,34 @@ import { getInstanceSelector, useInstanceSelector } from '~/hooks/use-params'
28
28
import { addToast } from '~/stores/toast'
29
29
import { useColsWithActions , type MenuAction } from '~/table/columns/action-col'
30
30
import { Columns } from '~/table/columns/common'
31
- import { PAGE_SIZE , useQueryTable } from '~/table/QueryTable '
31
+ import { Table } from '~/table/Table '
32
32
import { Button } from '~/ui/lib/Button'
33
33
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
34
+ import { TableEmptyBox } from '~/ui/lib/Table'
34
35
35
36
import { fancifyStates } from './common'
36
37
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
+
37
48
StorageTab . loader = async ( { params } : LoaderFunctionArgs ) => {
38
49
const { project, instance } = getInstanceSelector ( params )
50
+ const selector = { path : { instance } , query : { project } }
39
51
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 ) ,
44
56
// This is covered by the InstancePage loader but there's no downside to
45
57
// 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 ) ,
50
59
] )
51
60
return null
52
61
}
@@ -158,21 +167,17 @@ export function StorageTab() {
158
167
} ,
159
168
} )
160
169
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 )
170
171
171
- const columns = useColsWithActions ( staticCols , makeActions )
172
+ const table = useReactTable ( {
173
+ columns : useColsWithActions ( staticCols , makeActions ) ,
174
+ data : disks . items ,
175
+ getCoreRowModel : getCoreRowModel ( ) ,
176
+ } )
172
177
173
178
return (
174
179
< >
175
- < Table emptyState = { emptyState } columns = { columns } />
180
+ { disks . items . length > 0 ? < Table table = { table } /> : < EmptyState /> }
176
181
< div className = "mt-4 flex flex-col gap-3" >
177
182
< div className = "flex gap-3" >
178
183
< Button
0 commit comments