summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/clusters_list/components/agent_table.vue
blob: 487e512c06d50fb379ac5c7368ed138297c45530 (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
143
144
145
146
147
148
149
150
151
152
<script>
import {
  GlButton,
  GlLink,
  GlModalDirective,
  GlTable,
  GlIcon,
  GlSprintf,
  GlTooltip,
  GlPopover,
} from '@gitlab/ui';
import { s__ } from '~/locale';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import timeagoMixin from '~/vue_shared/mixins/timeago';
import { INSTALL_AGENT_MODAL_ID, AGENT_STATUSES, TROUBLESHOOTING_LINK } from '../constants';

export default {
  components: {
    GlButton,
    GlLink,
    GlTable,
    GlIcon,
    GlSprintf,
    GlTooltip,
    GlPopover,
    TimeAgoTooltip,
  },
  directives: {
    GlModalDirective,
  },
  mixins: [timeagoMixin],
  inject: ['integrationDocsUrl'],
  INSTALL_AGENT_MODAL_ID,
  AGENT_STATUSES,
  TROUBLESHOOTING_LINK,
  props: {
    agents: {
      required: true,
      type: Array,
    },
  },
  computed: {
    fields() {
      return [
        {
          key: 'name',
          label: s__('ClusterAgents|Name'),
        },
        {
          key: 'status',
          label: s__('ClusterAgents|Connection status'),
        },
        {
          key: 'lastContact',
          label: s__('ClusterAgents|Last contact'),
        },
        {
          key: 'configuration',
          label: s__('ClusterAgents|Configuration'),
        },
      ];
    },
  },
};
</script>

<template>
  <div>
    <div class="gl-display-block gl-text-right gl-my-3">
      <gl-button
        v-gl-modal-directive="$options.INSTALL_AGENT_MODAL_ID"
        variant="confirm"
        category="primary"
        >{{ s__('ClusterAgents|Install a new GitLab Agent') }}
      </gl-button>
    </div>

    <gl-table
      :items="agents"
      :fields="fields"
      stacked="md"
      head-variant="white"
      thead-class="gl-border-b-solid gl-border-b-1 gl-border-b-gray-100"
      data-testid="cluster-agent-list-table"
    >
      <template #cell(name)="{ item }">
        <gl-link :href="item.webPath" data-testid="cluster-agent-name-link">
          {{ item.name }}
        </gl-link>
      </template>

      <template #cell(status)="{ item }">
        <span
          :id="`connection-status-${item.name}`"
          class="gl-pr-5"
          data-testid="cluster-agent-connection-status"
        >
          <span :class="$options.AGENT_STATUSES[item.status].class" class="gl-mr-3">
            <gl-icon :name="$options.AGENT_STATUSES[item.status].icon" :size="12" /></span
          >{{ $options.AGENT_STATUSES[item.status].name }}
        </span>
        <gl-tooltip
          v-if="item.status === 'active'"
          :target="`connection-status-${item.name}`"
          placement="right"
        >
          <gl-sprintf :message="$options.AGENT_STATUSES[item.status].tooltip.title"
            ><template #timeAgo>{{ timeFormatted(item.lastContact) }}</template>
          </gl-sprintf>
        </gl-tooltip>
        <gl-popover
          v-else
          :target="`connection-status-${item.name}`"
          :title="$options.AGENT_STATUSES[item.status].tooltip.title"
          placement="right"
          container="viewport"
        >
          <p>
            <gl-sprintf :message="$options.AGENT_STATUSES[item.status].tooltip.body"
              ><template #timeAgo>{{ timeFormatted(item.lastContact) }}</template></gl-sprintf
            >
          </p>
          <p class="gl-mb-0">
            {{ s__('ClusterAgents|For more troubleshooting information go to') }}
            <gl-link :href="$options.TROUBLESHOOTING_LINK" target="_blank" class="gl-font-sm">
              {{ $options.TROUBLESHOOTING_LINK }}</gl-link
            >
          </p>
        </gl-popover>
      </template>

      <template #cell(lastContact)="{ item }">
        <span data-testid="cluster-agent-last-contact">
          <time-ago-tooltip v-if="item.lastContact" :time="item.lastContact" />
          <span v-else>{{ s__('ClusterAgents|Never') }}</span>
        </span>
      </template>

      <template #cell(configuration)="{ item }">
        <span data-testid="cluster-agent-configuration-link">
          <!-- eslint-disable @gitlab/vue-require-i18n-strings -->
          <gl-link v-if="item.configFolder" :href="item.configFolder.webPath">
            .gitlab/agents/{{ item.name }}
          </gl-link>

          <span v-else>.gitlab/agents/{{ item.name }}</span>
          <!-- eslint-enable @gitlab/vue-require-i18n-strings -->
        </span>
      </template>
    </gl-table>
  </div>
</template>