summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/clusters_list/components/clusters.vue
blob: 0b98f9c010191f14fbe52317d7c81db78c3b277c (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
<script>
import { mapState, mapActions } from 'vuex';
import {
  GlDeprecatedBadge as GlBadge,
  GlLink,
  GlLoadingIcon,
  GlPagination,
  GlTable,
} from '@gitlab/ui';
import tooltip from '~/vue_shared/directives/tooltip';
import { CLUSTER_TYPES, STATUSES } from '../constants';
import { __, sprintf } from '~/locale';

export default {
  components: {
    GlBadge,
    GlLink,
    GlLoadingIcon,
    GlPagination,
    GlTable,
  },
  directives: {
    tooltip,
  },
  computed: {
    ...mapState(['clusters', 'clustersPerPage', 'loading', 'page', 'totalCulsters']),
    currentPage: {
      get() {
        return this.page;
      },
      set(newVal) {
        this.setPage(newVal);
        this.fetchClusters();
      },
    },
    fields() {
      return [
        {
          key: 'name',
          label: __('Kubernetes cluster'),
        },
        {
          key: 'environment_scope',
          label: __('Environment scope'),
        },
        // Wait for backend to send these fields
        // {
        //  key: 'size',
        //  label: __('Size'),
        // },
        // {
        //  key: 'cpu',
        //  label: __('Total cores (vCPUs)'),
        // },
        // {
        //  key: 'memory',
        //  label: __('Total memory (GB)'),
        // },
        {
          key: 'cluster_type',
          label: __('Cluster level'),
          formatter: value => CLUSTER_TYPES[value],
        },
      ];
    },
    hasClusters() {
      return this.clustersPerPage > 0;
    },
  },
  mounted() {
    this.fetchClusters();
  },
  methods: {
    ...mapActions(['fetchClusters', 'setPage']),
    statusClass(status) {
      const iconClass = STATUSES[status] || STATUSES.default;
      return iconClass.className;
    },
    statusTitle(status) {
      const iconTitle = STATUSES[status] || STATUSES.default;
      return sprintf(__('Status: %{title}'), { title: iconTitle.title }, false);
    },
  },
};
</script>

<template>
  <gl-loading-icon v-if="loading" size="md" class="mt-3" />

  <section v-else>
    <gl-table :items="clusters" :fields="fields" stacked="md" class="qa-clusters-table">
      <template #cell(name)="{ item }">
        <div class="d-flex flex-row-reverse flex-md-row js-status">
          <gl-link data-qa-selector="cluster" :data-qa-cluster-name="item.name" :href="item.path">
            {{ item.name }}
          </gl-link>

          <gl-loading-icon
            v-if="item.status === 'deleting'"
            v-tooltip
            :title="statusTitle(item.status)"
            size="sm"
            class="mr-2 ml-md-2"
          />
          <div
            v-else
            v-tooltip
            class="cluster-status-indicator rounded-circle align-self-center gl-w-4 gl-h-4 mr-2 ml-md-2"
            :class="statusClass(item.status)"
            :title="statusTitle(item.status)"
          ></div>
        </div>
      </template>
      <template #cell(cluster_type)="{value}">
        <gl-badge variant="light">
          {{ value }}
        </gl-badge>
      </template>
    </gl-table>

    <gl-pagination
      v-if="hasClusters"
      v-model="currentPage"
      :per-page="clustersPerPage"
      :total-items="totalCulsters"
      :prev-text="__('Prev')"
      :next-text="__('Next')"
      align="center"
    />
  </section>
</template>