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

20% Statements 2/10
0% Branches 0/5
11.11% Functions 1/9
20% Lines 2/10

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              5x 5x                                                                                                                                                                                                                                                                                      
<script>
import { GlTooltip, GlTooltipDirective, GlIcon, GlBadge, GlTableLite } from '@gitlab/ui';
import { kebabCase } from 'lodash';
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
import { detailsLabels, subscriptionTable } from '../constants';
import { getLicenseTypeLabel } from '../utils';
 
const tdAttr = (_, key) => ({ 'data-testid': `subscription-cell-${kebabCase(key)}` });
const tdClassHighlight = 'gl-bg-blue-50!';
 
export default {
  i18n: {
    subscriptionHistoryTitle: subscriptionTable.title,
    detailsLabels,
  },
  name: 'SubscriptionDetailsHistory',
  components: {
    GlBadge,
    GlIcon,
    GlTooltip,
    GlTableLite,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    currentSubscriptionId: {
      type: String,
      required: false,
      default: null,
    },
    subscriptionList: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      fields: [
        {
          key: 'name',
          label: detailsLabels.name,
          tdAttr,
          tdClass: this.cellClass,
        },
        {
          key: 'plan',
          formatter: (v, k, item) => capitalizeFirstCharacter(item.plan),
          label: detailsLabels.plan,
          tdAttr,
          tdClass: this.cellClass,
        },
        {
          key: 'activatedAt',
          formatter: (v, k, { activatedAt }) => {
            Iif (!activatedAt) {
              return '-';
            }
 
            return activatedAt;
          },
          label: subscriptionTable.activatedAt,
          tdAttr,
          tdClass: this.cellClass,
        },
        {
          key: 'startsAt',
          label: subscriptionTable.startsAt,
          tdAttr,
          tdClass: this.cellClass,
        },
        {
          key: 'expiresAt',
          label: subscriptionTable.expiresOn,
          tdAttr,
          tdClass: this.cellClass,
        },
        {
          key: 'usersInLicenseCount',
          label: subscriptionTable.seats,
          tdAttr,
          tdClass: this.cellClass,
        },
        {
          key: 'type',
          formatter: (v, k, item) => getLicenseTypeLabel(item.type),
          label: subscriptionTable.type,
          tdAttr,
          tdClass: this.cellClass,
        },
      ],
    };
  },
  methods: {
    cellClass(_, x, item) {
      return this.isCurrentSubscription(item) ? tdClassHighlight : '';
    },
    isCurrentSubscription({ id }) {
      return id === this.currentSubscriptionId;
    },
    rowAttr() {
      return {
        'data-testid': 'subscription-history-row',
      };
    },
    rowClass(item) {
      return this.isCurrentSubscription(item) ? 'gl-font-weight-bold gl-text-blue-500' : '';
    },
  },
};
</script>
 
<template>
  <section>
    <header>
      <h2 class="gl-mb-6 gl-mt-0">{{ $options.i18n.subscriptionHistoryTitle }}</h2>
    </header>
    <gl-table-lite
      :details-td-class="$options.tdClass"
      :fields="fields"
      :items="subscriptionList"
      :tbody-tr-attr="rowAttr"
      :tbody-tr-class="rowClass"
      responsive
      stacked="sm"
      data-testid="subscription-history"
    >
      <template #cell(name)="{ item }">
        <span>
          <gl-icon :id="`tooltip-name-${item.id}`" v-gl-tooltip name="information-o" tabindex="0" />
          <gl-tooltip :target="`tooltip-name-${item.id}`">
            {{ item.email }}<br />({{ item.company }})
          </gl-tooltip>
          {{ item.name }}
          <span class="sr-only" data-testid="subscription-history-sr-only">
            {{ $options.i18n.detailsLabels.email }}: {{ item.email }}<br />({{
              $options.i18n.detailsLabels.company
            }}: {{ item.company }})
          </span>
        </span>
      </template>
      <template #cell(type)="{ value }">
        <gl-badge size="md" variant="info">{{ value }}</gl-badge>
      </template>
    </gl-table-lite>
  </section>
</template>