summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/monitoring/components/variables/dropdown_field.vue
blob: ff0327f5f99b76cdcd13411170643fb2ef3e0850 (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
<script>
import { GlFormGroup, GlDropdown, GlDropdownItem } from '@gitlab/ui';

export default {
  components: {
    GlFormGroup,
    GlDropdown,
    GlDropdownItem,
  },
  props: {
    name: {
      type: String,
      required: true,
    },
    label: {
      type: String,
      required: true,
    },
    value: {
      type: String,
      required: false,
      default: '',
    },
    options: {
      type: Object,
      required: true,
    },
  },
  computed: {
    text() {
      const selectedOpt = this.options.values?.find((opt) => opt.value === this.value);
      return selectedOpt?.text || this.value;
    },
  },
  methods: {
    onUpdate(value) {
      this.$emit('input', value);
    },
  },
};
</script>
<template>
  <gl-form-group :label="label">
    <gl-dropdown toggle-class="dropdown-menu-toggle" :text="text || s__('Metrics|Select a value')">
      <gl-dropdown-item
        v-for="val in options.values"
        :key="val.value"
        @click="onUpdate(val.value)"
        >{{ val.text }}</gl-dropdown-item
      >
    </gl-dropdown>
  </gl-form-group>
</template>