2021-11-18 22:05:49 +05:30
|
|
|
<script>
|
2022-05-07 20:08:51 +05:30
|
|
|
import { GlEmptyState, GlTable, GlTooltip, GlTruncate } from '@gitlab/ui';
|
2021-11-18 22:05:49 +05:30
|
|
|
import { s__ } from '~/locale';
|
|
|
|
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
|
2022-05-07 20:08:51 +05:30
|
|
|
import CreateTokenButton from './create_token_button.vue';
|
2022-07-23 23:45:48 +05:30
|
|
|
import CreateTokenModal from './create_token_modal.vue';
|
2022-07-16 23:28:13 +05:30
|
|
|
import RevokeTokenButton from './revoke_token_button.vue';
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlEmptyState,
|
|
|
|
GlTable,
|
|
|
|
GlTooltip,
|
|
|
|
GlTruncate,
|
|
|
|
TimeAgoTooltip,
|
2022-05-07 20:08:51 +05:30
|
|
|
CreateTokenButton,
|
2022-07-23 23:45:48 +05:30
|
|
|
CreateTokenModal,
|
2022-07-16 23:28:13 +05:30
|
|
|
RevokeTokenButton,
|
2021-11-18 22:05:49 +05:30
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
clusterAgentId: {
|
|
|
|
required: true,
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
cursor: {
|
|
|
|
required: true,
|
|
|
|
type: Object,
|
|
|
|
},
|
2021-11-18 22:05:49 +05:30
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
fields() {
|
2022-10-11 01:57:18 +05:30
|
|
|
const tdClass = 'gl-vertical-align-middle!';
|
2021-11-18 22:05:49 +05:30
|
|
|
return [
|
|
|
|
{
|
|
|
|
key: 'name',
|
|
|
|
label: this.$options.i18n.name,
|
|
|
|
tdAttr: { 'data-testid': 'agent-token-name' },
|
2022-10-11 01:57:18 +05:30
|
|
|
tdClass,
|
2021-11-18 22:05:49 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'lastUsed',
|
|
|
|
label: this.$options.i18n.lastUsed,
|
|
|
|
tdAttr: { 'data-testid': 'agent-token-used' },
|
2022-10-11 01:57:18 +05:30
|
|
|
tdClass,
|
2021-11-18 22:05:49 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'createdAt',
|
|
|
|
label: this.$options.i18n.dateCreated,
|
|
|
|
tdAttr: { 'data-testid': 'agent-token-created-time' },
|
2022-10-11 01:57:18 +05:30
|
|
|
tdClass,
|
2021-11-18 22:05:49 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'createdBy',
|
|
|
|
label: this.$options.i18n.createdBy,
|
|
|
|
tdAttr: { 'data-testid': 'agent-token-created-user' },
|
2022-10-11 01:57:18 +05:30
|
|
|
tdClass,
|
2021-11-18 22:05:49 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'description',
|
|
|
|
label: this.$options.i18n.description,
|
|
|
|
tdAttr: { 'data-testid': 'agent-token-description' },
|
2022-10-11 01:57:18 +05:30
|
|
|
tdClass,
|
2021-11-18 22:05:49 +05:30
|
|
|
},
|
2022-07-16 23:28:13 +05:30
|
|
|
{
|
|
|
|
key: 'actions',
|
|
|
|
label: '',
|
|
|
|
tdAttr: { 'data-testid': 'agent-token-revoke' },
|
2022-10-11 01:57:18 +05:30
|
|
|
tdClass,
|
2022-07-16 23:28:13 +05:30
|
|
|
},
|
2021-11-18 22:05:49 +05:30
|
|
|
];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
createdByName(token) {
|
|
|
|
return token?.createdByUser?.name || this.$options.i18n.unknownUser;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-07-23 23:45:48 +05:30
|
|
|
<div>
|
|
|
|
<div v-if="tokens.length">
|
|
|
|
<create-token-button class="gl-text-right gl-my-5" />
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
<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>
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
<template #cell(createdAt)="{ item }">
|
|
|
|
<time-ago-tooltip :time="item.createdAt" />
|
|
|
|
</template>
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
<template #cell(createdBy)="{ item }">
|
|
|
|
<span>{{ createdByName(item) }}</span>
|
|
|
|
</template>
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
<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" />
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
<gl-tooltip
|
|
|
|
:container="`tooltip-description-container-${item.id}`"
|
|
|
|
:target="`tooltip-description-${item.id}`"
|
|
|
|
placement="top"
|
|
|
|
>
|
|
|
|
{{ item.description }}
|
|
|
|
</gl-tooltip>
|
|
|
|
</div>
|
|
|
|
</template>
|
2022-07-16 23:28:13 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
<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 />
|
2022-07-16 23:28:13 +05:30
|
|
|
</template>
|
2022-07-23 23:45:48 +05:30
|
|
|
</gl-empty-state>
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
<create-token-modal :cluster-agent-id="clusterAgentId" :cursor="cursor" />
|
|
|
|
</div>
|
2021-11-18 22:05:49 +05:30
|
|
|
</template>
|