summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/runner/components/registration/registration_token.vue
blob: d54a66ff0e4f59f29c2816f54b80effa10be5956 (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
<script>
import { GlButtonGroup, GlButton, GlTooltipDirective } from '@gitlab/ui';
import { s__, __ } from '~/locale';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';

export default {
  components: {
    GlButtonGroup,
    GlButton,
    ModalCopyButton,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    value: {
      type: String,
      required: false,
      default: '',
    },
  },
  data() {
    return {
      isMasked: true,
    };
  },
  computed: {
    maskLabel() {
      if (this.isMasked) {
        return __('Click to reveal');
      }
      return __('Click to hide');
    },
    maskIcon() {
      if (this.isMasked) {
        return 'eye';
      }
      return 'eye-slash';
    },
    displayedValue() {
      if (this.isMasked && this.value?.length) {
        return '*'.repeat(this.value.length);
      }
      return this.value;
    },
  },
  methods: {
    onToggleMasked() {
      this.isMasked = !this.isMasked;
    },
    onCopied() {
      // value already in the clipboard, simply notify the user
      this.$toast?.show(s__('Runners|Registration token copied!'));
    },
  },
  i18n: {
    copyLabel: s__('Runners|Copy registration token'),
  },
};
</script>
<template>
  <gl-button-group>
    <gl-button class="gl-font-monospace" data-testid="token-value" label>
      {{ displayedValue }}
    </gl-button>
    <gl-button
      v-gl-tooltip
      :aria-label="maskLabel"
      :title="maskLabel"
      :icon="maskIcon"
      class="gl-w-auto! gl-flex-shrink-0!"
      data-testid="toggle-masked"
      @click.stop="onToggleMasked"
    />
    <modal-copy-button
      class="gl-w-auto! gl-flex-shrink-0!"
      :aria-label="$options.i18n.copyLabel"
      :title="$options.i18n.copyLabel"
      :text="value"
      @success="onCopied"
    />
  </gl-button-group>
</template>