Welcome to mirror list, hosted at ThFree Co, Russian Federation.

frequent_items_list_item.vue « components « frequent_items « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 75ea9beb5cf27cfc6fc316e9637306bf010dd276 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<script>
import { GlButton, GlTooltipDirective, GlIcon } from '@gitlab/ui';
import { snakeCase } from 'lodash';
import SafeHtml from '~/vue_shared/directives/safe_html';
import highlight from '~/lib/utils/highlight';
import { truncateNamespace } from '~/lib/utils/text_utility';
import { mapVuexModuleState, mapVuexModuleActions } from '~/lib/utils/vuex_module_mappers';
import Tracking from '~/tracking';
import ProjectAvatar from '~/vue_shared/components/project_avatar.vue';

const trackingMixin = Tracking.mixin();

export default {
  components: {
    GlIcon,
    GlButton,
    ProjectAvatar,
  },
  directives: {
    SafeHtml,
    GlTooltip: GlTooltipDirective,
  },
  mixins: [trackingMixin],
  inject: ['vuexModule'],
  props: {
    matcher: {
      type: String,
      required: false,
      default: '',
    },
    itemId: {
      type: Number,
      required: true,
    },
    itemName: {
      type: String,
      required: true,
    },
    namespace: {
      type: String,
      required: false,
      default: '',
    },
    webUrl: {
      type: String,
      required: true,
    },
    avatarUrl: {
      required: true,
      validator(value) {
        return value === null || typeof value === 'string';
      },
    },
  },
  computed: {
    ...mapVuexModuleState((vm) => vm.vuexModule, ['dropdownType', 'isItemsListEditable']),
    truncatedNamespace() {
      return truncateNamespace(this.namespace);
    },
    highlightedItemName() {
      return highlight(this.itemName, this.matcher);
    },
    itemTrackingLabel() {
      return `${this.dropdownType}_dropdown_frequent_items_list_item_${snakeCase(this.itemName)}`;
    },
  },
  methods: {
    ...mapVuexModuleActions((vm) => vm.vuexModule, ['removeFrequentItem']),
  },
};
</script>

<template>
  <li class="frequent-items-list-item-container gl-relative">
    <gl-button
      category="tertiary"
      :href="webUrl"
      class="gl-text-left gl-w-full"
      button-text-classes="gl-display-flex gl-w-full"
      data-testid="frequent-item-link"
      @click="track('click_link', { label: itemTrackingLabel })"
    >
      <div class="gl-flex-grow-1">
        <project-avatar
          class="gl-float-left gl-mr-3"
          :project-avatar-url="avatarUrl"
          :project-id="itemId"
          :project-name="itemName"
          aria-hidden="true"
        />
        <div
          data-testid="frequent-items-item-metadata-container"
          class="frequent-items-item-metadata-container"
        >
          <div
            v-safe-html="highlightedItemName"
            data-testid="frequent-items-item-title"
            :title="itemName"
            class="frequent-items-item-title"
          ></div>
          <div
            v-if="namespace"
            data-testid="frequent-items-item-namespace"
            :title="namespace"
            class="frequent-items-item-namespace"
          >
            {{ truncatedNamespace }}
          </div>
        </div>
      </div>
    </gl-button>
    <gl-button
      v-if="isItemsListEditable"
      v-gl-tooltip.left
      size="small"
      category="tertiary"
      :aria-label="__('Remove')"
      :title="__('Remove')"
      class="gl-align-self-center gl-p-1! gl-absolute! gl-w-auto! gl-top-4 gl-right-4"
      data-testid="item-remove"
      @click.stop.prevent="removeFrequentItem(itemId)"
    >
      <gl-icon name="close" />
    </gl-button>
  </li>
</template>