All files / app/assets/javascripts/vue_shared/components/project_selector project_list_item.vue

100% Statements 6/6
100% Branches 4/4
100% Functions 6/6
100% Lines 6/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            5x                                       91x     91x     91x     101x         1x                                                                              
<script>
import { GlButton, GlIcon } from '@gitlab/ui';
import { isString } from 'lodash';
import highlight from '~/lib/utils/highlight';
import { truncateNamespace } from '~/lib/utils/text_utility';
import ProjectAvatar from '~/vue_shared/components/project_avatar.vue';
import SafeHtml from '~/vue_shared/directives/safe_html';
 
export default {
  name: 'ProjectListItem',
  components: { GlIcon, ProjectAvatar, GlButton },
  directives: { SafeHtml },
  props: {
    project: {
      type: Object,
      required: true,
      validator: (p) =>
        (Number.isFinite(p.id) || isString(p.id)) &&
        isString(p.name) &&
        (isString(p.name_with_namespace) || isString(p.nameWithNamespace)),
    },
    selected: { type: Boolean, required: true },
    matcher: { type: String, required: false, default: '' },
  },
  computed: {
    projectAvatarUrl() {
      return this.project.avatar_url || this.project.avatarUrl;
    },
    projectNameWithNamespace() {
      return this.project.nameWithNamespace || this.project.name_with_namespace;
    },
    truncatedNamespace() {
      return truncateNamespace(this.projectNameWithNamespace);
    },
    highlightedProjectName() {
      return highlight(this.project.name, this.matcher);
    },
  },
  methods: {
    onClick() {
      this.$emit('click');
    },
  },
};
</script>
<template>
  <gl-button
    category="tertiary"
    class="gl-display-flex gl-align-items-center gl-justify-content-start! gl-mb-2 gl-w-full"
    @click="onClick"
  >
    <div
      class="gl-display-flex gl-align-items-center gl-flex-wrap project-namespace-name-container"
    >
      <gl-icon v-if="selected" data-testid="selected-icon" name="mobile-issue-close" />
      <project-avatar
        :project-id="project.id"
        :project-avatar-url="projectAvatarUrl"
        :project-name="projectNameWithNamespace"
        class="gl-mr-3"
      />
      <div
        v-if="truncatedNamespace"
        data-testid="project-namespace"
        :title="projectNameWithNamespace"
        class="text-secondary text-truncate"
      >
        {{ truncatedNamespace }}
        <span v-if="truncatedNamespace" class="text-secondary">/&nbsp;</span>
      </div>
      <div
        v-safe-html="highlightedProjectName"
        data-testid="project-name"
        :title="project.name"
        class="text-truncate"
      ></div>
    </div>
  </gl-button>
</template>