summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/sidebar/labels_select/dropdown_button.vue
blob: f874da3e60bb3697f04acfe124ad17369f1210ba (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 { __, s__, sprintf } from '~/locale';

export default {
  props: {
    abilityName: {
      type: String,
      required: true,
    },
    fieldName: {
      type: String,
      required: true,
    },
    updatePath: {
      type: String,
      required: true,
    },
    labelsPath: {
      type: String,
      required: true,
    },
    namespace: {
      type: String,
      required: true,
    },
    labels: {
      type: Array,
      required: true,
    },
    showExtraOptions: {
      type: Boolean,
      required: true,
    },
    enableScopedLabels: {
      type: Boolean,
      require: false,
      default: false,
    },
    scopedLabelsDocumentationLink: {
      type: String,
      require: false,
      default: '#',
    },
  },
  computed: {
    dropdownToggleText() {
      if (this.labels.length === 0) {
        return __('Label');
      }

      if (this.labels.length > 1) {
        return sprintf(s__('LabelSelect|%{firstLabelName} +%{remainingLabelCount} more'), {
          firstLabelName: this.labels[0].title,
          remainingLabelCount: this.labels.length - 1,
        });
      }

      return this.labels[0].title;
    },
  },
};
</script>

<template>
  <button
    ref="dropdownButton"
    :class="{ 'js-extra-options': showExtraOptions }"
    :data-ability-name="abilityName"
    :data-field-name="fieldName"
    :data-issue-update="updatePath"
    :data-labels="labelsPath"
    :data-namespace-path="namespace"
    :data-show-any="showExtraOptions"
    :data-scoped-labels="enableScopedLabels"
    :data-scoped-labels-documentation-link="scopedLabelsDocumentationLink"
    type="button"
    class="btn btn-default dropdown-menu-toggle wide js-label-select js-multiselect js-context-config-modal"
    data-toggle="dropdown"
  >
    <span class="dropdown-toggle-text"> {{ dropdownToggleText }} </span>
    <i aria-hidden="true" class="fa fa-chevron-down" data-hidden="true"> </i>
  </button>
</template>