Skip to content
Snippets Groups Projects

Change admin users search filter

6 files
+ 174
35
Compare changes
  • Side-by-side
  • Inline
Files
6
<script>
import { GlFilteredSearch, GlFilteredSearchToken } from '@gitlab/ui';
import { s__, __ } from '~/locale';
import { setUrlParams, visitUrl } from '~/lib/utils/url_utility';
import { OPERATORS_IS } from '~/vue_shared/components/filtered_search_bar/constants';
export const ADMIN_FILTER_TYPES = {
@@ -26,15 +27,18 @@ export default {
filterValue: [],
availableTokens: [
{
title: s__('AdminUsers|Access level'),
title: s__('AdminUsers|access level'),
type: 'admins',
token: GlFilteredSearchToken,
operators: OPERATORS_IS,
unique: true,
options: [{ value: ADMIN_FILTER_TYPES.Admins, title: s__('AdminUsers|Administrator') }],
options: [
{ value: ADMIN_FILTER_TYPES.Admins, title: s__('AdminUsers|Administrator') },
{ value: ADMIN_FILTER_TYPES.External, title: s__('AdminUsers|External') },
],
},
{
title: s__('AdminUsers|Two-factor Authentication'),
title: s__('AdminUsers|two-factor authentication'),
type: '2fa',
token: GlFilteredSearchToken,
operators: OPERATORS_IS,
@@ -45,13 +49,12 @@ export default {
],
},
{
title: __('Status'),
type: 'status',
title: __('state'),
type: 'state',
token: GlFilteredSearchToken,
operators: OPERATORS_IS,
unique: true,
options: [
{ value: ADMIN_FILTER_TYPES.External, title: s__('AdminUsers|External') },
{ value: ADMIN_FILTER_TYPES.Blocked, title: s__('AdminUsers|Blocked') },
{ value: ADMIN_FILTER_TYPES.Banned, title: s__('AdminUsers|Banned') },
{
@@ -84,9 +87,6 @@ export default {
return this.availableTokens;
},
isAdminTab() {
return this.$route.query.filter === ADMIN_FILTER_TYPES.Admins;
},
},
created() {
if (this.$route.query.filter) {
@@ -111,20 +111,18 @@ export default {
},
methods: {
handleSearch(filters) {
const newUrl = new URL(window.location);
newUrl.searchParams.delete('page');
newUrl.searchParams.delete('filter');
newUrl.searchParams.delete('search_query');
const newParams = {};
filters?.forEach((filter) => {
if (typeof filter === 'string') {
newUrl.searchParams.set('search_query', filter);
newParams.search_query = filter;
} else {
newUrl.searchParams.set('filter', filter.value.data);
newParams.filter = filter.value.data;
}
});
window.location = newUrl;
const newUrl = setUrlParams(newParams, window.location.href, true);
visitUrl(newUrl);
},
},
};
@@ -133,9 +131,10 @@ export default {
<template>
<gl-filtered-search
v-model="filterValue"
class="gl-mb-4"
:placeholder="s__('AdminUsers|Search by name, email, or username')"
:available-tokens="filteredAvailableTokens"
class="gl-mb-4"
terms-as-tokens
@submit="handleSearch"
/>
</template>
Loading