summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/components/trigger_block.vue
blob: 1afc1c9a5955a40132d6f8b8b4c21e8f61583532 (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
<script>
import { GlButton, GlTableLite } from '@gitlab/ui';
import { __ } from '~/locale';

const DEFAULT_TD_CLASSES = 'gl-w-half gl-font-sm! gl-border-gray-200!';
const DEFAULT_TH_CLASSES =
  'gl-bg-transparent! gl-border-b-solid! gl-border-b-gray-200! gl-border-b-1!';

export default {
  fields: [
    {
      key: 'key',
      label: __('Key'),
      tdAttr: { 'data-testid': 'trigger-build-key' },
      tdClass: DEFAULT_TD_CLASSES,
      thClass: DEFAULT_TH_CLASSES,
    },
    {
      key: 'value',
      label: __('Value'),
      tdAttr: { 'data-testid': 'trigger-build-value' },
      tdClass: DEFAULT_TD_CLASSES,
      thClass: DEFAULT_TH_CLASSES,
    },
  ],
  components: {
    GlButton,
    GlTableLite,
  },
  props: {
    trigger: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      showVariableValues: false,
    };
  },
  computed: {
    hasVariables() {
      return this.trigger.variables.length > 0;
    },
    getToggleButtonText() {
      return this.showVariableValues ? __('Hide values') : __('Reveal values');
    },
    hasValues() {
      return this.trigger.variables.some((v) => v.value);
    },
  },
  methods: {
    toggleValues() {
      this.showVariableValues = !this.showVariableValues;
    },
    getDisplayValue(value) {
      return this.showVariableValues ? value : '••••••';
    },
  },
};
</script>

<template>
  <div>
    <p
      v-if="trigger.short_token"
      :class="{ 'gl-mb-2': hasVariables, 'gl-mb-0': !hasVariables }"
      data-testid="trigger-short-token"
    >
      <span class="gl-font-weight-bold">{{ __('Trigger token:') }}</span> {{ trigger.short_token }}
    </p>

    <template v-if="hasVariables">
      <p class="gl-display-flex gl-justify-content-space-between gl-align-items-center">
        <span class="gl-font-weight-bold">{{ __('Trigger variables:') }}</span>

        <gl-button
          v-if="hasValues"
          class="gl-mt-2"
          size="small"
          data-testid="trigger-reveal-values-button"
          @click="toggleValues"
          >{{ getToggleButtonText }}</gl-button
        >
      </p>

      <gl-table-lite :items="trigger.variables" :fields="$options.fields" small bordered fixed>
        <template #cell(key)="{ item }">
          <span class="gl-overflow-break-word">{{ item.key }}</span>
        </template>

        <template #cell(value)="data">
          <span class="gl-overflow-break-word">{{ getDisplayValue(data.value) }}</span>
        </template>
      </gl-table-lite>
    </template>
  </div>
</template>