Welcome to mirror list, hosted at ThFree Co, Russian Federation.

token_table.vue « components « agents « clusters « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 667d10e1753730437cc20fc0230e48a5981073de (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
<script>
import { GlEmptyState, GlTable, GlTooltip, GlTruncate } from '@gitlab/ui';
import { s__ } from '~/locale';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import CreateTokenButton from './create_token_button.vue';
import CreateTokenModal from './create_token_modal.vue';
import RevokeTokenButton from './revoke_token_button.vue';

export default {
  components: {
    GlEmptyState,
    GlTable,
    GlTooltip,
    GlTruncate,
    TimeAgoTooltip,
    CreateTokenButton,
    CreateTokenModal,
    RevokeTokenButton,
  },
  i18n: {
    createdBy: s__('ClusterAgents|Created by'),
    createToken: s__('ClusterAgents|You will need to create a token to connect to your agent'),
    dateCreated: s__('ClusterAgents|Date created'),
    description: s__('ClusterAgents|Description'),
    lastUsed: s__('ClusterAgents|Last contact'),
    name: s__('ClusterAgents|Name'),
    neverUsed: s__('ClusterAgents|Never'),
    noTokens: s__('ClusterAgents|This agent has no tokens'),
    unknownUser: s__('ClusterAgents|Unknown user'),
  },
  props: {
    tokens: {
      required: true,
      type: Array,
    },
    clusterAgentId: {
      required: true,
      type: String,
    },
    cursor: {
      required: true,
      type: Object,
    },
  },
  computed: {
    fields() {
      const tdClass = 'gl-vertical-align-middle!';
      return [
        {
          key: 'name',
          label: this.$options.i18n.name,
          tdAttr: { 'data-testid': 'agent-token-name' },
          tdClass,
        },
        {
          key: 'lastUsed',
          label: this.$options.i18n.lastUsed,
          tdAttr: { 'data-testid': 'agent-token-used' },
          tdClass,
        },
        {
          key: 'createdAt',
          label: this.$options.i18n.dateCreated,
          tdAttr: { 'data-testid': 'agent-token-created-time' },
          tdClass,
        },
        {
          key: 'createdBy',
          label: this.$options.i18n.createdBy,
          tdAttr: { 'data-testid': 'agent-token-created-user' },
          tdClass,
        },
        {
          key: 'description',
          label: this.$options.i18n.description,
          tdAttr: { 'data-testid': 'agent-token-description' },
          tdClass,
        },
        {
          key: 'actions',
          label: '',
          tdAttr: { 'data-testid': 'agent-token-revoke' },
          tdClass,
        },
      ];
    },
  },
  methods: {
    createdByName(token) {
      return token?.createdByUser?.name || this.$options.i18n.unknownUser;
    },
  },
};
</script>

<template>
  <div>
    <div v-if="tokens.length">
      <create-token-button class="gl-text-right gl-my-5" />

      <gl-table
        :items="tokens"
        :fields="fields"
        fixed
        stacked="md"
        head-variant="white"
        thead-class="gl-border-b-solid gl-border-b-2 gl-border-b-gray-100"
      >
        <template #cell(lastUsed)="{ item }">
          <time-ago-tooltip v-if="item.lastUsedAt" :time="item.lastUsedAt" />
          <span v-else>{{ $options.i18n.neverUsed }}</span>
        </template>

        <template #cell(createdAt)="{ item }">
          <time-ago-tooltip :time="item.createdAt" />
        </template>

        <template #cell(createdBy)="{ item }">
          <span>{{ createdByName(item) }}</span>
        </template>

        <template #cell(description)="{ item }">
          <div v-if="item.description" :id="`tooltip-description-container-${item.id}`">
            <gl-truncate :id="`tooltip-description-${item.id}`" :text="item.description" />

            <gl-tooltip
              :container="`tooltip-description-container-${item.id}`"
              :target="`tooltip-description-${item.id}`"
              placement="top"
            >
              {{ item.description }}
            </gl-tooltip>
          </div>
        </template>

        <template #cell(actions)="{ item }">
          <revoke-token-button :token="item" :cluster-agent-id="clusterAgentId" :cursor="cursor" />
        </template>
      </gl-table>
    </div>

    <gl-empty-state v-else :title="$options.i18n.noTokens">
      <template #actions>
        <create-token-button />
      </template>
    </gl-empty-state>

    <create-token-modal :cluster-agent-id="clusterAgentId" :cursor="cursor" />
  </div>
</template>