summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issuable/bulk_update_sidebar/components/status_dropdown.vue
blob: ba94932289e0adf9b36c789de18c1148bab5521f (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
<script>
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { __ } from '~/locale';
import { statusDropdownOptions } from '../constants';

export default {
  components: {
    GlDropdown,
    GlDropdownItem,
  },
  data() {
    return {
      status: null,
    };
  },
  computed: {
    dropdownText() {
      return this.status?.text ?? this.$options.i18n.defaultDropdownText;
    },
    selectedValue() {
      return this.status?.value;
    },
  },
  methods: {
    onDropdownItemClick(statusOption) {
      // clear status if the currently checked status is clicked again
      if (this.status?.value === statusOption.value) {
        this.status = null;
      } else {
        this.status = statusOption;
      }
    },
  },
  i18n: {
    dropdownTitle: __('Change status'),
    defaultDropdownText: __('Select status'),
  },
  statusDropdownOptions,
};
</script>
<template>
  <div>
    <input type="hidden" name="update[state_event]" :value="selectedValue" />
    <gl-dropdown :text="dropdownText" :title="$options.i18n.dropdownTitle" class="gl-w-full">
      <gl-dropdown-item
        v-for="statusOption in $options.statusDropdownOptions"
        :key="statusOption.value"
        :is-checked="selectedValue === statusOption.value"
        is-check-item
        :title="statusOption.text"
        @click="onDropdownItemClick(statusOption)"
      >
        {{ statusOption.text }}
      </gl-dropdown-item>
    </gl-dropdown>
  </div>
</template>