summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/storage_counter/components/storage_table.vue
blob: a42a97115728b3de40521d7d11b77ab966aba80b (plain)
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
<script>
import { GlLink, GlIcon, GlTableLite as GlTable, GlSprintf } from '@gitlab/ui';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import { thWidthClass } from '~/lib/utils/table_utility';
import { sprintf } from '~/locale';
import { PROJECT_TABLE_LABELS, HELP_LINK_ARIA_LABEL } from '../constants';
import StorageTypeIcon from './storage_type_icon.vue';

export default {
  name: 'StorageTable',
  components: {
    GlLink,
    GlIcon,
    GlTable,
    GlSprintf,
    StorageTypeIcon,
  },
  props: {
    storageTypes: {
      type: Array,
      required: true,
    },
  },
  methods: {
    helpLinkAriaLabel(linkTitle) {
      return sprintf(HELP_LINK_ARIA_LABEL, {
        linkTitle,
      });
    },
  },
  projectTableFields: [
    {
      key: 'storageType',
      label: PROJECT_TABLE_LABELS.STORAGE_TYPE,
      thClass: thWidthClass(90),
      sortable: true,
    },
    {
      key: 'value',
      label: PROJECT_TABLE_LABELS.VALUE,
      thClass: thWidthClass(10),
      sortable: true,
      formatter: (value) => {
        return numberToHumanSize(value, 1);
      },
    },
  ],
};
</script>
<template>
  <gl-table :items="storageTypes" :fields="$options.projectTableFields">
    <template #cell(storageType)="{ item }">
      <div class="gl-display-flex gl-flex-direction-row">
        <storage-type-icon
          :name="item.storageType.id"
          :data-testid="`${item.storageType.id}-icon`"
        />
        <div>
          <p class="gl-font-weight-bold gl-mb-0" :data-testid="`${item.storageType.id}-name`">
            {{ item.storageType.name }}
            <gl-link
              v-if="item.storageType.helpPath"
              :href="item.storageType.helpPath"
              target="_blank"
              :aria-label="helpLinkAriaLabel(item.storageType.name)"
              :data-testid="`${item.storageType.id}-help-link`"
            >
              <gl-icon name="question" :size="12" />
            </gl-link>
          </p>
          <p class="gl-mb-0" :data-testid="`${item.storageType.id}-description`">
            {{ item.storageType.description }}
          </p>
          <p v-if="item.storageType.warningMessage" class="gl-mb-0 gl-font-sm">
            <gl-icon name="warning" :size="12" />
            <gl-sprintf :message="item.storageType.warningMessage">
              <template #warningLink="{ content }">
                <gl-link :href="item.storageType.warningLink" target="_blank" class="gl-font-sm">{{
                  content
                }}</gl-link>
              </template>
            </gl-sprintf>
          </p>
        </div>
      </div>
    </template>
  </gl-table>
</template>