-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathModelRegistryTableRowStatus.tsx
More file actions
164 lines (151 loc) · 5.01 KB
/
ModelRegistryTableRowStatus.tsx
File metadata and controls
164 lines (151 loc) · 5.01 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import React from 'react';
import { Label, Popover, Stack, StackItem } from '@patternfly/react-core';
import {
CheckCircleIcon,
ExclamationCircleIcon,
ExclamationTriangleIcon,
InProgressIcon,
} from '@patternfly/react-icons';
import { K8sCondition } from '#~/k8sTypes';
enum ModelRegistryStatus {
Progressing = 'Progressing',
Degraded = 'Degraded',
Available = 'Available',
IstioAvailable = 'IstioAvailable',
GatewayAvailable = 'GatewayAvailable',
}
enum ModelRegistryStatusLabel {
Progressing = 'Progressing',
Available = 'Available',
Degrading = 'Degrading',
Unavailable = 'Unavailable',
}
enum ConditionStatus {
True = 'True',
False = 'False',
}
interface ModelRegistryTableRowStatusProps {
conditions: K8sCondition[] | undefined;
}
export const ModelRegistryTableRowStatus: React.FC<ModelRegistryTableRowStatusProps> = ({
conditions,
}) => {
const conditionsMap =
conditions?.reduce((acc: Record<string, K8sCondition | undefined>, condition) => {
acc[condition.type] = condition;
return acc;
}, {}) ?? {};
let statusLabel: string = ModelRegistryStatusLabel.Progressing;
let icon = <InProgressIcon />;
let status: React.ComponentProps<typeof Label>['status'];
let popoverMessages: string[] = [];
let popoverTitle = '';
if (Object.values(conditionsMap).length) {
const {
[ModelRegistryStatus.Available]: availableCondition,
[ModelRegistryStatus.Progressing]: progressCondition,
[ModelRegistryStatus.Degraded]: degradedCondition,
} = conditionsMap;
popoverMessages =
availableCondition?.status === ConditionStatus.False
? Object.values(conditionsMap).reduce((messages: string[], condition) => {
if (condition?.status === ConditionStatus.False && condition.message) {
messages.push(condition.message);
}
return messages;
}, [])
: [];
// Unavailable
if (
availableCondition?.status === ConditionStatus.False &&
!popoverMessages.some((message) => message.includes('ContainerCreating'))
) {
statusLabel = ModelRegistryStatusLabel.Unavailable;
icon = <ExclamationTriangleIcon />;
status = 'warning';
}
// Degrading
else if (degradedCondition?.status === ConditionStatus.True) {
statusLabel = ModelRegistryStatusLabel.Degrading;
icon = <InProgressIcon className="ai-u-spin" />;
popoverTitle = 'Service is degrading';
}
// Available
else if (availableCondition?.status === ConditionStatus.True) {
statusLabel = ModelRegistryStatusLabel.Available;
icon = <CheckCircleIcon />;
status = 'success';
}
// Progressing
else if (progressCondition?.status === ConditionStatus.True) {
statusLabel = ModelRegistryStatusLabel.Progressing;
icon = <InProgressIcon className="ai-u-spin" />;
status = 'info';
}
}
// Handle popover logic for Unavailable status
if (statusLabel === ModelRegistryStatusLabel.Unavailable) {
const {
[ModelRegistryStatus.IstioAvailable]: istioAvailableCondition,
[ModelRegistryStatus.GatewayAvailable]: gatewayAvailableCondition,
} = conditionsMap;
if (
istioAvailableCondition?.status === ConditionStatus.False &&
gatewayAvailableCondition?.status === ConditionStatus.False
) {
popoverTitle = 'Istio resources and Istio Gateway resources are both unavailable';
} else if (istioAvailableCondition?.status === ConditionStatus.False) {
popoverTitle = 'Istio resources are unavailable';
} else if (gatewayAvailableCondition?.status === ConditionStatus.False) {
popoverTitle = 'Istio Gateway resources are unavailable';
} else if (
istioAvailableCondition?.status === ConditionStatus.True &&
gatewayAvailableCondition?.status === ConditionStatus.True
) {
popoverTitle = 'Deployment is unavailable';
} else {
popoverTitle = 'Service is unavailable';
}
}
const isClickable = popoverTitle && popoverMessages.length;
const label = (
<Label
{...(isClickable
? {
onClick: () => {
/* intentional no-op - Click event is handled by the Popover parent,
this prop enables clickable styles in the PatternFly Label */
},
}
: {})}
data-testid="model-registry-label"
icon={icon}
status={status}
isCompact
>
{statusLabel}
</Label>
);
return popoverTitle && popoverMessages.length ? (
<Popover
headerContent={popoverTitle}
{...(statusLabel === ModelRegistryStatusLabel.Degrading
? {
alertSeverityVariant: 'warning',
headerIcon: <ExclamationTriangleIcon />,
}
: { alertSeverityVariant: 'danger', headerIcon: <ExclamationCircleIcon /> })}
bodyContent={
<Stack hasGutter>
{popoverMessages.map((message, index) => (
<StackItem key={`message-${index}`}>{message}</StackItem>
))}
</Stack>
}
>
{label}
</Popover>
) : (
label
);
};