|
| 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 | +} |
0 commit comments