All files / ee/app/assets/javascripts/admin/subscriptions/show/components subscription_details_table.vue

28.57% Statements 4/14
0% Branches 0/7
7.69% Functions 1/13
28.57% Lines 4/14

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                  4x 4x 4x 4x                                                                                                                                                                                                                                                                  
<script>
import { GlSkeletonLoader, GlTableLite } from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports
import { mapGetters } from 'vuex';
import { slugify, slugifyWithUnderscore } from '~/lib/utils/text_utility';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import SubscriptionSyncButton from 'ee/admin/subscriptions/show/components/subscription_sync_button.vue';
import { copySubscriptionIdButtonText, detailsLabels, subscriptionTypes } from '../constants';
 
const placeholderHeightFactor = 32;
const placeholderWidth = 180;
const DEFAULT_TD_CLASSES = 'gl-border-none! gl-h-7 gl-line-height-normal! gl-p-0!';
const itemDetailTestId = (v, k, item) => ({ 'data-testid': `${slugify(item.detail || '')}` });
 
export default {
  detailsLabels,
  i18n: {
    copySubscriptionIdButtonText,
  },
  fields: [
    {
      key: 'label',
      label: '',
      tdClass: `${DEFAULT_TD_CLASSES} gl-w-13`,
    },
    {
      key: 'value',
      formatter: (v, k, item) => item.value?.toString() || '-',
      label: '',
      tdAttr: itemDetailTestId,
      tdClass: DEFAULT_TD_CLASSES,
    },
  ],
  name: 'SubscriptionDetailsTable',
  components: {
    ClipboardButton,
    GlSkeletonLoader,
    GlTableLite,
    SubscriptionSyncButton,
  },
  props: {
    details: {
      type: Array,
      required: true,
    },
    subscriptionType: {
      type: String,
      required: true,
    },
  },
  computed: {
    ...mapGetters(['didSyncFail']),
    hasContent() {
      return this.details.some(({ value }) => Boolean(value));
    },
    placeholderContainerHeight() {
      return this.details.length * placeholderHeightFactor;
    },
    placeholderContainerWidth() {
      return placeholderWidth;
    },
    placeHolderHeight() {
      return placeholderHeightFactor / 2;
    },
  },
  methods: {
    placeHolderPosition(index) {
      return (index - 1) * placeholderHeightFactor;
    },
    rowAttr({ detail }, type) {
      return {
        'data-testid': `${type}-${slugifyWithUnderscore(detail)}`,
      };
    },
    lastSyncFailed(item) {
      return item.detail === 'lastSync' && this.didSyncFail;
    },
    rowClass(item) {
      return this.lastSyncFailed(item) ? `gl-text-red-500` : 'gl-text-gray-800';
    },
    rowLabel({ detail }) {
      return this.$options.detailsLabels[detail];
    },
    shouldShowDetail(detail) {
      return (
        detail === 'lastSync' &&
        this.subscriptionType !== subscriptionTypes.OFFLINE_CLOUD &&
        this.subscriptionType !== subscriptionTypes.LEGACY_LICENSE
      );
    },
  },
};
</script>
 
<template>
  <gl-table-lite
    v-if="hasContent"
    :fields="$options.fields"
    :items="details"
    class="gl-m-0!"
    thead-class="gl-display-none"
    :tbody-tr-attr="rowAttr"
    :tbody-tr-class="rowClass"
  >
    <template #cell(label)="{ item }">
      <p class="gl-font-weight-bold" data-testid="details-label">{{ rowLabel(item) }}:</p>
    </template>
 
    <template #cell(value)="{ item, value }">
      <p class="gl-relative" data-testid="details-content">
        {{ value }}
        <clipboard-button
          v-if="item.detail === 'id'"
          :text="value"
          :title="$options.i18n.copySubscriptionIdButtonText"
          :aria-label="$options.i18n.copySubscriptionIdButtonText"
          category="tertiary"
          class="gl-absolute gl-mt-n2 gl-ml-2"
          size="small"
        />
        <subscription-sync-button v-if="shouldShowDetail(item.detail)" />
      </p>
    </template>
  </gl-table-lite>
  <div
    v-else
    :style="{ height: `${placeholderContainerHeight}px`, width: `${placeholderContainerWidth}px` }"
    class="gl-pt-2"
  >
    <gl-skeleton-loader :height="placeholderContainerHeight" :width="placeholderContainerWidth">
      <rect
        v-for="index in details.length"
        :key="index"
        :height="placeHolderHeight"
        :width="placeholderContainerWidth"
        :y="placeHolderPosition(index)"
        rx="8"
      />
    </gl-skeleton-loader>
  </div>
</template>