2021-12-11 22:18:48 +05:30
|
|
|
<script>
|
2022-08-27 11:52:29 +05:30
|
|
|
import { GlButton, GlLoadingIcon, GlTable, GlTooltipDirective } from '@gitlab/ui';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { s__, __ } from '~/locale';
|
2022-06-21 17:19:12 +05:30
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
2022-08-27 11:52:29 +05:30
|
|
|
import PaginatedTableWithSearchAndTabs from '~/vue_shared/components/paginated_table_with_search_and_tabs/paginated_table_with_search_and_tabs.vue';
|
|
|
|
import {
|
|
|
|
bodyTrClass,
|
|
|
|
initialPaginationState,
|
|
|
|
} from '~/vue_shared/components/paginated_table_with_search_and_tabs/constants';
|
|
|
|
import { convertToSnakeCase } from '~/lib/utils/text_utility';
|
|
|
|
import { EDIT_ROUTE_NAME, NEW_ROUTE_NAME, trackViewsOptions } from '../../constants';
|
|
|
|
import getGroupContacts from './graphql/get_group_contacts.query.graphql';
|
|
|
|
import getGroupContactsCountByState from './graphql/get_group_contacts_count_by_state.graphql';
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2022-01-26 12:08:38 +05:30
|
|
|
GlButton,
|
2021-12-11 22:18:48 +05:30
|
|
|
GlLoadingIcon,
|
|
|
|
GlTable,
|
2022-08-27 11:52:29 +05:30
|
|
|
PaginatedTableWithSearchAndTabs,
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
2022-01-26 12:08:38 +05:30
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
2022-08-27 11:52:29 +05:30
|
|
|
inject: ['canAdminCrmContact', 'groupFullPath', 'groupIssuesPath', 'textQuery'],
|
2021-12-11 22:18:48 +05:30
|
|
|
data() {
|
2022-01-26 12:08:38 +05:30
|
|
|
return {
|
2022-08-27 11:52:29 +05:30
|
|
|
contacts: { list: [] },
|
|
|
|
contactsCount: {},
|
2022-01-26 12:08:38 +05:30
|
|
|
error: false,
|
2022-08-27 11:52:29 +05:30
|
|
|
filteredByStatus: '',
|
|
|
|
pagination: initialPaginationState,
|
|
|
|
statusFilter: 'all',
|
|
|
|
searchTerm: this.textQuery,
|
|
|
|
sort: 'LAST_NAME_ASC',
|
|
|
|
sortDesc: false,
|
2022-01-26 12:08:38 +05:30
|
|
|
};
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
contacts: {
|
2022-08-27 11:52:29 +05:30
|
|
|
query: getGroupContacts,
|
2021-12-11 22:18:48 +05:30
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
groupFullPath: this.groupFullPath,
|
2022-08-27 11:52:29 +05:30
|
|
|
searchTerm: this.searchTerm,
|
|
|
|
state: this.statusFilter,
|
|
|
|
sort: this.sort,
|
|
|
|
firstPageSize: this.pagination.firstPageSize,
|
|
|
|
lastPageSize: this.pagination.lastPageSize,
|
|
|
|
prevPageCursor: this.pagination.prevPageCursor,
|
|
|
|
nextPageCursor: this.pagination.nextPageCursor,
|
2021-12-11 22:18:48 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
update(data) {
|
|
|
|
return this.extractContacts(data);
|
|
|
|
},
|
2022-01-26 12:08:38 +05:30
|
|
|
error() {
|
|
|
|
this.error = true;
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
|
|
|
},
|
2022-08-27 11:52:29 +05:30
|
|
|
contactsCount: {
|
|
|
|
query: getGroupContactsCountByState,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
groupFullPath: this.groupFullPath,
|
|
|
|
searchTerm: this.searchTerm,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update(data) {
|
|
|
|
return data?.group?.contactStateCounts;
|
|
|
|
},
|
|
|
|
error() {
|
|
|
|
this.error = true;
|
|
|
|
},
|
|
|
|
},
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isLoading() {
|
|
|
|
return this.$apollo.queries.contacts.loading;
|
|
|
|
},
|
2022-08-27 11:52:29 +05:30
|
|
|
tbodyTrClass() {
|
|
|
|
return {
|
|
|
|
[bodyTrClass]: !this.loading && !this.isEmpty,
|
|
|
|
};
|
2022-01-26 12:08:38 +05:30
|
|
|
},
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
|
|
|
methods: {
|
2022-08-27 11:52:29 +05:30
|
|
|
errorAlertDismissed() {
|
2022-11-25 23:54:43 +05:30
|
|
|
this.error = false;
|
2022-08-27 11:52:29 +05:30
|
|
|
},
|
2021-12-11 22:18:48 +05:30
|
|
|
extractContacts(data) {
|
|
|
|
const contacts = data?.group?.contacts?.nodes || [];
|
2022-08-27 11:52:29 +05:30
|
|
|
const pageInfo = data?.group?.contacts?.pageInfo || {};
|
|
|
|
return {
|
|
|
|
list: contacts,
|
|
|
|
pageInfo,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
fetchSortedData({ sortBy, sortDesc }) {
|
|
|
|
const sortingColumn = convertToSnakeCase(sortBy).toUpperCase();
|
|
|
|
const sortingDirection = sortDesc ? 'DESC' : 'ASC';
|
|
|
|
this.pagination = initialPaginationState;
|
|
|
|
this.sort = `${sortingColumn}_${sortingDirection}`;
|
|
|
|
},
|
|
|
|
filtersChanged({ searchTerm }) {
|
|
|
|
this.searchTerm = searchTerm;
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
2022-01-26 12:08:38 +05:30
|
|
|
getIssuesPath(path, value) {
|
2022-07-16 23:28:13 +05:30
|
|
|
return `${path}?crm_contact_id=${value}`;
|
2022-01-26 12:08:38 +05:30
|
|
|
},
|
2022-06-21 17:19:12 +05:30
|
|
|
getEditRoute(id) {
|
|
|
|
return { name: this.$options.EDIT_ROUTE_NAME, params: { id } };
|
2022-01-26 12:08:38 +05:30
|
|
|
},
|
2022-08-27 11:52:29 +05:30
|
|
|
pageChanged(pagination) {
|
|
|
|
this.pagination = pagination;
|
|
|
|
},
|
|
|
|
statusChanged({ filters, status }) {
|
|
|
|
this.statusFilter = filters;
|
|
|
|
this.filteredByStatus = status;
|
|
|
|
},
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
|
|
|
fields: [
|
|
|
|
{ key: 'firstName', sortable: true },
|
|
|
|
{ key: 'lastName', sortable: true },
|
|
|
|
{ key: 'email', sortable: true },
|
|
|
|
{ key: 'phone', sortable: true },
|
|
|
|
{ key: 'description', sortable: true },
|
|
|
|
{
|
|
|
|
key: 'organization',
|
|
|
|
formatter: (organization) => {
|
|
|
|
return organization?.name;
|
|
|
|
},
|
|
|
|
sortable: true,
|
|
|
|
},
|
2022-01-26 12:08:38 +05:30
|
|
|
{
|
|
|
|
key: 'id',
|
|
|
|
label: '',
|
|
|
|
formatter: (id) => {
|
|
|
|
return getIdFromGraphQLId(id);
|
|
|
|
},
|
|
|
|
},
|
2021-12-11 22:18:48 +05:30
|
|
|
],
|
|
|
|
i18n: {
|
|
|
|
emptyText: s__('Crm|No contacts found'),
|
2022-01-26 12:08:38 +05:30
|
|
|
issuesButtonLabel: __('View issues'),
|
|
|
|
editButtonLabel: __('Edit'),
|
2022-06-21 17:19:12 +05:30
|
|
|
title: s__('Crm|Customer relations contacts'),
|
2022-01-26 12:08:38 +05:30
|
|
|
newContact: s__('Crm|New contact'),
|
2022-11-25 23:54:43 +05:30
|
|
|
errorMsg: __('Something went wrong. Please try again.'),
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
2022-06-21 17:19:12 +05:30
|
|
|
EDIT_ROUTE_NAME,
|
|
|
|
NEW_ROUTE_NAME,
|
2022-08-27 11:52:29 +05:30
|
|
|
statusTabs: [
|
|
|
|
{
|
|
|
|
title: __('Active'),
|
|
|
|
status: 'ACTIVE',
|
|
|
|
filters: 'active',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __('Inactive'),
|
|
|
|
status: 'INACTIVE',
|
|
|
|
filters: 'inactive',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __('All'),
|
|
|
|
status: 'ALL',
|
|
|
|
filters: 'all',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
trackViewsOptions,
|
|
|
|
emptyArray: [],
|
2021-12-11 22:18:48 +05:30
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
2022-08-27 11:52:29 +05:30
|
|
|
<paginated-table-with-search-and-tabs
|
|
|
|
:show-items="true"
|
2022-11-25 23:54:43 +05:30
|
|
|
:show-error-msg="error"
|
2022-08-27 11:52:29 +05:30
|
|
|
:i18n="$options.i18n"
|
|
|
|
:items="contacts.list"
|
|
|
|
:page-info="contacts.pageInfo"
|
|
|
|
:items-count="contactsCount"
|
|
|
|
:status-tabs="$options.statusTabs"
|
|
|
|
:track-views-options="$options.trackViewsOptions"
|
|
|
|
:filter-search-tokens="$options.emptyArray"
|
|
|
|
filter-search-key="contacts"
|
|
|
|
@page-changed="pageChanged"
|
|
|
|
@tabs-changed="statusChanged"
|
|
|
|
@filters-changed="filtersChanged"
|
|
|
|
@error-alert-dismissed="errorAlertDismissed"
|
2022-01-26 12:08:38 +05:30
|
|
|
>
|
2022-08-27 11:52:29 +05:30
|
|
|
<template #header-actions>
|
|
|
|
<router-link v-if="canAdminCrmContact" :to="{ name: $options.NEW_ROUTE_NAME }">
|
|
|
|
<gl-button class="gl-my-3 gl-mr-5" variant="confirm" data-testid="new-contact-button">
|
2022-06-21 17:19:12 +05:30
|
|
|
{{ $options.i18n.newContact }}
|
|
|
|
</gl-button>
|
|
|
|
</router-link>
|
2022-01-26 12:08:38 +05:30
|
|
|
</template>
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
<template #title>
|
|
|
|
{{ $options.i18n.title }}
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #table>
|
|
|
|
<gl-table
|
|
|
|
:items="contacts.list"
|
|
|
|
:fields="$options.fields"
|
|
|
|
:busy="isLoading"
|
|
|
|
stacked="md"
|
|
|
|
:tbody-tr-class="tbodyTrClass"
|
|
|
|
sort-direction="asc"
|
|
|
|
:sort-desc.sync="sortDesc"
|
|
|
|
sort-by="createdAt"
|
|
|
|
show-empty
|
|
|
|
no-local-sorting
|
|
|
|
sort-icon-left
|
|
|
|
fixed
|
|
|
|
@sort-changed="fetchSortedData"
|
|
|
|
>
|
|
|
|
<template #cell(id)="{ value: id }">
|
|
|
|
<gl-button
|
|
|
|
v-gl-tooltip.hover.bottom="$options.i18n.issuesButtonLabel"
|
|
|
|
class="gl-mr-3"
|
|
|
|
data-testid="issues-link"
|
|
|
|
icon="issues"
|
|
|
|
:aria-label="$options.i18n.issuesButtonLabel"
|
|
|
|
:href="getIssuesPath(groupIssuesPath, id)"
|
|
|
|
/>
|
|
|
|
<router-link :to="getEditRoute(id)">
|
|
|
|
<gl-button
|
|
|
|
v-if="canAdminCrmContact"
|
|
|
|
v-gl-tooltip.hover.bottom="$options.i18n.editButtonLabel"
|
|
|
|
data-testid="edit-contact-button"
|
|
|
|
icon="pencil"
|
|
|
|
:aria-label="$options.i18n.editButtonLabel"
|
|
|
|
/>
|
|
|
|
</router-link>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #table-busy>
|
|
|
|
<gl-loading-icon size="lg" color="dark" class="mt-3" />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #empty>
|
2022-11-25 23:54:43 +05:30
|
|
|
<span>
|
2022-08-27 11:52:29 +05:30
|
|
|
{{ $options.i18n.emptyText }}
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
</gl-table>
|
|
|
|
</template>
|
|
|
|
</paginated-table-with-search-and-tabs>
|
|
|
|
<router-view />
|
2021-12-11 22:18:48 +05:30
|
|
|
</div>
|
|
|
|
</template>
|