All files / app/assets/javascripts/milestones/components milestone_results_section.vue

83.33% Statements 5/6
75% Branches 3/4
75% Functions 3/4
83.33% Lines 5/6

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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89  2x             2x                                                                                   62x         418x           1098x                                                      
<script>
import {
  GlDropdownSectionHeader,
  GlDropdownDivider,
  GlDropdownItem,
  GlBadge,
  GlIcon,
} from '@gitlab/ui';
import { s__ } from '~/locale';
 
export default {
  name: 'MilestoneResultsSection',
  components: {
    GlDropdownSectionHeader,
    GlDropdownDivider,
    GlDropdownItem,
    GlBadge,
    GlIcon,
  },
  props: {
    sectionTitle: {
      type: String,
      required: true,
    },
    totalCount: {
      type: Number,
      required: true,
    },
    items: {
      type: Array,
      required: true,
    },
    selectedMilestones: {
      type: Array,
      required: true,
      default: () => [],
    },
    error: {
      type: Error,
      required: false,
      default: null,
    },
    errorMessage: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    totalCountText() {
      return this.totalCount > 999 ? s__('TotalMilestonesIndicator|1000+') : `${this.totalCount}`;
    },
  },
  methods: {
    isSelectedMilestone(item) {
      return this.selectedMilestones.includes(item);
    },
  },
};
</script>
 
<template>
  <div>
    <gl-dropdown-section-header>
      <div
        class="gl-display-flex gl-align-items-center gl-pl-6"
        data-testid="milestone-results-section-header"
      >
        <span class="gl-mr-2 gl-mb-1">{{ sectionTitle }}</span>
        <gl-badge variant="neutral">{{ totalCountText }}</gl-badge>
      </div>
    </gl-dropdown-section-header>
    <template v-if="error">
      <div class="gl-display-flex align-items-start gl-text-red-500 gl-ml-4 gl-mr-4 gl-mb-3">
        <gl-icon name="error" class="gl-mr-2 gl-mt-2 gl-flex-shrink-0" />
        <span>{{ errorMessage }}</span>
      </div>
    </template>
    <template v-else>
      <gl-dropdown-item v-for="{ title } in items" :key="title" @click="$emit('selected', title)">
        <span class="gl-pl-6" :class="{ 'selected-item': isSelectedMilestone(title) }">
          {{ title }}
        </span>
      </gl-dropdown-item>
      <gl-dropdown-divider />
    </template>
  </div>
</template>