summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/usage_quotas/storage/components/project_storage_detail.vue
blob: 2b97886e650fdc63f8cf41e15b584dfb19f65ee8 (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
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
<script>
import { GlIcon, GlLink, GlSprintf, GlTableLite, GlPopover } from '@gitlab/ui';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import { thWidthPercent } from '~/lib/utils/table_utility';
import { sprintf } from '~/locale';
import {
  HELP_LINK_ARIA_LABEL,
  PROJECT_TABLE_LABEL_STORAGE_TYPE,
  PROJECT_TABLE_LABEL_USAGE,
  containerRegistryId,
  containerRegistryPopoverId,
  uploadsId,
  uploadsPopoverId,
  uploadsPopoverContent,
} from '../constants';
import { descendingStorageUsageSort } from '../utils';
import StorageTypeIcon from './storage_type_icon.vue';

export default {
  name: 'ProjectStorageDetail',
  components: {
    GlLink,
    GlIcon,
    GlTableLite,
    GlSprintf,
    StorageTypeIcon,
    GlPopover,
  },
  inject: ['containerRegistryPopoverContent'],
  props: {
    storageTypes: {
      type: Array,
      required: true,
    },
  },
  computed: {
    sizeSortedStorageTypes() {
      const warnings = {
        [containerRegistryId]: {
          popoverId: containerRegistryPopoverId,
          popoverContent: this.containerRegistryPopoverContent,
        },
        [uploadsId]: {
          popoverId: uploadsPopoverId,
          popoverContent: this.$options.i18n.uploadsPopoverContent,
        },
      };

      return this.storageTypes
        .map((type) => {
          const warning = warnings[type.storageType.id] || null;
          return {
            warning,
            ...type,
          };
        })
        .sort(descendingStorageUsageSort('value'));
    },
  },
  methods: {
    helpLinkAriaLabel(linkTitle) {
      return sprintf(HELP_LINK_ARIA_LABEL, {
        linkTitle,
      });
    },
    numberToHumanSize,
  },
  projectTableFields: [
    {
      key: 'storageType',
      label: PROJECT_TABLE_LABEL_STORAGE_TYPE,
      thClass: thWidthPercent(90),
    },
    {
      key: 'value',
      label: PROJECT_TABLE_LABEL_USAGE,
      thClass: thWidthPercent(10),
    },
  ],
  i18n: {
    uploadsPopoverContent,
  },
};
</script>
<template>
  <gl-table-lite :items="sizeSortedStorageTypes" :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>

    <template #cell(value)="{ item }">
      {{ numberToHumanSize(item.value, 1) }}

      <template v-if="item.warning">
        <gl-icon
          :id="item.warning.popoverId"
          name="warning"
          class="gl-mt-2 gl-lg-mt-0 gl-lg-ml-2"
        />
        <gl-popover
          triggers="hover focus"
          placement="top"
          :target="item.warning.popoverId"
          :content="item.warning.popoverContent"
          :data-testid="item.warning.popoverId"
        />
      </template>
    </template>
  </gl-table-lite>
</template>