Skip to content

Commit a6af083

Browse files
committed
Changes to apply button status; added a check on workflow task input filters pending changes; fixed discard args chages issue
1 parent c4fa5e1 commit a6af083

File tree

7 files changed

+203
-71
lines changed

7 files changed

+203
-71
lines changed

src/lib/common/component_utilities.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,22 @@ export function downloadBlob(content, filename, contentType) {
250250
downloader.setAttribute('download', filename);
251251
downloader.click();
252252
}
253+
254+
/**
255+
* @param {{ [key: string]: null | string | number | boolean}} oldObject
256+
* @param {{ [key: string]: null | string | number | boolean}} newObject
257+
*/
258+
export function objectChanged(oldObject, newObject) {
259+
if (Object.keys(oldObject).length !== Object.keys(newObject).length) {
260+
return true;
261+
}
262+
for (const [oldKey, oldValue] of Object.entries(oldObject)) {
263+
if (!(oldKey in newObject)) {
264+
return true;
265+
}
266+
if (oldValue !== newObject[oldKey]) {
267+
return true;
268+
}
269+
}
270+
return false;
271+
}

src/lib/components/v1/workflow/ArgumentsSchema.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
validSchema = false;
6060
}
6161
}
62+
63+
$: {
64+
if (!unsavedChanges) {
65+
schemaComponent?.discardChanges(args);
66+
}
67+
}
6268
</script>
6369
6470
<div id="workflow-arguments-schema-panel">

