Skip to content

Commit 620e00c

Browse files
committed
Added warning sign on tasks having new versions available
1 parent 0fe6ee4 commit 620e00c

File tree

3 files changed

+71
-24
lines changed

3 files changed

+71
-24
lines changed

src/lib/components/workflow/VersionUpdate.svelte

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<script>
2-
import { greatestVersionAsc, greatestVersionDesc } from '$lib/common/component_utilities';
32
import { displayStandardErrorAlert } from '$lib/common/errors';
43
import { SchemaValidator } from '$lib/common/jschema_validation';
54
import { page } from '$app/stores';
65
import { stripSchemaProperties } from '../common/jschema/schema_management';
6+
import { getNewVersions } from './version-checker';
77
88
/** @type {import('$lib/types').WorkflowTask} */
99
export let workflowTask;
1010
1111
/** @type {(workflowTask: import('$lib/types').WorkflowTask) => void} */
1212
export let updateWorkflowCallback;
13-
/** @type {(count: number) => void} */
13+
/** @type {(count: number) => Promise<void>} */
1414
export let updateNewVersionsCount;
1515
1616
$: task = workflowTask.task;
@@ -46,30 +46,14 @@
4646
return;
4747
}
4848
49-
console.log('Checking for new versions');
50-
const response = await fetch('/api/v1/task');
51-
52-
if (!response.ok) {
53-
errorAlert = displayStandardErrorAlert(await response.json(), 'versionUpdateError');
49+
try {
50+
updateCandidates = await getNewVersions(task);
51+
} catch (error) {
52+
errorAlert = displayStandardErrorAlert(error, 'versionUpdateError');
5453
return;
5554
}
5655
57-
/** @type {import('$lib/types').Task[]} */
58-
const result = await response.json();
59-
60-
updateCandidates = result
61-
.filter((t) => {
62-
return (
63-
t.name === task.name &&
64-
t.owner === task.owner &&
65-
t.version &&
66-
t.args_schema &&
67-
greatestVersionAsc(t, task) === 1
68-
);
69-
})
70-
.sort(greatestVersionDesc);
71-
72-
updateNewVersionsCount(updateCandidates.length);
56+
await updateNewVersionsCount(updateCandidates.length);
7357
}
7458
7559
function checkArgumentsWithNewSchema() {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { greatestVersionAsc, greatestVersionDesc } from '$lib/common/component_utilities';
2+
import { AlertError } from '$lib/common/errors';
3+
4+
/**
5+
* @param {import('$lib/types').Task} task
6+
* @returns {Promise<import('$lib/types').Task[]>} the list of update candidates for the given task
7+
*/
8+
export async function getNewVersions(task) {
9+
const updateCandidates = await getAllNewVersions([task]);
10+
return updateCandidates[task.id];
11+
}
12+
13+
/**
14+
* @param {import('$lib/types').Task[]} tasks
15+
* @returns {Promise<{ [id: string]: import('$lib/types').Task[] }>} the list of update candidates, for each task received as input
16+
*/
17+
export async function getAllNewVersions(tasks) {
18+
console.log('Checking for new versions');
19+
const response = await fetch('/api/v1/task');
20+
21+
if (!response.ok) {
22+
throw new AlertError(await response.json());
23+
}
24+
25+
/** @type {import('$lib/types').Task[]} */
26+
const result = await response.json();
27+
28+
return tasks.reduce(function (map, task) {
29+
map[task.id] = result
30+
.filter((t) => {
31+
return (
32+
task.args_schema !== null &&
33+
task.version !== null &&
34+
t.name === task.name &&
35+
t.owner === task.owner &&
36+
t.version &&
37+
t.args_schema &&
38+
greatestVersionAsc(t, task) === 1
39+
);
40+
})
41+
.sort(greatestVersionDesc);
42+
return map;
43+
}, {});
44+
}

src/routes/projects/[projectId]/workflows/[workflowId]/+page.svelte

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import Modal from '$lib/components/common/Modal.svelte';
1414
import StandardDismissableAlert from '$lib/components/common/StandardDismissableAlert.svelte';
1515
import VersionUpdate from '$lib/components/workflow/VersionUpdate.svelte';
16+
import { getAllNewVersions } from '$lib/components/workflow/version-checker';
1617
1718
// Workflow
1819
/** @type {import('$lib/types').Workflow|undefined} */
@@ -65,6 +66,9 @@
6566
/** @type {Modal} */
6667
let editWorkflowModal;
6768
69+
/** @type {{ [id: string]: import('$lib/types').Task[] }} */
70+
let newVersionsMap = {};
71+
6872
$: updatableWorkflowList = workflow?.task_list || [];
6973
7074
workflowTaskContext.subscribe((value) => {
@@ -81,6 +85,7 @@
8185
workflow = $page.data.workflow;
8286
project = $page.data.project;
8387
datasets = $page.data.datasets;
88+
checkNewVersions();
8489
});
8590
8691
beforeNavigate((navigation) => {
@@ -258,6 +263,7 @@
258263
// UI Feedback
259264
workflowSuccessMessage = 'Workflow task created';
260265
resetCreateWorkflowTaskModal();
266+
await checkNewVersions();
261267
});
262268
}
263269
@@ -498,14 +504,21 @@
498504
workflow = workflowResult;
499505
selectedWorkflowTask = workflowTask;
500506
workflowSuccessMessage = 'Task version updated successfully';
507+
await checkNewVersions();
508+
}
509+
510+
async function checkNewVersions() {
511+
if (workflow) {
512+
newVersionsMap = await getAllNewVersions(workflow.task_list.map((wt) => wt.task));
513+
}
501514
}
502515
503516
let newVersionsCount = 0;
504517
/**
505518
* Used to receive new version count from VersionUpdate component.
506519
* @param count {number}
507520
*/
508-
function updateNewVersionsCount(count) {
521+
async function updateNewVersionsCount(count) {
509522
newVersionsCount = count;
510523
}
511524
</script>
@@ -606,6 +619,12 @@
606619
on:keypress|preventDefault
607620
>
608621
{workflowTask.task.name} #{workflowTask.id}
622+
623+
{#if newVersionsMap[workflowTask.task.id]?.length > 0}
624+
<span class="float-end text-warning" title="new version available">
625+
<i class="bi bi-exclamation-triangle" />
626+
</span>
627+
{/if}
609628
</li>
610629
{/each}
611630
</ul>

0 commit comments

Comments
 (0)