Skip to content

Commit d836fca

Browse files
committed
Add snapshot state
1 parent 6271041 commit d836fca

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

app/components/StatusBadge.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DiskState, InstanceState } from '@oxide/api'
1+
import type { DiskState, InstanceState, SnapshotState } from '@oxide/api'
22
import type { BadgeColor, BadgeProps } from '@oxide/ui'
33
import { Badge } from '@oxide/ui'
44

@@ -41,3 +41,23 @@ export const DiskStatusBadge = (props: { status: DiskStateStr; className?: strin
4141
{props.status}
4242
</Badge>
4343
)
44+
45+
const SNAPSHOT_COLORS: Record<SnapshotState, BadgeColor> = {
46+
creating: 'notice',
47+
destroyed: 'neutral',
48+
faulted: 'destructive',
49+
ready: 'default',
50+
}
51+
52+
export const SnapshotStatusBadge = (props: {
53+
status: SnapshotState
54+
className?: string
55+
}) => (
56+
<Badge
57+
variant="default"
58+
color={SNAPSHOT_COLORS[props.status]}
59+
className={props.className}
60+
>
61+
{props.status}
62+
</Badge>
63+
)

app/pages/project/snapshots/SnapshotsPage.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom'
33
import { Link } from 'react-router-dom'
44

55
import type { Snapshot } from '@oxide/api'
6+
import { useApiQuery } from '@oxide/api'
67
import { apiQueryClient, useApiMutation, useApiQueryClient } from '@oxide/api'
78
import type { MenuAction } from '@oxide/table'
89
import { DateCell, SizeCell, useQueryTable } from '@oxide/table'
@@ -15,10 +16,17 @@ import {
1516
buttonStyle,
1617
} from '@oxide/ui'
1718

19+
import { SnapshotStatusBadge } from 'app/components/StatusBadge'
1820
import { CreateSnapshotSideModalForm } from 'app/forms/snapshot-create'
1921
import { requireProjectParams, useProjectParams, useRequiredParams } from 'app/hooks'
2022
import { pb } from 'app/util/path-builder'
2123

24+
const DiskNameFromId = ({ value }: { value: string }) => {
25+
const { data: disk } = useApiQuery('diskViewById', { id: value })
26+
if (!disk) return null
27+
return <>{disk.name}</>
28+
}
29+
2230
const EmptyState = () => (
2331
<EmptyMessage
2432
icon={<Snapshots24Icon />}
@@ -78,6 +86,11 @@ export function SnapshotsPage({ modal }: SnapshotsPageProps) {
7886
<Table emptyState={<EmptyState />} makeActions={makeActions}>
7987
<Column accessor="name" />
8088
<Column accessor="description" />
89+
<Column id="disk" accessor="diskId" cell={DiskNameFromId} />
90+
<Column
91+
accessor="state"
92+
cell={({ value }) => <SnapshotStatusBadge status={value} />}
93+
/>
8194
<Column accessor="size" cell={SizeCell} />
8295
<Column accessor="timeCreated" cell={DateCell} />
8396
</Table>

0 commit comments

Comments
 (0)