All files / app/assets/javascripts/vue_shared/components/sidebar/labels_select_vue dropdown_value.vue

100% Statements 7/7
100% Branches 6/6
100% Functions 5/5
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  20x   20x   20x                                           20x         15x         16x           95x                                                        
<script>
import { GlLabel } from '@gitlab/ui';
import { sortBy } from 'lodash';
import { mapState } from 'vuex';
 
import { isScopedLabel } from '~/lib/utils/common_utils';
 
export default {
  components: {
    GlLabel,
  },
  props: {
    disableLabels: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  computed: {
    ...mapState([
      'selectedLabels',
      'allowLabelRemove',
      'allowScopedLabels',
      'labelsFilterBasePath',
      'labelsFilterParam',
    ]),
    sortedSelectedLabels() {
      return sortBy(this.selectedLabels, (label) => (isScopedLabel(label) ? 0 : 1));
    },
  },
  methods: {
    labelFilterUrl(label) {
      return `${this.labelsFilterBasePath}?${this.labelsFilterParam}[]=${encodeURIComponent(
        label.title,
      )}`;
    },
    scopedLabel(label) {
      return this.allowScopedLabels && isScopedLabel(label);
    },
  },
};
</script>
 
<template>
  <div
    :class="{
      'has-labels': selectedLabels.length,
    }"
    class="hide-collapsed value issuable-show-labels js-value"
  >
    <span v-if="!selectedLabels.length" class="text-secondary">
      <slot></slot>
    </span>
    <template v-for="label in sortedSelectedLabels" v-else>
      <gl-label
        :key="label.id"
        data-qa-selector="selected_label_content"
        :data-qa-label-name="label.title"
        :title="label.title"
        :description="label.description"
        :background-color="label.color"
        :target="labelFilterUrl(label)"
        :scoped="scopedLabel(label)"
        :show-close-button="allowLabelRemove"
        :disabled="disableLabels"
        tooltip-placement="top"
        @close="$emit('onLabelRemove', label.id)"
      />
    </template>
  </div>
</template>