forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstates.ts
More file actions
246 lines (232 loc) · 8.23 KB
/
states.ts
File metadata and controls
246 lines (232 loc) · 8.23 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import {
faClock,
faCloud,
faExclamationTriangle,
faLock,
faPause,
faSpinner,
type IconDefinition,
} from "@fortawesome/free-solid-svg-icons";
import type { DCESummary, HDADetailed, HDCADetailed } from "@/api";
import { ERROR_DATASET_STATES, NON_TERMINAL_DATASET_STATES } from "@/api/datasets";
import type { HistoryContentsResult } from "@/api/histories";
import type { components } from "@/api/schema";
import { DatasetStateSummary } from "../Collection/DatasetStateSummary";
type HistoryContentItem = HistoryContentsResult[number];
function isHDCAItem(item: HistoryContentItem | HDADetailed | HDCADetailed | DCESummary): boolean {
return (
item &&
typeof item === "object" &&
"history_content_type" in item &&
item.history_content_type === "dataset_collection"
);
}
function isDCEWithCollection(item: HistoryContentItem | HDADetailed | HDCADetailed | DCESummary): boolean {
return item && typeof item === "object" && "collection_type" in item && item.collection_type !== undefined;
}
type DatasetState = components["schemas"]["DatasetState"];
// The 'failed' state is for the collection job state summary, not a dataset state.
export type State =
| DatasetState
| "failed"
| "placeholder"
| "failed_populated_state"
| "new_populated_state"
| "inaccessible";
interface StateRepresentation {
status: "success" | "warning" | "info" | "danger" | "secondary";
text?: string;
displayName?: string;
icon?: IconDefinition;
spin?: boolean;
nonDb?: boolean;
}
export type StateMap = {
[__ in State]: StateRepresentation;
};
/**
* Client representation of state and state messages.
* See: https://github.com/galaxyproject/galaxy/blob/dev/lib/galaxy/model/__init__.py#L3292 for a list of available states.
*/
export const STATES: StateMap = {
/** has successfully completed running */
ok: {
status: "success",
displayName: "ok",
},
/** has no data */
empty: {
status: "success",
text: "No data.",
displayName: "empty",
},
/** was created without a tool */
new: {
status: "warning",
text: "This is a new dataset and not all of its data are available yet.",
displayName: "new",
icon: faClock,
},
/** the job that will produce the dataset queued in the runner */
queued: {
status: "warning",
text: "This job is waiting to run.",
displayName: "queued",
icon: faClock,
},
/** the job that will produce the dataset is running */
running: {
status: "warning",
text: "This job is currently running.",
displayName: "running",
icon: faSpinner,
spin: true,
},
/** metadata for the dataset is being discovered/set */
setting_metadata: {
status: "warning",
text: "Metadata is being auto-detected.",
displayName: "setting metadata",
icon: faSpinner,
spin: true,
},
/** is uploading and not ready */
upload: {
status: "warning",
text: "This dataset is currently uploading.",
displayName: "uploading",
icon: faSpinner,
spin: true,
},
/** remote dataset */
deferred: {
status: "info",
text: "This dataset is remote, has not been ingested by Galaxy, and full metadata may not be available.",
displayName: "deferred",
icon: faCloud,
},
/** the job that will produce the dataset paused */
paused: {
status: "info",
text: "This job is paused. Use the 'Resume Paused Jobs' in the history menu to resume.",
displayName: "paused",
icon: faPause,
},
/** deleted while uploading */
discarded: {
status: "danger",
text: "This dataset is discarded - the job creating it may have been cancelled or it may have been imported without file data.",
displayName: "discarded",
icon: faExclamationTriangle,
},
/** the tool producing this dataset has errored */
error: {
status: "danger",
text: "An error occurred with this dataset.",
displayName: "error",
icon: faExclamationTriangle,
},
/** metadata discovery/setting failed or errored (but otherwise ok) */
failed_metadata: {
status: "danger",
text: "Metadata generation failed. Please retry.",
displayName: "failed metadata",
icon: faExclamationTriangle,
},
/** the job has failed, this is not a dataset but a job state used in the collection job state summary. */
failed: {
status: "danger",
displayName: "failed",
icon: faExclamationTriangle,
},
/** the dataset is not yet loaded in the UI. This state is only visual and transitional, it does not exist in the database. */
placeholder: {
status: "secondary",
text: "This dataset is being fetched.",
displayName: "loading",
icon: faSpinner,
spin: true,
nonDb: true,
},
/** the `populated_state: failed`. This state is only visual and transitional, it does not exist in the database. */
failed_populated_state: {
status: "danger",
text: "Failed to populate the collection.",
displayName: "failed",
icon: faExclamationTriangle,
nonDb: true,
},
/** the `populated_state: new`. This state is only visual and transitional, it does not exist in the database. */
new_populated_state: {
status: "warning",
text: "This is a new collection and not all of its data are available yet.",
displayName: "new",
icon: faClock,
nonDb: true,
},
inaccessible: {
status: "warning",
text: "User not allowed to access this dataset.",
displayName: "inaccessible",
icon: faLock,
nonDb: true,
},
} as const satisfies StateMap;
/** We want to display a single state for a dataset collection whose elements may have mixed states.
* This list is ordered from highest to lowest priority. If any element is in error state the whole collection should be in error.
*/
export const HIERARCHICAL_COLLECTION_JOB_STATES = [
"error",
"failed",
"upload",
"paused",
"running",
"queued",
"new",
] as const;
/** Similar hierarchy for dataset states, ordered from highest to lowest priority. */
export const HIERARCHICAL_COLLECTION_DATASET_STATES = [
...(ERROR_DATASET_STATES as readonly DatasetState[]),
...(NON_TERMINAL_DATASET_STATES as readonly DatasetState[]),
"deferred" as const,
"discarded" as const,
] as const satisfies readonly DatasetState[];
export function getContentItemState(item: HistoryContentItem | HDADetailed | HDCADetailed): State {
if (isHDCAItem(item) || isDCEWithCollection(item)) {
if ("populated_state" in item && item.populated_state === "failed") {
return "failed_populated_state";
}
if ("populated_state" in item && item.populated_state === "new") {
return "new_populated_state";
}
// Check dataset states first (higher priority for actual data states)
if ("elements_states" in item && item.elements_states) {
const datasetSummary = new DatasetStateSummary(
item as {
elements_states?: Record<string, number>;
elements_deleted?: number;
populated_state?: string | null;
},
);
for (const datasetState of HIERARCHICAL_COLLECTION_DATASET_STATES) {
if (datasetSummary.get(datasetState) > 0) {
return datasetState;
}
}
}
// Fall back to job states if no dataset states
if ("job_state_summary" in item && item.job_state_summary) {
const jobStateSummary = item.job_state_summary as Record<string, number>;
for (const jobState of HIERARCHICAL_COLLECTION_JOB_STATES) {
if ((jobStateSummary[jobState] || 0) > 0) {
return jobState;
}
}
}
} else if ("accessible" in item && item.accessible === false) {
return "inaccessible";
} else if ("state" in item && item.state) {
return item.state;
}
return "ok";
}