summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ci_variable_list/components/ci_variable_table.vue
blob: e240323d2c5143d5150558eb1cc258d0312662ee (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
<script>
import { GlTable, GlButton, GlModalDirective, GlIcon } from '@gitlab/ui';
import { s__, __ } from '~/locale';
import { mapState, mapActions } from 'vuex';
import { ADD_CI_VARIABLE_MODAL_ID } from '../constants';

export default {
  modalId: ADD_CI_VARIABLE_MODAL_ID,
  fields: [
    {
      key: 'variable_type',
      label: s__('CiVariables|Type'),
    },
    {
      key: 'key',
      label: s__('CiVariables|Key'),
    },
    {
      key: 'value',
      label: s__('CiVariables|Value'),
      tdClass: 'qa-ci-variable-input-value',
    },
    {
      key: 'protected',
      label: s__('CiVariables|Protected'),
    },
    {
      key: 'masked',
      label: s__('CiVariables|Masked'),
    },
    {
      key: 'environment_scope',
      label: s__('CiVariables|Environment Scope'),
    },
    {
      key: 'actions',
      label: '',
    },
  ],
  components: {
    GlTable,
    GlButton,
    GlIcon,
  },
  directives: {
    GlModalDirective,
  },
  computed: {
    ...mapState(['variables', 'valuesHidden', 'isGroup', 'isLoading', 'isDeleting']),
    valuesButtonText() {
      return this.valuesHidden ? __('Reveal values') : __('Hide values');
    },
    tableIsNotEmpty() {
      return this.variables && this.variables.length > 0;
    },
    fields() {
      if (this.isGroup) {
        return this.$options.fields.filter(field => field.key !== 'environment_scope');
      }
      return this.$options.fields;
    },
  },
  mounted() {
    this.fetchVariables();
  },
  methods: {
    ...mapActions(['fetchVariables', 'deleteVariable', 'toggleValues', 'editVariable']),
  },
};
</script>

<template>
  <div class="ci-variable-table">
    <gl-table
      :fields="fields"
      :items="variables"
      responsive
      show-empty
      tbody-tr-class="js-ci-variable-row"
    >
      <template #cell(value)="data">
        <span v-if="valuesHidden">*****************</span>
        <span v-else>{{ data.value }}</span>
      </template>
      <template #cell(actions)="data">
        <gl-button
          ref="edit-ci-variable"
          v-gl-modal-directive="$options.modalId"
          @click="editVariable(data.item)"
        >
          <gl-icon name="pencil" />
        </gl-button>
        <gl-button
          ref="delete-ci-variable"
          category="secondary"
          variant="danger"
          @click="deleteVariable(data.item)"
        >
          <gl-icon name="remove" />
        </gl-button>
      </template>
      <template #empty>
        <p ref="empty-variables" class="settings-message text-center empty-variables">
          {{
            __(
              'There are currently no variables, add a variable with the Add Variable button below.',
            )
          }}
        </p>
      </template>
    </gl-table>
    <div class="ci-variable-actions d-flex justify-content-end">
      <gl-button
        v-if="tableIsNotEmpty"
        ref="secret-value-reveal-button"
        data-qa-selector="reveal_ci_variable_value"
        class="append-right-8"
        @click="toggleValues(!valuesHidden)"
        >{{ valuesButtonText }}</gl-button
      >
      <gl-button
        ref="add-ci-variable"
        v-gl-modal-directive="$options.modalId"
        data-qa-selector="add_ci_variable"
        variant="success"
        >{{ __('Add Variable') }}</gl-button
      >
    </div>
  </div>
</template>