Skip to content

Commit d2d91a0

Browse files
committed
User editor: groups are added on save
1 parent c7a84c2 commit d2d91a0

File tree

3 files changed

+170
-100
lines changed

3 files changed

+170
-100
lines changed

src/lib/common/slim_select.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/lib/components/v1/jobs/JobsList.svelte

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import { removeDuplicatedItems } from '$lib/common/component_utilities';
1212
import StandardDismissableAlert from '../../common/StandardDismissableAlert.svelte';
1313
import TimestampCell from '../../jobs/TimestampCell.svelte';
14-
import { setSlimSelect, setSlimSelectOptions } from '$lib/common/slim_select';
14+
import SlimSelect from 'slim-select';
1515
1616
/** @type {() => Promise<import('$lib/types').ApplyWorkflow[]>} */
1717
export let jobUpdater;
@@ -44,15 +44,15 @@
4444
let rows = tableHandler.getRows();
4545
4646
// Selectors
47-
/** @type {import('slim-select').default|undefined} */
47+
/** @type {SlimSelect|undefined} */
4848
let statusSelect;
49-
/** @type {import('slim-select').default|undefined} */
49+
/** @type {SlimSelect|undefined} */
5050
let projectSelect;
51-
/** @type {import('slim-select').default|undefined} */
51+
/** @type {SlimSelect|undefined} */
5252
let workflowSelect;
53-
/** @type {import('slim-select').default|undefined} */
53+
/** @type {SlimSelect|undefined} */
5454
let inputDatasetSelect;
55-
/** @type {import('slim-select').default|undefined} */
55+
/** @type {SlimSelect|undefined} */
5656
let outputDatasetSelect;
5757
5858
// Filters
@@ -206,6 +206,44 @@
206206
);
207207
});
208208
209+
/**
210+
* Initializes slim-select dropdown on a given HTML element.
211+
* @param {string} id id of HTML element where slim-select has to be configured
212+
* @param {Array<{ name: string, id: number|string }>} values
213+
* @param {(value: string) => void} setter function executed when a dropdown value is selected
214+
* @param {boolean} showSearch
215+
* @returns the SlimSelect instance
216+
*/
217+
function setSlimSelect(id, values, setter, showSearch = true) {
218+
if (!values) {
219+
return;
220+
}
221+
const selectElement = document.getElementById(id);
222+
if (!selectElement) {
223+
return;
224+
}
225+
selectElement.classList.remove('invisible');
226+
const select = new SlimSelect({
227+
select: `#${id}`,
228+
settings: {
229+
showSearch,
230+
allowDeselect: true
231+
},
232+
events: {
233+
afterChange: (selection) => {
234+
const selectedOption = selection[0];
235+
if (!selectedOption || selectedOption.placeholder) {
236+
setter('');
237+
} else {
238+
setter(selectedOption.value);
239+
}
240+
}
241+
}
242+
});
243+
setSlimSelectOptions(select, values);
244+
return select;
245+
}
246+
209247
/**
210248
* Rebuilds valid slim-select options according to the visible rows.
211249
* Example: if a project filter is selected the user can select only the workflows belonging to that project.
@@ -229,7 +267,7 @@
229267
/**
230268
* Updates the available options only when needed, to avoid unsetting the selected value when the desired list of
231269
* options is already set (e.g. if we change the selected dataset we don't want to change the selected workflow).
232-
* @param {import('slim-select').default|undefined} select
270+
* @param {SlimSelect|undefined} select
233271
* @param {{id: number, name: string}[]} validValues
234272
*/
235273
function setValidSlimSelectOptions(select, validValues) {
@@ -242,6 +280,19 @@
242280
}
243281
}
244282
283+
/**
284+
* Updates SlimSelect options. This rebuilds the HTML elements and unset the selected value.
285+
* @param {SlimSelect|undefined} select
286+
* @param {Array<{ name: string, id: number|string }>} values
287+
*/
288+
function setSlimSelectOptions(select, values) {
289+
if (!select) {
290+
return;
291+
}
292+
const options = values.map((p) => ({ text: p.name, value: p.id.toString() }));
293+
select.setData([{ text: 'All', placeholder: true }, ...options]);
294+
}
295+
245296
onDestroy(() => {
246297
clearTimeout(updateJobsTimeout);
247298
});

0 commit comments

Comments
 (0)