Refactor filters

This commit is contained in:
Angelina Filippova 2020-10-25 02:09:38 +03:00
parent c4c547c0e5
commit 9e3dc60373
3 changed files with 10 additions and 37 deletions

View file

@ -32,14 +32,7 @@ const users = {
currentPage: 1,
pageSize: 50,
actorTypeFilters: [],
filters: {
local: false,
external: false,
active: false,
need_approval: false,
deactivated: false,
unconfirmed: false
},
filters: [],
passwordResetToken: {
token: '',
link: ''
@ -153,14 +146,7 @@ const users = {
},
ClearUsersState({ commit }) {
commit('SET_SEARCH_QUERY', '')
commit('SET_USERS_FILTERS',
{ local: false,
external: false,
active: false,
need_approval: false,
deactivated: false,
unconfirmed: false
})
commit('SET_USERS_FILTERS', [])
},
async ClearFilters({ commit, dispatch, state }) {
commit('CLEAR_USERS_FILTERS')
@ -251,7 +237,7 @@ const users = {
},
async FetchUsers({ commit, dispatch, getters, state }, { page }) {
commit('SET_LOADING', true)
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
const filters = state.filters.join()
const response = await fetchUsers(filters, state.actorTypeFilters, getters.authHost, getters.token, page)
await dispatch('GetNodeInfo')
loadUsers(commit, page, response.data)
@ -302,7 +288,7 @@ const users = {
commit('SET_LOADING', true)
commit('SET_SEARCH_QUERY', query)
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
const filters = state.filters.join()
const response = await searchUsers(query, filters, state.actorTypeFilters, getters.authHost, getters.token, page)
loadUsers(commit, page, response.data)
@ -319,16 +305,7 @@ const users = {
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
},
async ToggleUsersFilter({ commit, dispatch, state }, filters) {
const defaultFilters = {
local: false,
external: false,
active: false,
need_approval: false,
deactivated: false,
unconfirmed: false
}
const currentFilters = { ...defaultFilters, ...filters }
commit('SET_USERS_FILTERS', currentFilters)
commit('SET_USERS_FILTERS', filters)
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
},
async UpdateActorType({ dispatch, getters }, { user, type, _userId, _statusId }) {

View file

@ -37,12 +37,10 @@ export default {
}
},
created() {
const currentFilters = this.$data.value.reduce((acc, filter) => ({ ...acc, [filter]: true }), {})
this.$store.dispatch('ToggleUsersFilter', currentFilters)
this.$store.dispatch('ToggleUsersFilter', this.$data.value)
},
methods: {
removeOppositeFilters() {
const filtersQuantity = Object.keys(this.$store.state.users.filters).length
const currentFilters = []
const indexOfLocal = this.$data.value.indexOf('local')
const indexOfExternal = this.$data.value.indexOf('external')
@ -54,10 +52,6 @@ export default {
const indexOfService = this.$data.value.indexOf('Service')
const indexOfApplication = this.$data.value.indexOf('Application')
if (this.$data.value.length === filtersQuantity) {
return []
}
Math.max(indexOfLocal, indexOfExternal) > -1
? currentFilters.push(this.$data.value[Math.max(indexOfLocal, indexOfExternal)])
: currentFilters
@ -84,8 +78,7 @@ export default {
const [allFilters, filters, actorTypeFilters] = this.removeOppositeFilters()
this.$data.value = allFilters
const currentFilters = filters.reduce((acc, filter) => ({ ...acc, [filter]: true }), {})
this.$store.dispatch('ToggleUsersFilter', currentFilters)
this.$store.dispatch('ToggleUsersFilter', filters)
this.$store.dispatch('ToggleActorTypeFilter', actorTypeFilters)
}
}

View file

@ -249,6 +249,9 @@ export default {
usersCount() {
return this.$store.state.users.totalUsersCount
},
pendingView() {
return this.$store.state.users.filters.includes('need_approval')
},
width() {
return this.isMobile ? 55 : false
}