2022-09-07 05:12:12 -04:00
|
|
|
<script>
|
2022-10-04 17:08:34 -04:00
|
|
|
import { GlTabs, GlTab, GlSearchBoxByType, GlSorting, GlSortingItem } from '@gitlab/ui';
|
|
|
|
import { isString, debounce } from 'lodash';
|
2022-09-07 05:12:12 -04:00
|
|
|
import { __ } from '~/locale';
|
2022-10-18 17:09:37 -04:00
|
|
|
import { DEBOUNCE_DELAY } from '~/vue_shared/components/filtered_search_bar/constants';
|
2022-09-07 05:12:12 -04:00
|
|
|
import GroupsStore from '../store/groups_store';
|
|
|
|
import GroupsService from '../service/groups_service';
|
|
|
|
import {
|
|
|
|
ACTIVE_TAB_SUBGROUPS_AND_PROJECTS,
|
|
|
|
ACTIVE_TAB_SHARED,
|
|
|
|
ACTIVE_TAB_ARCHIVED,
|
2022-10-04 17:08:34 -04:00
|
|
|
OVERVIEW_TABS_SORTING_ITEMS,
|
2022-09-07 05:12:12 -04:00
|
|
|
} from '../constants';
|
2022-10-04 17:08:34 -04:00
|
|
|
import eventHub from '../event_hub';
|
2022-09-07 05:12:12 -04:00
|
|
|
import GroupsApp from './app.vue';
|
|
|
|
|
2022-10-04 17:08:34 -04:00
|
|
|
const [SORTING_ITEM_NAME] = OVERVIEW_TABS_SORTING_ITEMS;
|
2022-10-31 08:11:25 -04:00
|
|
|
const MIN_SEARCH_LENGTH = 3;
|
2022-10-04 17:08:34 -04:00
|
|
|
|
2022-09-07 05:12:12 -04:00
|
|
|
export default {
|
2022-10-04 17:08:34 -04:00
|
|
|
components: { GlTabs, GlTab, GroupsApp, GlSearchBoxByType, GlSorting, GlSortingItem },
|
|
|
|
inject: ['endpoints', 'initialSort'],
|
2022-09-07 05:12:12 -04:00
|
|
|
data() {
|
2022-10-18 08:09:21 -04:00
|
|
|
const tabs = [
|
|
|
|
{
|
|
|
|
title: this.$options.i18n[ACTIVE_TAB_SUBGROUPS_AND_PROJECTS],
|
|
|
|
key: ACTIVE_TAB_SUBGROUPS_AND_PROJECTS,
|
|
|
|
renderEmptyState: true,
|
|
|
|
lazy: this.$route.name !== ACTIVE_TAB_SUBGROUPS_AND_PROJECTS,
|
|
|
|
service: new GroupsService(this.endpoints[ACTIVE_TAB_SUBGROUPS_AND_PROJECTS]),
|
|
|
|
store: new GroupsStore({ showSchemaMarkup: true }),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: this.$options.i18n[ACTIVE_TAB_SHARED],
|
|
|
|
key: ACTIVE_TAB_SHARED,
|
|
|
|
renderEmptyState: false,
|
|
|
|
lazy: this.$route.name !== ACTIVE_TAB_SHARED,
|
|
|
|
service: new GroupsService(this.endpoints[ACTIVE_TAB_SHARED]),
|
|
|
|
store: new GroupsStore(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: this.$options.i18n[ACTIVE_TAB_ARCHIVED],
|
|
|
|
key: ACTIVE_TAB_ARCHIVED,
|
|
|
|
renderEmptyState: false,
|
|
|
|
lazy: this.$route.name !== ACTIVE_TAB_ARCHIVED,
|
|
|
|
service: new GroupsService(this.endpoints[ACTIVE_TAB_ARCHIVED]),
|
|
|
|
store: new GroupsStore(),
|
|
|
|
},
|
|
|
|
];
|
2022-09-07 05:12:12 -04:00
|
|
|
return {
|
2022-10-18 08:09:21 -04:00
|
|
|
tabs,
|
|
|
|
activeTabIndex: tabs.findIndex((tab) => tab.key === this.$route.name),
|
2022-10-04 17:08:34 -04:00
|
|
|
sort: SORTING_ITEM_NAME,
|
|
|
|
isAscending: true,
|
|
|
|
search: '',
|
2022-09-07 05:12:12 -04:00
|
|
|
};
|
|
|
|
},
|
2022-10-04 17:08:34 -04:00
|
|
|
computed: {
|
|
|
|
activeTab() {
|
|
|
|
return this.tabs[this.activeTabIndex];
|
|
|
|
},
|
|
|
|
sortQueryStringValue() {
|
|
|
|
return this.isAscending ? this.sort.asc : this.sort.desc;
|
|
|
|
},
|
|
|
|
},
|
2022-09-12 20:10:14 -04:00
|
|
|
mounted() {
|
2022-10-04 17:08:34 -04:00
|
|
|
this.search = this.$route.query?.filter || '';
|
|
|
|
|
|
|
|
const sortQueryStringValue = this.$route.query?.sort || this.initialSort;
|
|
|
|
const sort =
|
|
|
|
OVERVIEW_TABS_SORTING_ITEMS.find((sortOption) =>
|
|
|
|
[sortOption.asc, sortOption.desc].includes(sortQueryStringValue),
|
|
|
|
) || SORTING_ITEM_NAME;
|
|
|
|
this.sort = sort;
|
|
|
|
this.isAscending = sort.asc === sortQueryStringValue;
|
2022-09-12 20:10:14 -04:00
|
|
|
},
|
2022-09-07 05:12:12 -04:00
|
|
|
methods: {
|
|
|
|
handleTabInput(tabIndex) {
|
2022-09-12 20:10:14 -04:00
|
|
|
if (tabIndex === this.activeTabIndex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-07 05:12:12 -04:00
|
|
|
this.activeTabIndex = tabIndex;
|
|
|
|
|
|
|
|
const tab = this.tabs[tabIndex];
|
|
|
|
tab.lazy = false;
|
2022-09-12 20:10:14 -04:00
|
|
|
|
|
|
|
// Vue router will convert `/` to `%2F` if you pass a string as a param
|
|
|
|
// If you pass an array as a param it will concatenate them with a `/`
|
|
|
|
// This makes sure we are always passing an array for the group param
|
|
|
|
const groupParam = isString(this.$route.params.group)
|
|
|
|
? this.$route.params.group.split('/')
|
|
|
|
: this.$route.params.group;
|
|
|
|
|
2022-10-04 17:08:34 -04:00
|
|
|
this.$router.push({ name: tab.key, params: { group: groupParam }, query: this.$route.query });
|
|
|
|
},
|
|
|
|
handleSearchOrSortChange() {
|
|
|
|
// Update query string
|
|
|
|
const query = {};
|
|
|
|
if (this.sortQueryStringValue !== this.initialSort) {
|
|
|
|
query.sort = this.isAscending ? this.sort.asc : this.sort.desc;
|
|
|
|
}
|
|
|
|
if (this.search) {
|
|
|
|
query.filter = this.search;
|
|
|
|
}
|
|
|
|
this.$router.push({ query });
|
|
|
|
|
|
|
|
// Reset `lazy` prop so that groups/projects are fetched with updated `sort` and `filter` params when switching tabs
|
|
|
|
this.tabs.forEach((tab, index) => {
|
|
|
|
if (index === this.activeTabIndex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
tab.lazy = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update data
|
|
|
|
eventHub.$emit(`${this.activeTab.key}fetchFilteredAndSortedGroups`, {
|
|
|
|
filterGroupsBy: this.search,
|
|
|
|
sortBy: this.sortQueryStringValue,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleSortDirectionChange() {
|
|
|
|
this.isAscending = !this.isAscending;
|
|
|
|
|
|
|
|
this.handleSearchOrSortChange();
|
|
|
|
},
|
|
|
|
handleSortingItemClick(sortingItem) {
|
|
|
|
if (sortingItem === this.sort) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sort = sortingItem;
|
|
|
|
|
|
|
|
this.handleSearchOrSortChange();
|
2022-09-07 05:12:12 -04:00
|
|
|
},
|
2022-10-18 17:09:37 -04:00
|
|
|
handleSearchInput(value) {
|
|
|
|
this.search = value;
|
|
|
|
|
2022-10-31 08:11:25 -04:00
|
|
|
if (!this.search || this.search.length >= MIN_SEARCH_LENGTH) {
|
|
|
|
this.debouncedSearch();
|
|
|
|
}
|
2022-10-18 17:09:37 -04:00
|
|
|
},
|
|
|
|
debouncedSearch: debounce(async function debouncedSearch() {
|
|
|
|
this.handleSearchOrSortChange();
|
|
|
|
}, DEBOUNCE_DELAY),
|
2022-09-07 05:12:12 -04:00
|
|
|
},
|
|
|
|
i18n: {
|
2022-09-12 20:10:14 -04:00
|
|
|
[ACTIVE_TAB_SUBGROUPS_AND_PROJECTS]: __('Subgroups and projects'),
|
|
|
|
[ACTIVE_TAB_SHARED]: __('Shared projects'),
|
|
|
|
[ACTIVE_TAB_ARCHIVED]: __('Archived projects'),
|
2022-10-04 17:08:34 -04:00
|
|
|
searchPlaceholder: __('Search'),
|
2022-09-07 05:12:12 -04:00
|
|
|
},
|
2022-10-04 17:08:34 -04:00
|
|
|
OVERVIEW_TABS_SORTING_ITEMS,
|
2022-09-07 05:12:12 -04:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<gl-tabs content-class="gl-pt-0" :value="activeTabIndex" @input="handleTabInput">
|
|
|
|
<gl-tab
|
|
|
|
v-for="{ key, title, renderEmptyState, lazy, service, store } in tabs"
|
|
|
|
:key="key"
|
|
|
|
:title="title"
|
|
|
|
:lazy="lazy"
|
|
|
|
>
|
|
|
|
<groups-app
|
|
|
|
:action="key"
|
|
|
|
:service="service"
|
|
|
|
:store="store"
|
|
|
|
:hide-projects="false"
|
|
|
|
:render-empty-state="renderEmptyState"
|
|
|
|
/>
|
|
|
|
</gl-tab>
|
2022-10-04 17:08:34 -04:00
|
|
|
<template #tabs-end>
|
|
|
|
<li class="gl-flex-grow-1 gl-align-self-center gl-w-full gl-lg-w-auto gl-py-2">
|
|
|
|
<div class="gl-lg-display-flex gl-justify-content-end gl-mx-n2 gl-my-n2">
|
|
|
|
<div class="gl-p-2 gl-lg-form-input-md gl-w-full">
|
|
|
|
<gl-search-box-by-type
|
2022-10-18 17:09:37 -04:00
|
|
|
:value="search"
|
2022-10-04 17:08:34 -04:00
|
|
|
:placeholder="$options.i18n.searchPlaceholder"
|
|
|
|
data-qa-selector="groups_filter_field"
|
2022-10-18 17:09:37 -04:00
|
|
|
@input="handleSearchInput"
|
2022-10-04 17:08:34 -04:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="gl-p-2 gl-w-full gl-lg-w-auto">
|
|
|
|
<gl-sorting
|
|
|
|
class="gl-w-full"
|
|
|
|
dropdown-class="gl-w-full"
|
|
|
|
data-testid="group_sort_by_dropdown"
|
|
|
|
:text="sort.label"
|
|
|
|
:is-ascending="isAscending"
|
|
|
|
@sortDirectionChange="handleSortDirectionChange"
|
|
|
|
>
|
|
|
|
<gl-sorting-item
|
|
|
|
v-for="sortingItem in $options.OVERVIEW_TABS_SORTING_ITEMS"
|
|
|
|
:key="sortingItem.label"
|
|
|
|
:active="sortingItem === sort"
|
|
|
|
@click="handleSortingItemClick(sortingItem)"
|
|
|
|
>{{ sortingItem.label }}</gl-sorting-item
|
|
|
|
>
|
|
|
|
</gl-sorting>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</template>
|
2022-09-07 05:12:12 -04:00
|
|
|
</gl-tabs>
|
|
|
|
</template>
|