-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathEvaluationStatusLabel.tsx
More file actions
114 lines (105 loc) · 2.53 KB
/
EvaluationStatusLabel.tsx
File metadata and controls
114 lines (105 loc) · 2.53 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import * as React from 'react';
import { Icon, Label, LabelProps, Popover, Stack, StackItem } from '@patternfly/react-core';
import {
BanIcon,
CheckCircleIcon,
ExclamationCircleIcon,
InProgressIcon,
OffIcon,
PendingIcon,
} from '@patternfly/react-icons';
import { EvaluationJobState } from '~/app/types';
type StatusConfig = {
label: string;
color?: LabelProps['color'];
status?: LabelProps['status'];
icon: React.ReactNode;
isFilled?: boolean;
};
const statusMap: Record<EvaluationJobState, StatusConfig> = {
pending: {
label: 'Pending',
color: 'purple',
icon: <PendingIcon />,
},
running: {
label: 'Running',
color: 'blue',
icon: <InProgressIcon />,
},
completed: {
label: 'Complete',
status: 'success',
icon: <CheckCircleIcon />,
},
failed: {
label: 'Failed',
status: 'danger',
icon: <ExclamationCircleIcon />,
isFilled: true,
},
cancelled: {
label: 'Canceled',
color: 'grey',
icon: <BanIcon />,
},
stopping: {
label: 'Canceling',
color: 'grey',
icon: <InProgressIcon className="ai-u-spin" />,
},
stopped: {
label: 'Stopped',
color: 'grey',
icon: <OffIcon />,
},
};
type EvaluationStatusLabelProps = {
state: EvaluationJobState;
message?: string;
};
const EvaluationStatusLabel: React.FC<EvaluationStatusLabelProps> = ({ state, message }) => {
const config = statusMap[state];
const hasPopover = state === 'failed' && !!message;
const label = (
<Label
variant={config.isFilled ? 'filled' : 'outline'}
color={config.color}
status={config.status}
icon={<Icon isInline>{config.icon}</Icon>}
data-testid={`status-label-${state}`}
{...(hasPopover
? {
onClick: () => {
/* intentional no-op - Click event is handled by the Popover parent,
this prop enables clickable styles in the PatternFly Label */
},
}
: {})}
>
{config.label}
</Label>
);
if (!hasPopover) {
return label;
}
const lines = message.split('\n').filter(Boolean);
return (
<Popover
headerContent="Evaluation failed"
alertSeverityVariant="danger"
headerIcon={<ExclamationCircleIcon />}
data-testid="evaluation-status-popover"
bodyContent={
<Stack hasGutter>
{lines.map((line, index) => (
<StackItem key={`message-${index}`}>{line}</StackItem>
))}
</Stack>
}
>
{label}
</Popover>
);
};
export default EvaluationStatusLabel;