Add ability to choose only one filter in group

This commit is contained in:
Angelina Filippova 2019-03-25 01:04:37 +03:00
parent 3c0768868b
commit b8b7e4b021

View file

@ -1,5 +1,12 @@
<template> <template>
<el-select v-model="value" placeholder="Select filter"> <el-select
v-model="value"
:collapse-tags="isMobile"
multiple
placeholder="Select filter"
class="select-field"
@change="handleFilterToggle"
@remove-tag="handleFilterToggle">
<el-option-group <el-option-group
v-for="group in filters" v-for="group in filters"
:key="group.label" :key="group.label"
@ -20,24 +27,57 @@ export default {
filters: [{ filters: [{
label: 'By user type', label: 'By user type',
options: [{ options: [{
label: 'Show local', label: 'Local',
value: 'showLocal' value: 'userType/showLocalUsersOnly'
}, { }, {
label: 'Show external', label: 'External',
value: 'showExternal' value: 'userType/showExternalUsersOnly'
}] }]
}, { }, {
label: 'By status', label: 'By status',
options: [{ options: [{
label: 'Show Active', label: 'Active',
value: 'showActive' value: 'userStatus/showActiveUsersOnly'
}, { }, {
label: 'Show Deactivated', label: 'Deactivated',
value: 'showDeactivated' value: 'userStatus/showDeactivatedUsersOnly'
}] }]
}], }],
value: '' value: []
}
},
computed: {
isMobile() {
return this.$store.state.app.device === 'mobile'
}
},
methods: {
handleFilterToggle(value) {
const reversed = value.reverse()
const userTypeFilter = reversed.find(filter => filter.includes('userType'))
const userStatusFilter = reversed.find(filter => filter.includes('userStatus'))
const filters = [userTypeFilter, userStatusFilter].filter(item => item)
this.$data.value = filters
const filtersWithoutGroupnames = filters.reduce((acc, item) => {
const filter = item.split('/')[1]
acc.push(filter)
return acc
}, [])
this.$store.dispatch('ToggleUsersFilter', filtersWithoutGroupnames)
} }
} }
} }
</script> </script>
<style rel='stylesheet/scss' lang='scss' scoped>
.select-field {
width: 350px;
}
@media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
.select-field {
width: 48%;
}
}
</style>