2021-06-08 01:23:25 +05:30
|
|
|
<script>
|
|
|
|
import { GlTabs, GlTab, GlBadge } from '@gitlab/ui';
|
|
|
|
import { mapState } from 'vuex';
|
2021-09-30 23:02:18 +05:30
|
|
|
// eslint-disable-next-line import/no-deprecated
|
|
|
|
import { urlParamsToObject } from '~/lib/utils/url_utility';
|
2021-06-08 01:23:25 +05:30
|
|
|
import { __ } from '~/locale';
|
2021-09-30 23:02:18 +05:30
|
|
|
import { MEMBER_TYPES, TAB_QUERY_PARAM_VALUES, ACTIVE_TAB_QUERY_PARAM_NAME } from '../constants';
|
2021-06-08 01:23:25 +05:30
|
|
|
import MembersApp from './app.vue';
|
|
|
|
|
|
|
|
const countComputed = (state, namespace) => state[namespace]?.pagination?.totalItems || 0;
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'MembersTabs',
|
2021-09-30 23:02:18 +05:30
|
|
|
ACTIVE_TAB_QUERY_PARAM_NAME,
|
|
|
|
TABS: [
|
2021-06-08 01:23:25 +05:30
|
|
|
{
|
|
|
|
namespace: MEMBER_TYPES.user,
|
|
|
|
title: __('Members'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
namespace: MEMBER_TYPES.group,
|
|
|
|
title: __('Groups'),
|
|
|
|
attrs: { 'data-qa-selector': 'groups_list_tab' },
|
2021-09-30 23:02:18 +05:30
|
|
|
queryParamValue: TAB_QUERY_PARAM_VALUES.group,
|
2021-06-08 01:23:25 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
namespace: MEMBER_TYPES.invite,
|
|
|
|
title: __('Invited'),
|
|
|
|
canManageMembersPermissionsRequired: true,
|
2021-09-30 23:02:18 +05:30
|
|
|
queryParamValue: TAB_QUERY_PARAM_VALUES.invite,
|
2021-06-08 01:23:25 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
namespace: MEMBER_TYPES.accessRequest,
|
|
|
|
title: __('Access requests'),
|
|
|
|
canManageMembersPermissionsRequired: true,
|
2021-09-30 23:02:18 +05:30
|
|
|
queryParamValue: TAB_QUERY_PARAM_VALUES.accessRequest,
|
2021-06-08 01:23:25 +05:30
|
|
|
},
|
|
|
|
],
|
|
|
|
components: { MembersApp, GlTabs, GlTab, GlBadge },
|
|
|
|
inject: ['canManageMembers'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedTabIndex: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
userCount(state) {
|
|
|
|
return countComputed(state, MEMBER_TYPES.user);
|
|
|
|
},
|
|
|
|
groupCount(state) {
|
|
|
|
return countComputed(state, MEMBER_TYPES.group);
|
|
|
|
},
|
|
|
|
inviteCount(state) {
|
|
|
|
return countComputed(state, MEMBER_TYPES.invite);
|
|
|
|
},
|
|
|
|
accessRequestCount(state) {
|
|
|
|
return countComputed(state, MEMBER_TYPES.accessRequest);
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
urlParams() {
|
2021-09-30 23:02:18 +05:30
|
|
|
// eslint-disable-next-line import/no-deprecated
|
2021-06-08 01:23:25 +05:30
|
|
|
return Object.keys(urlParamsToObject(window.location.search));
|
|
|
|
},
|
|
|
|
activeTabIndexCalculatedFromUrlParams() {
|
2021-09-30 23:02:18 +05:30
|
|
|
return this.$options.TABS.findIndex(({ namespace }) => {
|
2021-06-08 01:23:25 +05:30
|
|
|
return this.getTabUrlParams(namespace).some((urlParam) =>
|
|
|
|
this.urlParams.includes(urlParam),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getTabUrlParams(namespace) {
|
|
|
|
const state = this.$store.state[namespace];
|
|
|
|
const urlParams = [];
|
|
|
|
|
|
|
|
if (state?.filteredSearchBar?.searchParam) {
|
|
|
|
urlParams.push(state.filteredSearchBar.searchParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return urlParams;
|
|
|
|
},
|
|
|
|
getTabCount({ namespace }) {
|
|
|
|
return this[`${namespace}Count`];
|
|
|
|
},
|
|
|
|
showTab(tab, index) {
|
|
|
|
if (tab.namespace === MEMBER_TYPES.user) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { canManageMembersPermissionsRequired = false } = tab;
|
|
|
|
const tabCanBeShown =
|
|
|
|
this.getTabCount(tab) > 0 || this.activeTabIndexCalculatedFromUrlParams === index;
|
|
|
|
|
|
|
|
if (canManageMembersPermissionsRequired) {
|
|
|
|
return this.canManageMembers && tabCanBeShown;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tabCanBeShown;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2021-09-30 23:02:18 +05:30
|
|
|
<gl-tabs
|
|
|
|
v-model="selectedTabIndex"
|
|
|
|
sync-active-tab-with-query-params
|
|
|
|
:query-param-name="$options.ACTIVE_TAB_QUERY_PARAM_NAME"
|
|
|
|
>
|
|
|
|
<template v-for="(tab, index) in $options.TABS">
|
|
|
|
<gl-tab
|
|
|
|
v-if="showTab(tab, index)"
|
|
|
|
:key="tab.namespace"
|
|
|
|
:title-link-attributes="tab.attrs"
|
|
|
|
:query-param-value="tab.queryParamValue"
|
|
|
|
>
|
|
|
|
<template #title>
|
2021-06-08 01:23:25 +05:30
|
|
|
<span>{{ tab.title }}</span>
|
|
|
|
<gl-badge size="sm" class="gl-tab-counter-badge">{{ getTabCount(tab) }}</gl-badge>
|
|
|
|
</template>
|
2021-09-30 23:02:18 +05:30
|
|
|
<members-app :namespace="tab.namespace" :tab-query-param-value="tab.queryParamValue" />
|
2021-06-08 01:23:25 +05:30
|
|
|
</gl-tab>
|
|
|
|
</template>
|
|
|
|
</gl-tabs>
|
|
|
|
</template>
|