From ab12129b8aae446b94a27dba677c72ad6de58960 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 25 Mar 2019 15:55:39 +0300 Subject: [PATCH] Add ability to clear all filters --- src/store/modules/users.js | 18 +++++++++++++++--- src/views/users/components/UsersFilter.vue | 5 +++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/store/modules/users.js b/src/store/modules/users.js index c4b7ec21..d5a10d48 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -44,11 +44,19 @@ const users = { }, SET_USERS_FILTER: (state, filter) => { state.filters[filter] = !state.filters[filter] + }, + CLEAR_USERS_FILTERS: (state) => { + state.filters = { + showLocalUsersOnly: false, + showExternalUsersOnly: false, + showActiveUsersOnly: false, + showDeactivatedUsersOnly: false + } } }, actions: { async FetchUsers({ commit, state, getters }, { page }) { - const response = await fetchUsers(state.filters.showLocalUsersOnly, getters.authHost, getters.token, page) + const response = await fetchUsers(state.filters, getters.authHost, getters.token, page) commit('SET_LOADING', true) @@ -67,14 +75,18 @@ const users = { commit('SET_LOADING', true) commit('SET_SEARCH_QUERY', query) - const response = await searchUsers(query, state.filters.showLocalUsersOnly, getters.authHost, getters.token, page) + const response = await searchUsers(query, state.filters, getters.authHost, getters.token, page) loadUsers(commit, page, response.data) } }, async ToggleUsersFilter({ commit, dispatch, state }, filter) { commit('SET_USERS_FILTER', filter) - // dispatch('SearchUsers', { query: state.searchQuery, page: 1 }) + dispatch('SearchUsers', { query: state.searchQuery, page: 1 }) + }, + async ClearFilters({ commit, dispatch, state }) { + commit('CLEAR_USERS_FILTERS') + dispatch('SearchUsers', { query: state.searchQuery, page: 1 }) }, async ToggleRight({ commit, getters }, { user, right }) { user.roles[right] diff --git a/src/views/users/components/UsersFilter.vue b/src/views/users/components/UsersFilter.vue index 41e6b673..6da55b41 100644 --- a/src/views/users/components/UsersFilter.vue +++ b/src/views/users/components/UsersFilter.vue @@ -3,9 +3,11 @@ v-model="value" :collapse-tags="isMobile" multiple + clearable placeholder="Select filter" class="select-field" @change="handleFilterToggle" + @clear="clearFilters" @remove-tag="handleFilterToggle">