-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecutionStatusBadge.tsx
67 lines (61 loc) · 1.95 KB
/
ExecutionStatusBadge.tsx
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
import { Badge, ProgressCircle, SpectrumBadgeProps, Text } from '@adobe/react-spectrum';
import Alert from '@spectrum-icons/workflow/Alert';
import Cancel from '@spectrum-icons/workflow/Cancel';
import Checkmark from '@spectrum-icons/workflow/Checkmark';
import Clock from '@spectrum-icons/workflow/Clock';
import Pause from '@spectrum-icons/workflow/Pause';
import React from 'react';
import { ExecutionStatus } from '../utils/api.types';
type ExecutionStatusProps = {
value: ExecutionStatus;
} & Partial<SpectrumBadgeProps>;
const getVariant = (status: ExecutionStatus): 'positive' | 'negative' | 'neutral' | 'info' | 'yellow' => {
switch (status) {
case ExecutionStatus.SUCCEEDED:
return 'positive';
case ExecutionStatus.FAILED:
return 'negative';
case ExecutionStatus.ACTIVE:
return 'info';
case ExecutionStatus.QUEUED:
return 'yellow';
case ExecutionStatus.STOPPED:
case ExecutionStatus.SKIPPED:
return 'neutral';
case ExecutionStatus.ABORTED:
return 'negative';
default:
return 'neutral';
}
};
const getIcon = (status: ExecutionStatus) => {
switch (status) {
case ExecutionStatus.SUCCEEDED:
return <Checkmark />;
case ExecutionStatus.FAILED:
return <Alert />;
case ExecutionStatus.ACTIVE:
return <ProgressCircle size="S" aria-label="Loading…" isIndeterminate marginX="size-100" />;
case ExecutionStatus.QUEUED:
return <Clock />;
case ExecutionStatus.STOPPED:
return <Pause />;
case ExecutionStatus.SKIPPED:
return <Pause />;
case ExecutionStatus.ABORTED:
return <Cancel />;
default:
return null;
}
};
const ExecutionStatusBadge: React.FC<ExecutionStatusProps> = ({ value, ...props }) => {
const variant = getVariant(value);
const icon = getIcon(value);
return (
<Badge variant={variant} {...props}>
<Text>{value.toLowerCase()}</Text>
{icon}
</Badge>
);
};
export default ExecutionStatusBadge;