summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/sidebar/labels_select/dropdown_value.vue
blob: fe43f77b1ee1293a6f6d8191f3f8201cb125209d (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
<script>
import { GlLabel } from '@gitlab/ui';
import { isScopedLabel } from '~/lib/utils/common_utils';

export default {
  components: {
    GlLabel,
  },
  props: {
    labels: {
      type: Array,
      required: true,
    },
    labelFilterBasePath: {
      type: String,
      required: true,
    },
    enableScopedLabels: {
      type: Boolean,
      required: false,
      default: false,
    },
    scopedLabelsDocumentationLink: {
      type: String,
      required: false,
      default: '#',
    },
  },
  computed: {
    isEmpty() {
      return this.labels.length === 0;
    },
  },
  methods: {
    labelFilterUrl(label) {
      return `${this.labelFilterBasePath}?label_name[]=${encodeURIComponent(label.title)}`;
    },
    scopedLabelsDescription({ description = '' }) {
      return `<span class="font-weight-bold scoped-label-tooltip-title">Scoped label</span><br />${description}`;
    },
    showScopedLabels(label) {
      return this.enableScopedLabels && isScopedLabel(label);
    },
  },
};
</script>

<template>
  <div
    :class="{
      'has-labels': !isEmpty,
    }"
    class="hide-collapsed value issuable-show-labels js-value"
  >
    <span v-if="isEmpty" class="text-secondary">
      <slot>{{ __('None') }}</slot>
    </span>

    <template v-for="label in labels" v-else>
      <gl-label
        :key="label.id"
        :target="labelFilterUrl(label)"
        :background-color="label.color"
        :title="label.title"
        :description="label.description"
        :scoped="showScopedLabels(label)"
        :scoped-labels-documentation-link="scopedLabelsDocumentationLink"
      />
    </template>
  </div>
</template>