src/lib/components/v2/projects/datasets/FiltersCreationForm.svelte

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<script>
2+
import { objectChanged } from '$lib/common/component_utilities';
23
import { tick } from 'svelte';
34
5+
/** @type {{ [key: string]: string | number | boolean }} */
6+
let initialAttributeFields = {};
7+
/** @type {{ [key: string]: boolean }} */
8+
let initialTypeFields = {};
9+
410
/** @type {Array<{ key: string, value: string, type: string, error: string }>} */
511
let attributeFields = [];
612
/** @type {Array<{ key: string, value: boolean, error: string }>} */
@@ -17,6 +23,44 @@
1723
typeFields = Object.entries(types).map(([k, v]) => {
1824
return { key: k, value: v, error: '' };
1925
});
26+
initialAttributeFields = getAttributes();
27+
initialTypeFields = getTypes();
28+
}
29+
30+
/**
31+
* @returns {boolean}
32+
*/
33+
export function hasUnsavedChanges() {
34+
return (
35+
objectChanged(initialAttributeFields, getAttributes()) ||
36+
objectChanged(initialTypeFields, getTypes())
37+
);
38+
}
39+
40+
export function discardChanges() {
41+
init(initialAttributeFields, initialTypeFields);
42+
}
43+
44+
export function save() {
45+
initialAttributeFields = getAttributes();
46+
initialTypeFields = getTypes();
47+
}
48+
49+
/**
50+
* @param {string} key
51+
* @param {string} value
52+
* @param {string} type
53+
*/
54+
export function importAttribute(key, value, type) {
55+
attributeFields = [...attributeFields, { key, value, type, error: '' }];
56+
}
57+
58+
/**
59+
* @param {string} key
60+
* @param {boolean} value
61+
*/
62+
export function importType(key, value) {
63+
typeFields = [...typeFields, { key, value, error: '' }];
2064
}
2165
2266
/**

src/lib/components/v2/workflow/InputFiltersTab.svelte

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
}
6969
}
7070
71-
async function save() {
71+
export async function save() {
7272
if (errorAlert) {
7373
errorAlert.hide();
7474
}
@@ -101,22 +101,33 @@
101101
setTimeout(() => {
102102
successfullySaved = false;
103103
}, 3000);
104+
form.save();
104105
updateWorkflowTaskCallback(await response.json());
105106
} else {
106107
errorAlert = displayStandardErrorAlert(await response.json(), `errorAlert-inputFilters`);
107108
}
108109
saving = false;
109110
}
110111
112+
/**
113+
* @returns {boolean}
114+
*/
115+
export function hasUnsavedChanges() {
116+
return form.hasUnsavedChanges();
117+
}
118+
119+
export function discard() {
120+
form.discardChanges();
121+
}
122+
111123
function onOpenAddDatasetAttributeModal() {
112124
selectedDatasetAttributeKey = '';
113125
selectedDatasetAttributeValue = '';
114126
}
115127
116128
function addDatasetAttribute() {
117-
const attributes = form.getAttributes();
118-
attributes[selectedDatasetAttributeKey] = selectedDatasetAttributeValue;
119-
form.init(attributes, form.getTypes());
129+
const attributeType = typeof datasetAttributes[selectedDatasetAttributeKey];
130+
form.importAttribute(selectedDatasetAttributeKey, selectedDatasetAttributeValue, attributeType);
120131
}
121132
122133
function onOpenAddDatasetTypeModal() {
@@ -125,9 +136,7 @@
125136
}
126137
127138
function addDatasetType() {
128-
const types = form.getTypes();
129-
types[selectedDatasetTypeKey] = selectedDatasetTypeValue;
130-
form.init(form.getAttributes(), types);
139+
form.importType(selectedDatasetTypeKey, selectedDatasetTypeValue);
131140
}
132141
</script>
133142

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@
9090
}
9191
});
9292
93+
/**
94+
* @param {number} id
95+
*/
96+
function setWorkflowTabContextId(id) {
97+
if (argumentsWithUnsavedChanges === true) {
98+
toggleUnsavedChangesModal();
99+
return;
100+
}
101+
workflowTabContextId = id;
102+
}
103+
93104
/**
94105
* Exports a project's workflow from the server
95106
* @returns {Promise<void>}
@@ -333,9 +344,12 @@
333344
}
334345
if (argumentsWithUnsavedChanges === true) {
335346
toggleUnsavedChangesModal();
336-
preventedTaskContextChange = wft;
347+
if (wft) {
348+
preventedTaskContextChange = wft;
349+
}
337350
throw new Error('Cannot change workflow task context while there are unsaved changes');
338351
}
352+
preventedTaskContextChange = undefined;
339353
setWorkflowTaskContext(wft);
340354
}
341355
@@ -347,6 +361,9 @@
347361
* @param {import('$lib/types').WorkflowTask} wft
348362
*/
349363
function setWorkflowTaskContext(wft) {
364+
if (!wft) {
365+
return;
366+
}
350367
selectedWorkflowTask = wft;
351368
// Check if args schema is available
352369
argsSchemaAvailable =
@@ -673,40 +690,32 @@
673690
<ul class="nav nav-tabs card-header-tabs">
674691
<li class="nav-item">
675692
<button
676-
data-bs-toggle="tab"
677-
data-bs-target="#args-tab"
678693
class="nav-link {workflowTabContextId === 0 ? 'active' : ''}"
679-
on:click={() => (workflowTabContextId = 0)}
694+
on:click={() => setWorkflowTabContextId(0)}
680695
aria-current={workflowTabContextId === 0}
681696
>Arguments
682697
</button>
683698
</li>
684699
<li class="nav-item">
685700
<button
686-
data-bs-toggle="tab"
687-
data-bs-target="#meta-tab"
688701
class="nav-link {workflowTabContextId === 1 ? 'active' : ''}"
689-
on:click={() => (workflowTabContextId = 1)}
702+
on:click={() => setWorkflowTabContextId(1)}
690703
aria-current={workflowTabContextId === 1}
691704
>Meta
692705
</button>
693706
</li>
694707
<li class="nav-item">
695708
<button
696-
data-bs-toggle="tab"
697-
data-bs-target="#info-tab"
698709
class="nav-link {workflowTabContextId === 2 ? 'active' : ''}"
699-
on:click={() => (workflowTabContextId = 2)}
710+
on:click={() => setWorkflowTabContextId(2)}
700711
aria-current={workflowTabContextId === 2}
701712
>Info
702713
</button>
703714
</li>
704715
<li class="nav-item">
705716
<button
706-
data-bs-toggle="tab"
707-
data-bs-target="#version-tab"
708717
class="nav-link {workflowTabContextId === 3 ? 'active' : ''}"
709-
on:click={() => (workflowTabContextId = 3)}
718+
on:click={() => setWorkflowTabContextId(3)}
710719
aria-current={workflowTabContextId === 3}
711720
>
712721
Version

src/routes/v2/projects/[projectId]/datasets/[datasetId]/+page.svelte

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import BooleanIcon from '$lib/components/common/BooleanIcon.svelte';
1111
import SlimSelect from 'slim-select';
1212
import { onMount, tick } from 'svelte';
13+
import { objectChanged } from '$lib/common/component_utilities';
1314
1415
let projectId = $page.params.projectId;
1516
@@ -152,27 +153,8 @@
152153
}
153154
154155
$: applyBtnActive =
155-
filtersChanged(lastAppliedAttributeFilters, attributeFilters) ||
156-
filtersChanged(lastAppliedTypeFilters, typeFilters);
157-
158-
/**
159-
* @param {{ [key: string]: null | string | number | boolean}} oldFilters
160-
* @param {{ [key: string]: null | string | number | boolean}} newFilters
161-
*/
162-
function filtersChanged(oldFilters, newFilters) {
163-
if (Object.keys(oldFilters).length !== Object.keys(newFilters).length) {
164-
return true;
165-
}
166-
for (const [oldKey, oldValue] of Object.entries(oldFilters)) {
167-
if (!(oldKey in newFilters)) {
168-
return true;
169-
}
170-
if (oldValue !== newFilters[oldKey]) {
171-
return true;
172-
}
173-
}
174-
return false;
175-
}
156+
objectChanged(lastAppliedAttributeFilters, attributeFilters) ||
157+
objectChanged(lastAppliedTypeFilters, typeFilters);
176158
177159
let resetBtnActive = false;
178160

0 commit comments

Comments
 (0)