-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathNotebookStatusLabel.tsx
More file actions
106 lines (99 loc) · 2.58 KB
/
NotebookStatusLabel.tsx
File metadata and controls
106 lines (99 loc) · 2.58 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
import * as React from 'react';
import { Label, LabelProps } from '@patternfly/react-core';
import {
CheckCircleIcon,
ExclamationCircleIcon,
InProgressIcon,
OffIcon,
} from '@patternfly/react-icons';
import { EventStatus, NotebookStatus } from '#~/types';
import { getKueueStatusInfo } from '#~/concepts/kueue';
import {
KUEUE_STATUSES_OVERRIDE_WORKBENCH,
type KueueWorkloadStatusWithMessage,
} from '#~/concepts/kueue/types';
type NotebookStateStatusProps = {
isStarting: boolean;
isStopping: boolean;
isRunning: boolean;
notebookStatus?: NotebookStatus | null;
kueueStatus?: KueueWorkloadStatusWithMessage | null;
isCompact?: boolean;
onClick?: LabelProps['onClick'];
};
type StatusLabelSettings = {
label: string;
color?: LabelProps['color'];
status?: LabelProps['status'];
icon: React.ReactNode;
};
const NotebookStatusLabel: React.FC<NotebookStateStatusProps> = ({
isStarting,
isStopping,
isRunning,
notebookStatus,
kueueStatus = null,
isCompact,
onClick,
}) => {
const isError = notebookStatus?.currentStatus === EventStatus.ERROR;
const labelSettings = React.useMemo<StatusLabelSettings>(() => {
if (isError) {
return {
label: 'Failed',
status: 'danger',
icon: <ExclamationCircleIcon />,
};
}
if (isStopping) {
return {
label: 'Stopping',
color: 'grey',
icon: <InProgressIcon className="ai-u-spin" />,
};
}
if (kueueStatus?.status && KUEUE_STATUSES_OVERRIDE_WORKBENCH.includes(kueueStatus.status)) {
const info = getKueueStatusInfo(kueueStatus.status);
return {
label: info.label,
color: info.color,
status: info.status,
icon: <info.IconComponent className={info.iconClassName} />,
};
}
if (isStarting) {
return {
label: 'Starting',
color: 'blue',
icon: <InProgressIcon className="ai-u-spin" />,
};
}
if (isRunning) {
return {
label: 'Ready',
status: 'success',
icon: <CheckCircleIcon />,
};
}
return {
label: 'Stopped',
color: 'grey',
icon: <OffIcon />,
};
}, [kueueStatus, isError, isRunning, isStarting, isStopping]);
return (
<Label
variant={onClick ? 'filled' : 'outline'}
isCompact={isCompact}
color={labelSettings.color}
status={labelSettings.status}
icon={labelSettings.icon}
data-testid="notebook-status-text"
style={{ width: 'fit-content' }}
onClick={onClick}
>
{labelSettings.label}
</Label>
);
};
export default NotebookStatusLabel;