Skip to content

Commit 6c1a266

Browse files
committed
Displayed Zarr URLs in unit status modal
1 parent 18ea0e5 commit 6c1a266

File tree

1 file changed

+75
-17
lines changed

1 file changed

+75
-17
lines changed

src/lib/components/jobs/RunStatusModal.svelte

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@
2929
/** @type {(import('fractal-components/types/api').Pagination<import('fractal-components/types/api').HistoryUnit>)|undefined} */
3030
let data = undefined;
3131
32+
/** @type {import('fractal-components/types/api').HistoryUnit|undefined} */
33+
let selectedUnit = undefined;
34+
3235
let loadingLogs = false;
33-
/** @type {number|undefined} */
34-
let selectedLogUnit = undefined;
3536
/** @type {Array<{text: string, highlight: boolean}>} */
3637
let logParts = [];
3738
let loadedLogsStatus = '';
3839
40+
let showLogs = false;
41+
let showZarrUrls = false;
42+
3943
let statusFilter = '';
4044
/** @type {SlimSelect|undefined} */
4145
let statusFilterSelector = undefined;
@@ -60,6 +64,9 @@
6064
datasetId = _datasetId;
6165
workflowTaskId = _workflowTaskId;
6266
historyRunIndex = _historyRunIndex;
67+
selectedUnit = undefined;
68+
showLogs = false;
69+
showZarrUrls = false;
6370
data = undefined;
6471
page = 1;
6572
pageSize = 10;
@@ -101,14 +108,13 @@
101108
}
102109
103110
/**
104-
* @param {number} unitId
105-
* @param {string} status
111+
* @param {import('fractal-components/types/api').HistoryUnit} unit
106112
*/
107-
async function loadLogs(unitId, status) {
113+
async function loadLogs(unit) {
108114
unsetStatusFilterSelector();
109115
loadingLogs = true;
110116
const response = await fetch(
111-
`/api/v2/project/${projectId}/status/unit-log?history_run_id=${historyRunId}&history_unit_id=${unitId}&workflowtask_id=${workflowTaskId}&dataset_id=${datasetId}`,
117+
`/api/v2/project/${projectId}/status/unit-log?history_run_id=${historyRunId}&history_unit_id=${unit.id}&workflowtask_id=${workflowTaskId}&dataset_id=${datasetId}`,
112118
{
113119
method: 'GET'
114120
}
@@ -119,18 +125,32 @@
119125
return;
120126
}
121127
const log = await response.json();
122-
loadedLogsStatus = status;
123-
if (status === 'failed') {
128+
loadedLogsStatus = unit.status;
129+
if (unit.status === 'failed') {
124130
logParts = extractJobErrorParts(log, false, true);
125131
} else {
126132
logParts = [{ text: log, highlight: false }];
127133
}
128-
selectedLogUnit = unitId;
134+
selectedUnit = unit;
129135
loadingLogs = false;
136+
showLogs = true;
137+
}
138+
139+
/**
140+
* @param {import('fractal-components/types/api').HistoryUnit} unit
141+
*/
142+
async function displayZarrUrls(unit) {
143+
unsetStatusFilterSelector();
144+
showZarrUrls = true;
145+
selectedUnit = unit;
146+
await tick();
147+
restoreModalFocus();
130148
}
131149
132150
async function back() {
133-
selectedLogUnit = undefined;
151+
showZarrUrls = false;
152+
showLogs = false;
153+
selectedUnit = undefined;
134154
await tick();
135155
setStatusFilterSelector();
136156
}
@@ -181,13 +201,25 @@
181201
page = 1;
182202
await loadRun(page, pageSize);
183203
}
204+
205+
/**
206+
* Restore focus on modal, otherwise it will not be possible to close it using the esc key
207+
*/
208+
function restoreModalFocus() {
209+
const modal = document.querySelector('.modal.show');
210+
if (modal instanceof HTMLElement) {
211+
modal.focus();
212+
}
213+
}
184214
</script>
185215
186216
<Modal id="runStatusModal" bind:this={modal} fullscreen={true} bodyCss="p-0" {onClose}>
187217
<svelte:fragment slot="header">
188218
<h1 class="modal-title fs-5">
189-
{#if selectedLogUnit && !loadingLogs}
190-
Run {historyRunIndex} - Logs for unit #{selectedLogUnit}
219+
{#if showLogs && !loadingLogs}
220+
Run {historyRunIndex} - Logs for unit #{selectedUnit?.id}
221+
{:else if showZarrUrls}
222+
Run {historyRunIndex} - Zarr URLs for unit #{selectedUnit?.id}
191223
{:else}
192224
Run {historyRunIndex}
193225
{/if}
@@ -197,7 +229,7 @@
197229
<div id="errorAlert-runStatusModal" class="mb-2" />
198230
{#if loading && !data}
199231
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" />
200-
{:else if selectedLogUnit && !loadingLogs}
232+
{:else if showLogs && !loadingLogs}
201233
<div class="row">
202234
<div class="col">
203235
<ExpandableLog bind:logParts highlight={loadedLogsStatus === 'failed'} />
@@ -208,6 +240,25 @@
208240
<button class="m-2 ms-3 btn btn-primary" on:click={back}> Back </button>
209241
</div>
210242
</div>
243+
{:else if showZarrUrls && selectedUnit}
244+
<div class="row">
245+
<div class="col">
246+
<table class="table table-striped">
247+
<tbody>
248+
{#each selectedUnit.zarr_urls as zarrUrl}
249+
<tr>
250+
<td>{zarrUrl}</td>
251+
</tr>
252+
{/each}
253+
</tbody>
254+
</table>
255+
</div>
256+
</div>
257+
<div class="row">
258+
<div class="col">
259+
<button class="m-2 ms-3 btn btn-primary" on:click={back}> Back </button>
260+
</div>
261+
</div>
211262
{:else if data}
212263
<table class="table table-striped">
213264
<colgroup>
@@ -230,12 +281,16 @@
230281
</tr>
231282
</thead>
232283
<tbody>
233-
{#each data.items as run}
284+
{#each data.items as unit}
234285
<tr>
235-
<td>{run.id}</td>
236-
<td>{run.status || '-'}</td>
286+
<td>{unit.id}</td>
287+
<td>{unit.status || '-'}</td>
237288
<td>
238-
<button class="btn btn-light" on:click={() => loadLogs(run.id, run.status)}>
289+
<button
290+
class="btn btn-light me-2"
291+
on:click={() => loadLogs(unit)}
292+
disabled={loadingLogs}
293+
>
239294
{#if loadingLogs}
240295
<span
241296
class="spinner-border spinner-border-sm"
@@ -245,6 +300,9 @@
245300
{/if}
246301
<i class="bi-list-columns-reverse" /> Logs
247302
</button>
303+
<button class="btn btn-light" on:click={() => displayZarrUrls(unit)}>
304+
<i class="bi bi-list-task" /> Zarr URLs
305+
</button>
248306
</td>
249307
</tr>
250308
{/each}

0 commit comments

Comments
 (0)