debian-mirror-gitlab/app/assets/javascripts/members/components/members_tabs.vue

136 lines
3.8 KiB
Vue
Raw Normal View History

2021-06-08 01:23:25 +05:30
<script>
2021-10-27 15:23:28 +05:30
import { GlTabs, GlTab, GlBadge, GlButton } from '@gitlab/ui';
2021-06-08 01:23:25 +05:30
import { mapState } from 'vuex';
2021-10-27 15:23:28 +05:30
import { queryToObject } 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
},
],
2021-10-27 15:23:28 +05:30
components: { MembersApp, GlTabs, GlTab, GlBadge, GlButton },
inject: ['canManageMembers', 'canExportMembers', 'exportCsvPath'],
2021-06-08 01:23:25 +05:30
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-10-27 15:23:28 +05:30
return Object.keys(queryToObject(window.location.search, { gatherArrays: true }));
2021-06-08 01:23:25 +05:30
},
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>
2021-10-27 15:23:28 +05:30
<template #tabs-end>
<gl-button
v-if="canExportMembers"
class="gl-align-self-center gl-ml-auto"
icon="export"
:href="exportCsvPath"
>
{{ __('Export as CSV') }}
</gl-button>
</template>
2021-06-08 01:23:25 +05:30
</gl-tabs>
</template>