Skip to content
Snippets Groups Projects

Migrate GlDropdown to GlListbox in severity filter

Merged David Pisek requested to merge 409701-migrate-severity_filter-to-listbox into master
All threads resolved!
Compare and Show latest version
3 files
+ 28
43
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -22,6 +22,7 @@ export const FILTER_ITEMS = [
@@ -22,6 +22,7 @@ export const FILTER_ITEMS = [
...SEVERITY_LEVEL_ITEMS,
...SEVERITY_LEVEL_ITEMS,
];
];
 
//
const VALID_IDS = SEVERITY_LEVEL_ITEMS.map(({ id }) => id);
const VALID_IDS = SEVERITY_LEVEL_ITEMS.map(({ id }) => id);
export default {
export default {
@@ -31,39 +32,31 @@ export default {
@@ -31,39 +32,31 @@ export default {
}),
}),
computed: {
computed: {
toggleText() {
toggleText() {
return getSelectedOptionsText(this.listboxItems[0].options, this.selectedIds);
return getSelectedOptionsText(FILTER_ITEMS, this.selectedIds);
},
listboxItems() {
const optionsGroup = {
text: this.$options.i18n.label,
options: FILTER_ITEMS,
};
return [optionsGroup];
},
},
},
},
watch: {
watch: {
selectedIds: {
selectedIds: {
handler(selection = [], prevSelection = []) {
handler() {
const lastSelectedId = selection.at(-1);
this.$emit('filter-changed', {
const prevLastSelectedId = prevSelection.at(-1);
severity: this.selectedIds.filter((value) => value !== ALL_ID),
});
if (!prevSelection.length || lastSelectedId === prevLastSelectedId) {
return;
}
const shouldSelectAll = lastSelectedId === ALL_ID || selection.length === 0;
this.selectedIds = shouldSelectAll
? [ALL_ID]
: selection.filter((id) => VALID_IDS.includes(id));
this.$emit('filter-changed', { severity: shouldSelectAll ? [] : this.selectedIds });
},
},
},
},
},
},
 
methods: {
 
updateSelected(selected) {
 
if (!selected.length || selected.at(-1) === ALL_ID) {
 
this.selectedIds = [ALL_ID];
 
} else {
 
this.selectedIds = selected.filter((value) => value !== ALL_ID);
 
}
 
},
 
},
i18n: {
i18n: {
label: s__('SecurityReports|Severity'),
label: s__('SecurityReports|Severity'),
allItemsText: s__('SecurityReports|All severities'),
},
},
 
FILTER_ITEMS,
VALID_IDS,
VALID_IDS,
};
};
</script>
</script>
@@ -71,22 +64,21 @@ export default {
@@ -71,22 +64,21 @@ export default {
<template>
<template>
<div>
<div>
<querystring-sync
<querystring-sync
v-model="selectedIds"
:value="selectedIds"
querystring-key="severity"
querystring-key="severity"
:valid-values="$options.VALID_IDS"
:valid-values="$options.VALID_IDS"
 
@input="updateSelected"
/>
/>
<label class="gl-mb-2">{{ $options.i18n.label }}</label>
<label class="gl-mb-2">{{ $options.i18n.label }}</label>
<gl-collapsible-listbox
<gl-collapsible-listbox
v-model="selectedIds"
:header-text="$options.i18n.label"
:items="listboxItems"
:items="$options.FILTER_ITEMS"
 
:selected="selectedIds"
:toggle-text="toggleText"
:toggle-text="toggleText"
multiple
multiple
block
block
toggle-class="gl-mb-0"
toggle-class="gl-mb-0"
>
@select="updateSelected"
<template #list-item="{ item }">
/>
<span :data-testid="item.id">{{ item.text }}</span>
</template>
</gl-collapsible-listbox>
</div>
</div>
</template>
</template>
Loading