-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathModelTransferJobTableRow.tsx
More file actions
176 lines (167 loc) · 5.7 KB
/
ModelTransferJobTableRow.tsx
File metadata and controls
176 lines (167 loc) · 5.7 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
165
166
167
168
169
170
171
172
173
174
175
176
import { Button, Content, Flex, FlexItem, Label, Truncate } from '@patternfly/react-core';
import { ActionsColumn, Td, Tr } from '@patternfly/react-table';
import {
CheckCircleIcon,
ExclamationCircleIcon,
InProgressIcon,
PendingIcon,
BanIcon,
} from '@patternfly/react-icons';
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import ModelTimestamp from '~/app/pages/modelRegistry/screens/components/ModelTimestamp';
import { ModelRegistrySelectorContext } from '~/app/context/ModelRegistrySelectorContext';
import { registeredModelUrl, modelVersionUrl } from '~/app/pages/modelRegistry/screens/routeUtils';
import { ModelTransferJob, ModelTransferJobStatus } from '~/app/types';
import { EMPTY_CUSTOM_PROPERTY_VALUE } from '~/concepts/modelCatalog/const';
import ModelTransferJobStatusModal from './ModelTransferJobStatusModal';
type ModelTransferJobTableRowProps = {
job: ModelTransferJob;
onRequestDelete?: (job: ModelTransferJob) => void;
onRequestRetry?: (job: ModelTransferJob) => void;
};
export const getStatusLabel = (
status: ModelTransferJobStatus,
): {
label: string;
color?: React.ComponentProps<typeof Label>['color'];
status?: React.ComponentProps<typeof Label>['status'];
icon: React.ReactNode;
} => {
switch (status) {
case ModelTransferJobStatus.COMPLETED:
return { label: 'Complete', status: 'success', icon: <CheckCircleIcon /> };
case ModelTransferJobStatus.RUNNING:
return { label: 'Running', color: 'blue', icon: <InProgressIcon /> };
case ModelTransferJobStatus.PENDING:
return { label: 'Pending', color: 'purple', icon: <PendingIcon /> };
case ModelTransferJobStatus.FAILED:
return { label: 'Failed', status: 'danger', icon: <ExclamationCircleIcon /> };
case ModelTransferJobStatus.CANCELLED:
return { label: 'Canceled', color: 'grey', icon: <BanIcon /> };
default:
return { label: status, color: 'grey', icon: null };
}
};
const ModelTransferJobTableRow: React.FC<ModelTransferJobTableRowProps> = ({
job,
onRequestDelete,
onRequestRetry,
}) => {
const navigate = useNavigate();
const { preferredModelRegistry } = React.useContext(ModelRegistrySelectorContext);
const [isStatusModalOpen, setIsStatusModalOpen] = React.useState(false);
const handleModelNameClick = () => {
if (job.registeredModelId) {
navigate(registeredModelUrl(job.registeredModelId, preferredModelRegistry?.name));
}
};
const handleVersionNameClick = () => {
if (job.modelVersionId && job.registeredModelId) {
navigate(
modelVersionUrl(job.modelVersionId, job.registeredModelId, preferredModelRegistry?.name),
);
}
};
const statusInfo = getStatusLabel(job.status);
// Actions menu - just Delete (retry is handled via button in status column)
const actions = React.useMemo(
() => [
{
title: 'Delete',
onClick: () => {
onRequestDelete?.(job);
},
},
],
[job, onRequestDelete],
);
return (
<Tr>
<Td dataLabel="Job name">
<div data-testid="job-name">
<Truncate content={job.jobDisplayName || job.name} />
</div>
</Td>
<Td dataLabel="Model name">
{job.registeredModelName ? (
job.registeredModelId ? (
<Button variant="link" isInline onClick={handleModelNameClick}>
<Truncate content={job.registeredModelName} />
</Button>
) : (
<Truncate content={job.registeredModelName} />
)
) : (
EMPTY_CUSTOM_PROPERTY_VALUE
)}
</Td>
<Td dataLabel="Model version name">
{job.modelVersionName ? (
job.registeredModelId && job.modelVersionId ? (
<Button variant="link" isInline onClick={handleVersionNameClick}>
<Truncate content={job.modelVersionName} />
</Button>
) : (
<Truncate content={job.modelVersionName} />
)
) : (
EMPTY_CUSTOM_PROPERTY_VALUE
)}
</Td>
<Td dataLabel="Namespace">
<Content component="p" data-testid="job-namespace">
{job.namespace || EMPTY_CUSTOM_PROPERTY_VALUE}
</Content>
</Td>
<Td dataLabel="Created">
<ModelTimestamp timeSinceEpoch={job.createTimeSinceEpoch} />
</Td>
<Td dataLabel="Author">
<Content component="p" data-testid="job-author">
{job.author || EMPTY_CUSTOM_PROPERTY_VALUE}
</Content>
</Td>
<Td dataLabel="Transfer job status">
<Flex alignItems={{ default: 'alignItemsCenter' }} spaceItems={{ default: 'spaceItemsSm' }}>
<FlexItem>
<Label
color={statusInfo.color}
status={statusInfo.status}
icon={statusInfo.icon}
data-testid="job-status"
variant="filled"
isClickable
onClick={() => setIsStatusModalOpen(true)}
>
{statusInfo.label}
</Label>
</FlexItem>
{job.status === ModelTransferJobStatus.FAILED && onRequestRetry && (
<FlexItem>
<Button
variant="link"
isInline
onClick={() => onRequestRetry(job)}
data-testid="job-retry-button"
>
Retry
</Button>
</FlexItem>
)}
</Flex>
</Td>
<Td isActionCell>
<ActionsColumn items={actions} />
</Td>
{isStatusModalOpen && (
<ModelTransferJobStatusModal
job={job}
isOpen={isStatusModalOpen}
onClose={() => setIsStatusModalOpen(false)}
/>
)}
</Tr>
);
};
export default ModelTransferJobTableRow;