Skip to content

Commit

Permalink
make it a little cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Sep 18, 2024
1 parent e904012 commit aa828ea
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions app/pages/project/instances/instance/tabs/StorageTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useApiQueryClient,
usePrefetchedApiQuery,
type Disk,
type Instance,
type InstanceState,
} from '@oxide/api'
import { Storage24Icon } from '@oxide/design-system/icons/react'

Expand Down Expand Up @@ -61,22 +61,19 @@ StorageTab.loader = async ({ params }: LoaderFunctionArgs) => {
return null
}

type InstanceDisk = {
// hack to opt in to auto copy ID button
id: string // disk ID
disk: Disk
instance: Instance
type InstanceDisk = Disk & {
instanceState: InstanceState
}

const colHelper = createColumnHelper<InstanceDisk>()
const staticCols = [
colHelper.accessor('disk.name', { header: 'Disk' }),
colHelper.accessor('disk.size', Columns.size),
colHelper.accessor((row) => row.disk.state.state, {
colHelper.accessor('name', { header: 'Disk' }),
colHelper.accessor('size', Columns.size),
colHelper.accessor((row) => row.state.state, {
header: 'state',
cell: (info) => <DiskStateBadge state={info.getValue()} />,
}),
colHelper.accessor('disk.timeCreated', Columns.timeCreated),
colHelper.accessor('timeCreated', Columns.timeCreated),
]

export function StorageTab() {
Expand Down Expand Up @@ -120,7 +117,7 @@ export function StorageTab() {
const { data: instance } = usePrefetchedApiQuery('instanceView', instancePathQuery)

const makeActions = useCallback(
({ disk, instance }: InstanceDisk): MenuAction[] => [
(disk: InstanceDisk): MenuAction[] => [
{
label: 'Snapshot',
disabled: !diskCan.snapshot(disk) && (
Expand All @@ -143,7 +140,7 @@ export function StorageTab() {
// don't bother checking disk state: assume that if it is showing up
// in this list, it can be detached
label: 'Detach',
disabled: !instanceCan.detachDisk(instance) && (
disabled: !instanceCan.detachDisk({ runState: disk.instanceState }) && (
<>
Instance must be <span className="text-default">stopped</span> before disk can
be detached
Expand Down Expand Up @@ -176,7 +173,7 @@ export function StorageTab() {
const { data: disks } = usePrefetchedApiQuery('instanceDiskList', instancePathQuery)

const rows = useMemo(
() => disks.items.map((disk) => ({ id: disk.id, disk, instance })),
() => disks.items.map((disk) => ({ ...disk, instanceState: instance.runState })),
[disks.items, instance]
)

Expand Down

0 comments on commit aa828ea

Please sign in to comment.