All files / app/assets/javascripts/integrations/overrides/components integration_overrides.vue

100% Statements 31/31
100% Branches 8/8
100% Functions 11/11
100% Lines 31/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156  1x 1x   1x 1x 1x 1x 1x 1x 1x 1x   1x   1x                                                     12x                   24x     19x     6x           12x 12x       12x   14x 14x 14x   14x         11x 11x 11x 11x     3x   3x     14x                             228x                                                                                                  
<script>
import { GlLink, GlLoadingIcon, GlPagination, GlTable, GlAlert } from '@gitlab/ui';
import * as Sentry from '@sentry/browser';
 
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';
import { getParameterByName } from '~/lib/utils/url_utility';
import { __, s__ } from '~/locale';
import ProjectAvatar from '~/vue_shared/components/project_avatar.vue';
import UrlSync from '~/vue_shared/components/url_sync.vue';
 
import IntegrationTabs from './integration_tabs.vue';
 
const DEFAULT_PAGE = 1;
 
export default {
  name: 'IntegrationOverrides',
  components: {
    GlLink,
    GlLoadingIcon,
    GlPagination,
    GlTable,
    GlAlert,
    ProjectAvatar,
    UrlSync,
    IntegrationTabs,
  },
  props: {
    overridesPath: {
      type: String,
      required: true,
    },
  },
  fields: [
    {
      key: 'name',
      label: __('Project'),
    },
  ],
  data() {
    return {
      isLoading: true,
      overrides: [],
      page: DEFAULT_PAGE,
      totalItems: 0,
      errorMessage: null,
    };
  },
  computed: {
    overridesCount() {
      return this.isLoading ? null : this.totalItems;
    },
    showPagination() {
      return this.totalItems > this.$options.DEFAULT_PER_PAGE && this.overrides.length > 0;
    },
    query() {
      return {
        page: this.page,
      };
    },
  },
  created() {
    const initialPage = this.getInitialPage();
    this.loadOverrides(initialPage);
  },
  methods: {
    getInitialPage() {
      return getParameterByName('page') ?? DEFAULT_PAGE;
    },
    loadOverrides(page) {
      this.isLoading = true;
      this.errorMessage = null;
 
      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) => {
          this.errorMessage = this.$options.i18n.defaultErrorMessage;
 
          Sentry.captureException(error);
        })
        .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>
    <integration-tabs :project-overrides-count="overridesCount" />
    <gl-alert v-if="errorMessage" variant="danger" :dismissible="false">
      {{ errorMessage }}
    </gl-alert>
    <gl-table
      v-else
      :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>
        <gl-loading-icon size="md" class="gl-my-2" />
      </template>
    </gl-table>
    <div class="gl-display-flex gl-justify-content-center gl-mt-5">
      <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>
    </div>
  </div>
</template>