debian-mirror-gitlab/app/assets/javascripts/crm/contacts/components/contacts_root.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

149 lines
4 KiB
Vue
Raw Normal View History

2021-12-11 22:18:48 +05:30
<script>
2022-01-26 12:08:38 +05:30
import { GlAlert, GlButton, GlLoadingIcon, GlTable, GlTooltipDirective } from '@gitlab/ui';
import { parseBoolean } from '~/lib/utils/common_utils';
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';
import { EDIT_ROUTE_NAME, NEW_ROUTE_NAME } from '../../constants';
import getGroupContactsQuery from './graphql/get_group_contacts.query.graphql';
2021-12-11 22:18:48 +05:30
export default {
components: {
2022-01-26 12:08:38 +05:30
GlAlert,
GlButton,
2021-12-11 22:18:48 +05:30
GlLoadingIcon,
GlTable,
},
2022-01-26 12:08:38 +05:30
directives: {
GlTooltip: GlTooltipDirective,
},
2022-06-21 17:19:12 +05:30
inject: ['canAdminCrmContact', 'groupFullPath', 'groupIssuesPath'],
2021-12-11 22:18:48 +05:30
data() {
2022-01-26 12:08:38 +05:30
return {
contacts: [],
error: false,
};
2021-12-11 22:18:48 +05:30
},
apollo: {
contacts: {
query() {
return getGroupContactsQuery;
},
variables() {
return {
groupFullPath: this.groupFullPath,
};
},
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
},
},
},
computed: {
isLoading() {
return this.$apollo.queries.contacts.loading;
},
2022-01-26 12:08:38 +05:30
canAdmin() {
return parseBoolean(this.canAdminCrmContact);
},
2021-12-11 22:18:48 +05:30
},
methods: {
extractContacts(data) {
const contacts = data?.group?.contacts?.nodes || [];
return contacts.slice().sort((a, b) => a.firstName.localeCompare(b.firstName));
},
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
},
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'),
errorText: __('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,
2021-12-11 22:18:48 +05:30
};
</script>
<template>
<div>
2022-01-26 12:08:38 +05:30
<gl-alert v-if="error" variant="danger" class="gl-mt-6" @dismiss="error = false">
{{ $options.i18n.errorText }}
</gl-alert>
<div
class="gl-display-flex gl-align-items-baseline gl-flex-direction-row gl-justify-content-space-between gl-mt-6"
>
<h2 class="gl-font-size-h2 gl-my-0">
{{ $options.i18n.title }}
</h2>
2022-06-21 17:19:12 +05:30
<div v-if="canAdmin">
<router-link :to="{ name: $options.NEW_ROUTE_NAME }">
<gl-button variant="confirm" data-testid="new-contact-button">
{{ $options.i18n.newContact }}
</gl-button>
</router-link>
2022-01-26 12:08:38 +05:30
</div>
</div>
2022-06-21 17:19:12 +05:30
<router-view />
2021-12-11 22:18:48 +05:30
<gl-loading-icon v-if="isLoading" class="gl-mt-5" size="lg" />
<gl-table
v-else
2022-01-26 12:08:38 +05:30
class="gl-mt-5"
2021-12-11 22:18:48 +05:30
:items="contacts"
:fields="$options.fields"
:empty-text="$options.i18n.emptyText"
show-empty
2022-01-26 12:08:38 +05:30
>
2022-06-21 17:19:12 +05:30
<template #cell(id)="{ value: id }">
2022-01-26 12:08:38 +05:30
<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"
2022-06-21 17:19:12 +05:30
:href="getIssuesPath(groupIssuesPath, id)"
2022-01-26 12:08:38 +05:30
/>
2022-06-21 17:19:12 +05:30
<router-link :to="getEditRoute(id)">
<gl-button
v-if="canAdmin"
v-gl-tooltip.hover.bottom="$options.i18n.editButtonLabel"
data-testid="edit-contact-button"
icon="pencil"
:aria-label="$options.i18n.editButtonLabel"
/>
</router-link>
2022-01-26 12:08:38 +05:30
</template>
</gl-table>
2021-12-11 22:18:48 +05:30
</div>
</template>