debian-mirror-gitlab/app/assets/javascripts/error_tracking/components/error_tracking_list.vue

422 lines
12 KiB
Vue
Raw Normal View History

2019-02-15 15:39:39 +05:30
<script>
2020-01-01 13:55:28 +05:30
import { mapActions, mapState } from 'vuex';
2019-12-26 22:10:19 +05:30
import {
GlEmptyState,
2020-04-22 19:07:51 +05:30
GlDeprecatedButton,
2020-01-01 13:55:28 +05:30
GlIcon,
2019-12-26 22:10:19 +05:30
GlLink,
GlLoadingIcon,
GlTable,
2020-01-01 13:55:28 +05:30
GlFormInput,
GlDropdown,
GlDropdownItem,
GlDropdownDivider,
GlTooltipDirective,
GlPagination,
2019-12-26 22:10:19 +05:30
} from '@gitlab/ui';
2020-01-01 13:55:28 +05:30
import AccessorUtils from '~/lib/utils/accessor';
2019-02-15 15:39:39 +05:30
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
import { __ } from '~/locale';
2020-03-13 15:44:24 +05:30
import { isEmpty } from 'lodash';
2020-04-22 19:07:51 +05:30
import ErrorTrackingActions from './error_tracking_actions.vue';
2020-06-23 00:09:42 +05:30
import Tracking from '~/tracking';
import { trackErrorListViewsOptions, trackErrorStatusUpdateOptions } from '../utils';
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
export const tableDataClass = 'table-col d-flex d-md-table-cell align-items-center';
2019-02-15 15:39:39 +05:30
export default {
2020-01-01 13:55:28 +05:30
FIRST_PAGE: 1,
PREV_PAGE: 1,
NEXT_PAGE: 2,
2019-02-15 15:39:39 +05:30
fields: [
2020-03-13 15:44:24 +05:30
{
key: 'error',
label: __('Error'),
thClass: 'w-60p',
2020-04-08 14:13:33 +05:30
tdClass: `${tableDataClass} px-3 rounded-top`,
2020-03-13 15:44:24 +05:30
},
{
key: 'events',
label: __('Events'),
thClass: 'text-right',
tdClass: `${tableDataClass}`,
},
{
key: 'users',
label: __('Users'),
thClass: 'text-right',
tdClass: `${tableDataClass}`,
},
{
key: 'lastSeen',
label: __('Last seen'),
thClass: 'w-15p',
tdClass: `${tableDataClass}`,
},
{
key: 'status',
label: '',
2020-04-22 19:07:51 +05:30
tdClass: `${tableDataClass}`,
2020-03-13 15:44:24 +05:30
},
2019-02-15 15:39:39 +05:30
],
2020-04-08 14:13:33 +05:30
statusFilters: {
unresolved: __('Unresolved'),
ignored: __('Ignored'),
resolved: __('Resolved'),
},
2020-01-01 13:55:28 +05:30
sortFields: {
last_seen: __('Last Seen'),
first_seen: __('First Seen'),
frequency: __('Frequency'),
},
2019-02-15 15:39:39 +05:30
components: {
GlEmptyState,
2020-04-22 19:07:51 +05:30
GlDeprecatedButton,
2020-01-01 13:55:28 +05:30
GlDropdown,
GlDropdownItem,
GlDropdownDivider,
GlIcon,
2019-02-15 15:39:39 +05:30
GlLink,
GlLoadingIcon,
GlTable,
2020-01-01 13:55:28 +05:30
GlFormInput,
GlPagination,
2019-02-15 15:39:39 +05:30
TimeAgo,
2020-04-22 19:07:51 +05:30
ErrorTrackingActions,
2019-02-15 15:39:39 +05:30
},
2019-12-21 20:55:43 +05:30
directives: {
2020-01-01 13:55:28 +05:30
GlTooltip: GlTooltipDirective,
2019-12-21 20:55:43 +05:30
},
2019-02-15 15:39:39 +05:30
props: {
indexPath: {
type: String,
required: true,
},
enableErrorTrackingLink: {
type: String,
required: true,
},
errorTrackingEnabled: {
type: Boolean,
required: true,
},
illustrationPath: {
type: String,
required: true,
},
2019-12-04 20:38:33 +05:30
userCanEnableErrorTracking: {
type: Boolean,
required: true,
},
2020-03-13 15:44:24 +05:30
projectPath: {
type: String,
required: true,
},
listPath: {
type: String,
required: true,
},
2019-02-15 15:39:39 +05:30
},
2020-01-01 13:55:28 +05:30
hasLocalStorage: AccessorUtils.isLocalStorageAccessSafe(),
2019-12-26 22:10:19 +05:30
data() {
return {
errorSearchQuery: '',
2020-01-01 13:55:28 +05:30
pageValue: this.$options.FIRST_PAGE,
2019-12-26 22:10:19 +05:30
};
},
2019-02-15 15:39:39 +05:30
computed: {
2020-01-01 13:55:28 +05:30
...mapState('list', [
'errors',
'loading',
'searchQuery',
'sortField',
'recentSearches',
'pagination',
2020-04-08 14:13:33 +05:30
'statusFilter',
2020-03-13 15:44:24 +05:30
'cursor',
2020-01-01 13:55:28 +05:30
]),
paginationRequired() {
2020-03-13 15:44:24 +05:30
return !isEmpty(this.pagination);
2020-01-01 13:55:28 +05:30
},
},
watch: {
pagination() {
if (typeof this.pagination.previous === 'undefined') {
this.pageValue = this.$options.FIRST_PAGE;
}
2019-12-26 22:10:19 +05:30
},
2019-02-15 15:39:39 +05:30
},
created() {
if (this.errorTrackingEnabled) {
2020-01-01 13:55:28 +05:30
this.setEndpoint(this.indexPath);
this.startPolling();
2019-02-15 15:39:39 +05:30
}
},
2020-06-23 00:09:42 +05:30
mounted() {
this.trackPageViews();
},
2019-02-15 15:39:39 +05:30
methods: {
2020-01-01 13:55:28 +05:30
...mapActions('list', [
'startPolling',
'restartPolling',
'setEndpoint',
'searchByQuery',
'sortByField',
'addRecentSearch',
'clearRecentSearches',
'loadRecentSearches',
'setIndexPath',
2020-03-13 15:44:24 +05:30
'fetchPaginatedResults',
'updateStatus',
'removeIgnoredResolvedErrors',
2020-04-08 14:13:33 +05:30
'filterByStatus',
2020-01-01 13:55:28 +05:30
]),
setSearchText(text) {
this.errorSearchQuery = text;
this.searchByQuery(text);
},
getDetailsLink(errorId) {
return `error_tracking/${errorId}/details`;
},
goToNextPage() {
this.pageValue = this.$options.NEXT_PAGE;
2020-03-13 15:44:24 +05:30
this.fetchPaginatedResults(this.pagination.next.cursor);
2020-01-01 13:55:28 +05:30
},
goToPrevPage() {
2020-03-13 15:44:24 +05:30
this.fetchPaginatedResults(this.pagination.previous.cursor);
2020-01-01 13:55:28 +05:30
},
goToPage(page) {
window.scrollTo(0, 0);
return page === this.$options.PREV_PAGE ? this.goToPrevPage() : this.goToNextPage();
},
isCurrentSortField(field) {
return field === this.sortField;
2019-12-26 22:10:19 +05:30
},
2020-04-08 14:13:33 +05:30
isCurrentStatusFilter(filter) {
return filter === this.statusFilter;
},
2020-03-13 15:44:24 +05:30
getIssueUpdatePath(errorId) {
return `/${this.projectPath}/-/error_tracking/${errorId}.json`;
},
2020-04-08 14:13:33 +05:30
filterErrors(status, label) {
this.filterValue = label;
return this.filterByStatus(status);
},
2020-06-23 00:09:42 +05:30
updateErrosStatus({ errorId, status }) {
// eslint-disable-next-line promise/catch-or-return
2020-03-13 15:44:24 +05:30
this.updateStatus({
endpoint: this.getIssueUpdatePath(errorId),
status,
2020-06-23 00:09:42 +05:30
}).then(() => {
this.trackStatusUpdate(status);
2020-03-13 15:44:24 +05:30
});
2020-06-23 00:09:42 +05:30
2020-03-13 15:44:24 +05:30
this.removeIgnoredResolvedErrors(errorId);
},
2020-06-23 00:09:42 +05:30
trackPageViews() {
const { category, action } = trackErrorListViewsOptions;
Tracking.event(category, action);
},
trackStatusUpdate(status) {
const { category, action } = trackErrorStatusUpdateOptions(status);
Tracking.event(category, action);
},
2019-02-15 15:39:39 +05:30
},
};
</script>
<template>
2020-01-01 13:55:28 +05:30
<div class="error-list">
2019-02-15 15:39:39 +05:30
<div v-if="errorTrackingEnabled">
2020-04-22 19:07:51 +05:30
<div
class="row flex-column flex-md-row align-items-md-center m-0 mt-sm-2 p-3 p-sm-3 bg-secondary border"
>
<div class="search-box flex-fill mb-1 mb-md-0">
2020-03-13 15:44:24 +05:30
<div class="filtered-search-box mb-0">
<gl-dropdown
:text="__('Recent searches')"
class="filtered-search-history-dropdown-wrapper"
toggle-class="filtered-search-history-dropdown-toggle-button"
2020-01-01 13:55:28 +05:30
:disabled="loading"
>
2020-03-13 15:44:24 +05:30
<div v-if="!$options.hasLocalStorage" class="px-3">
{{ __('This feature requires local storage to be enabled') }}
</div>
<template v-else-if="recentSearches.length > 0">
<gl-dropdown-item
v-for="searchQuery in recentSearches"
:key="searchQuery"
@click="setSearchText(searchQuery)"
>{{ searchQuery }}
</gl-dropdown-item>
<gl-dropdown-divider />
<gl-dropdown-item ref="clearRecentSearches" @click="clearRecentSearches"
>{{ __('Clear recent searches') }}
</gl-dropdown-item>
</template>
<div v-else class="px-3">{{ __("You don't have any recent searches") }}</div>
</gl-dropdown>
<div class="filtered-search-input-container flex-fill">
<gl-form-input
v-model="errorSearchQuery"
class="pl-2 filtered-search"
:disabled="loading"
:placeholder="__('Search or filter results…')"
autofocus
@keyup.enter.native="searchByQuery(errorSearchQuery)"
/>
</div>
<div class="gl-search-box-by-type-right-icons">
2020-04-22 19:07:51 +05:30
<gl-deprecated-button
2020-03-13 15:44:24 +05:30
v-if="errorSearchQuery.length > 0"
v-gl-tooltip.hover
:title="__('Clear')"
class="clear-search text-secondary"
name="clear"
@click="errorSearchQuery = ''"
>
<gl-icon name="close" :size="12" />
2020-04-22 19:07:51 +05:30
</gl-deprecated-button>
2020-03-13 15:44:24 +05:30
</div>
2020-01-01 13:55:28 +05:30
</div>
2019-02-15 15:39:39 +05:30
</div>
2019-12-21 20:55:43 +05:30
2020-01-01 13:55:28 +05:30
<gl-dropdown
2020-04-08 14:13:33 +05:30
:text="$options.statusFilters[statusFilter]"
2020-04-22 19:07:51 +05:30
class="status-dropdown mx-md-1 mb-1 mb-md-0"
2020-04-08 14:13:33 +05:30
menu-class="dropdown"
:disabled="loading"
>
<gl-dropdown-item
v-for="(label, status) in $options.statusFilters"
:key="status"
@click="filterErrors(status, label)"
>
<span class="d-flex">
<gl-icon
class="flex-shrink-0 append-right-4"
:class="{ invisible: !isCurrentStatusFilter(status) }"
name="mobile-issue-close"
/>
{{ label }}
</span>
</gl-dropdown-item>
</gl-dropdown>
<gl-dropdown
2020-01-01 13:55:28 +05:30
:text="$options.sortFields[sortField]"
left
:disabled="loading"
2020-04-08 14:13:33 +05:30
menu-class="dropdown"
2019-12-26 22:10:19 +05:30
>
2020-01-01 13:55:28 +05:30
<gl-dropdown-item
v-for="(label, field) in $options.sortFields"
:key="field"
@click="sortByField(field)"
>
<span class="d-flex">
2020-04-08 14:13:33 +05:30
<gl-icon
2020-01-01 13:55:28 +05:30
class="flex-shrink-0 append-right-4"
:class="{ invisible: !isCurrentSortField(field) }"
name="mobile-issue-close"
/>
{{ label }}
</span>
</gl-dropdown-item>
</gl-dropdown>
</div>
2019-02-15 15:39:39 +05:30
2020-01-01 13:55:28 +05:30
<div v-if="loading" class="py-3">
<gl-loading-icon size="md" />
</div>
2019-02-15 15:39:39 +05:30
2020-03-13 15:44:24 +05:30
<template v-else>
2020-04-08 14:13:33 +05:30
<h4 class="d-block d-md-none my-3">{{ __('Open errors') }}</h4>
2019-02-15 15:39:39 +05:30
2020-03-13 15:44:24 +05:30
<gl-table
2020-04-08 14:13:33 +05:30
class="error-list-table mt-3"
2020-03-13 15:44:24 +05:30
:items="errors"
:fields="$options.fields"
:show-empty="true"
fixed
2020-04-08 14:13:33 +05:30
stacked="md"
2020-03-13 15:44:24 +05:30
tbody-tr-class="table-row mb-4"
>
<template #head(error)>
2020-04-08 14:13:33 +05:30
<div class="d-none d-md-block">{{ __('Open errors') }}</div>
2020-03-13 15:44:24 +05:30
</template>
<template #head(events)="data">
2020-04-08 14:13:33 +05:30
<div class="text-md-right">{{ data.label }}</div>
2020-03-13 15:44:24 +05:30
</template>
<template #head(users)="data">
2020-04-08 14:13:33 +05:30
<div class="text-md-right">{{ data.label }}</div>
2020-03-13 15:44:24 +05:30
</template>
2020-01-01 13:55:28 +05:30
2020-03-13 15:44:24 +05:30
<template #cell(error)="errors">
<div class="d-flex flex-column">
<gl-link class="d-flex mw-100 text-dark" :href="getDetailsLink(errors.item.id)">
<strong class="text-truncate">{{ errors.item.title.trim() }}</strong>
</gl-link>
<span class="text-secondary text-truncate mw-100">
{{ errors.item.culprit }}
</span>
</div>
</template>
<template #cell(events)="errors">
<div class="text-right">{{ errors.item.count }}</div>
</template>
<template #cell(users)="errors">
<div class="text-right">{{ errors.item.userCount }}</div>
</template>
<template #cell(lastSeen)="errors">
2020-04-08 14:13:33 +05:30
<div class="text-lg-left text-right">
2020-03-13 15:44:24 +05:30
<time-ago :time="errors.item.lastSeen" class="text-secondary" />
</div>
</template>
<template #cell(status)="errors">
2020-06-23 00:09:42 +05:30
<error-tracking-actions :error="errors.item" @update-issue-status="updateErrosStatus" />
2020-03-13 15:44:24 +05:30
</template>
<template #empty>
2020-01-01 13:55:28 +05:30
{{ __('No errors to display.') }}
<gl-link class="js-try-again" @click="restartPolling">
{{ __('Check again') }}
</gl-link>
2020-03-13 15:44:24 +05:30
</template>
</gl-table>
<gl-pagination
v-show="!loading"
v-if="paginationRequired"
:prev-page="$options.PREV_PAGE"
:next-page="$options.NEXT_PAGE"
:value="pageValue"
align="center"
@input="goToPage"
/>
</template>
2019-02-15 15:39:39 +05:30
</div>
2019-12-04 20:38:33 +05:30
<div v-else-if="userCanEnableErrorTracking">
2019-02-15 15:39:39 +05:30
<gl-empty-state
:title="__('Get started with error tracking')"
2019-12-04 20:38:33 +05:30
:description="__('Monitor your errors by integrating with Sentry.')"
2019-02-15 15:39:39 +05:30
:primary-button-text="__('Enable error tracking')"
:primary-button-link="enableErrorTrackingLink"
:svg-path="illustrationPath"
/>
</div>
2019-12-04 20:38:33 +05:30
<div v-else>
<gl-empty-state :title="__('Get started with error tracking')" :svg-path="illustrationPath">
<template #description>
<div>
<span>{{ __('Monitor your errors by integrating with Sentry.') }}</span>
2020-05-24 23:13:21 +05:30
<gl-link target="_blank" href="/help/user/project/operations/error_tracking.html">{{
__('More information')
}}</gl-link>
2019-12-04 20:38:33 +05:30
</div>
</template>
</gl-empty-state>
</div>
2019-02-15 15:39:39 +05:30
</div>
</template>