debian-mirror-gitlab/app/assets/javascripts/integrations/overrides/components/integration_overrides.vue

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

156 lines
4 KiB
Vue
Raw Normal View History

2021-10-27 15:23:28 +05:30
<script>
2021-11-18 22:05:49 +05:30
import { GlLink, GlLoadingIcon, GlPagination, GlTable, GlAlert } from '@gitlab/ui';
import * as Sentry from '@sentry/browser';
2021-10-27 15:23:28 +05:30
import { DEFAULT_PER_PAGE } from '~/api';
import { fetchOverrides } from '~/integrations/overrides/api';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { truncateNamespace } from '~/lib/utils/text_utility';
2022-01-26 12:08:38 +05:30
import { getParameterByName } from '~/lib/utils/url_utility';
2021-10-27 15:23:28 +05:30
import { __, s__ } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar.vue';
2022-01-26 12:08:38 +05:30
import UrlSync from '~/vue_shared/components/url_sync.vue';
2022-03-02 08:16:31 +05:30
import IntegrationTabs from './integration_tabs.vue';
2022-01-26 12:08:38 +05:30
const DEFAULT_PAGE = 1;
2021-10-27 15:23:28 +05:30
export default {
name: 'IntegrationOverrides',
components: {
GlLink,
GlLoadingIcon,
GlPagination,
GlTable,
2021-11-18 22:05:49 +05:30
GlAlert,
2021-10-27 15:23:28 +05:30
ProjectAvatar,
2022-01-26 12:08:38 +05:30
UrlSync,
2022-03-02 08:16:31 +05:30
IntegrationTabs,
2021-10-27 15:23:28 +05:30
},
props: {
overridesPath: {
type: String,
required: true,
},
},
fields: [
{
key: 'name',
label: __('Project'),
},
],
data() {
return {
isLoading: true,
overrides: [],
2022-01-26 12:08:38 +05:30
page: DEFAULT_PAGE,
2021-10-27 15:23:28 +05:30
totalItems: 0,
2021-11-18 22:05:49 +05:30
errorMessage: null,
2021-10-27 15:23:28 +05:30
};
},
computed: {
2022-03-02 08:16:31 +05:30
overridesCount() {
return this.isLoading ? null : this.totalItems;
},
2021-10-27 15:23:28 +05:30
showPagination() {
return this.totalItems > this.$options.DEFAULT_PER_PAGE && this.overrides.length > 0;
},
2022-01-26 12:08:38 +05:30
query() {
return {
page: this.page,
};
},
2021-10-27 15:23:28 +05:30
},
2022-01-26 12:08:38 +05:30
created() {
const initialPage = this.getInitialPage();
this.loadOverrides(initialPage);
2021-10-27 15:23:28 +05:30
},
methods: {
2022-01-26 12:08:38 +05:30
getInitialPage() {
return getParameterByName('page') ?? DEFAULT_PAGE;
},
loadOverrides(page) {
2021-10-27 15:23:28 +05:30
this.isLoading = true;
2021-11-18 22:05:49 +05:30
this.errorMessage = null;
2021-10-27 15:23:28 +05:30
fetchOverrides(this.overridesPath, {
page,
perPage: this.$options.DEFAULT_PER_PAGE,
})
.then(({ data, headers }) => {
const { page: newPage, total } = parseIntPagination(normalizeHeaders(headers));
this.page = newPage;
this.totalItems = total;
this.overrides = data;
})
.catch((error) => {
2021-11-18 22:05:49 +05:30
this.errorMessage = this.$options.i18n.defaultErrorMessage;
Sentry.captureException(error);
2021-10-27 15:23:28 +05:30
})
.finally(() => {
this.isLoading = false;
});
},
truncateNamespace,
},
DEFAULT_PER_PAGE,
i18n: {
defaultErrorMessage: s__(
'Integrations|An error occurred while loading projects using custom settings.',
),
tableEmptyText: s__('Integrations|There are no projects using custom settings'),
},
};
</script>
<template>
<div>
2022-03-02 08:16:31 +05:30
<integration-tabs :project-overrides-count="overridesCount" />
2021-11-18 22:05:49 +05:30
<gl-alert v-if="errorMessage" variant="danger" :dismissible="false">
{{ errorMessage }}
</gl-alert>
2021-10-27 15:23:28 +05:30
<gl-table
2021-11-18 22:05:49 +05:30
v-else
2021-10-27 15:23:28 +05:30
:items="overrides"
:fields="$options.fields"
:busy="isLoading"
show-empty
:empty-text="$options.i18n.tableEmptyText"
>
<template #cell(name)="{ item }">
<gl-link
class="gl-display-inline-flex gl-align-items-center gl-hover-text-decoration-none gl-text-body!"
:href="item.full_path"
>
<project-avatar
class="gl-mr-3"
:project-avatar-url="item.avatar_url"
:project-name="item.name"
aria-hidden="true"
/>
{{ truncateNamespace(item.full_name) }} /&nbsp;
<strong>{{ item.name }}</strong>
</gl-link>
</template>
<template #table-busy>
2022-07-23 23:45:48 +05:30
<gl-loading-icon size="lg" class="gl-my-2" />
2021-10-27 15:23:28 +05:30
</template>
</gl-table>
<div class="gl-display-flex gl-justify-content-center gl-mt-5">
2022-01-26 12:08:38 +05:30
<template v-if="showPagination">
<gl-pagination
:per-page="$options.DEFAULT_PER_PAGE"
:total-items="totalItems"
:value="page"
:disabled="isLoading"
@input="loadOverrides"
/>
<url-sync :query="query" />
</template>
2021-10-27 15:23:28 +05:30
</div>
</div>
</template>