All files / app/assets/javascripts/confidential_merge_request/components dropdown.vue

87.5% Statements 7/8
100% Branches 2/2
75% Functions 3/4
87.5% Lines 7/8

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  4x 4x                             2x         3x 1x     2x                     23x                          
<script>
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { __ } from '~/locale';
 
export default {
  components: {
    GlDropdown,
    GlDropdownItem,
  },
  props: {
    projects: {
      type: Array,
      required: true,
    },
    selectedProject: {
      type: Object,
      required: false,
      default: () => ({}),
    },
  },
  computed: {
    dropdownText() {
      if (Object.keys(this.selectedProject).length) {
        return this.selectedProject.name;
      }
 
      return __('Select private project');
    },
  },
  methods: {
    selectProject(project) {
      this.$emit('click', project);
    },
  },
};
</script>
 
<template>
  <gl-dropdown block icon="lock" :text="dropdownText">
    <gl-dropdown-item
      v-for="project in projects"
      :key="project.id"
      :is-check-item="true"
      :is-checked="project.id === selectedProject.id"
      @click="selectProject(project)"
    >
      {{ project.name }}
    </gl-dropdown-item>
  </gl-dropdown>
</template>