-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathStateBadge.tsx
More file actions
85 lines (75 loc) · 2.42 KB
/
Copy pathStateBadge.tsx
File metadata and controls
85 lines (75 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import cn from 'classnames'
import {
diskTransitioning,
instanceTransitioning,
type DiskState,
type InstanceState,
type SnapshotState,
} from '@oxide/api'
import { Badge, type BadgeColor } from '~/ui/lib/Badge'
import { Spinner } from '~/ui/lib/Spinner'
const INSTANCE_COLORS: Record<InstanceState, BadgeColor> = {
running: 'default',
stopped: 'neutral',
failed: 'destructive',
destroyed: 'destructive',
creating: 'default',
starting: 'blue',
rebooting: 'blue',
migrating: 'purple',
repairing: 'notice',
stopping: 'neutral',
}
const badgeClasses = 'children:flex children:items-center children:gap-1'
export const InstanceStateBadge = (props: { state: InstanceState; className?: string }) => (
<Badge color={INSTANCE_COLORS[props.state]} className={cn(props.className, badgeClasses)}>
{instanceTransitioning(props.state) && (
<Spinner size="sm" variant={INSTANCE_COLORS[props.state]} />
)}
{props.state}
</Badge>
)
type DiskStateStr = DiskState['state']
const DISK_COLORS: Record<DiskStateStr, BadgeColor> = {
attached: 'default',
attaching: 'blue',
creating: 'default',
detaching: 'blue',
detached: 'neutral',
destroyed: 'destructive', // should we ever see this?
faulted: 'destructive',
maintenance: 'notice',
import_ready: 'blue',
importing_from_url: 'purple',
importing_from_bulk_writes: 'purple',
finalizing: 'blue',
}
export const DiskStateBadge = (props: { state: DiskStateStr; className?: string }) => (
<Badge color={DISK_COLORS[props.state]} className={cn(props.className, badgeClasses)}>
{diskTransitioning(props.state) && (
<Spinner size="sm" variant={DISK_COLORS[props.state]} />
)}
{props.state.replace(/_/g, ' ')}
</Badge>
)
const SNAPSHOT_COLORS: Record<SnapshotState, BadgeColor> = {
creating: 'default',
destroyed: 'neutral',
faulted: 'destructive',
ready: 'default',
}
export const SnapshotStateBadge = (props: { state: SnapshotState; className?: string }) => (
<Badge color={SNAPSHOT_COLORS[props.state]} className={cn(props.className, badgeClasses)}>
{props.state === 'creating' && (
<Spinner size="sm" variant={SNAPSHOT_COLORS[props.state]} />
)}
{props.state}
</Badge>
)