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

scope_navigation.vue « components « sidebar « search « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f5e1525090ef5fe3533434a8700c9d266d518a42 (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
<script>
import { GlNav, GlNavItem } from '@gitlab/ui';
import { mapActions, mapState } from 'vuex';
import { formatNumber } from '~/locale';
import Tracking from '~/tracking';
import { NAV_LINK_DEFAULT_CLASSES, NUMBER_FORMATING_OPTIONS } from '../constants';

export default {
  name: 'ScopeNavigation',
  components: {
    GlNav,
    GlNavItem,
  },
  mixins: [Tracking.mixin()],
  computed: {
    ...mapState(['navigation', 'urlQuery']),
  },
  created() {
    this.fetchSidebarCount();
  },
  methods: {
    ...mapActions(['fetchSidebarCount']),
    activeClasses(currentScope) {
      return currentScope === this.urlQuery.scope ? 'gl-font-weight-bold' : '';
    },
    showFormatedCount(count) {
      if (!count) {
        return '0';
      }
      const countNumber = parseInt(count.replace(/,/g, ''), 10);
      return formatNumber(countNumber, NUMBER_FORMATING_OPTIONS);
    },
    handleClick(scope) {
      this.track('click_menu_item', { label: `vertical_navigation_${scope}` });
    },
    linkClasses(scope) {
      return [
        { 'gl-font-weight-bold': scope === this.urlQuery.scope },
        ...this.$options.NAV_LINK_DEFAULT_CLASSES,
      ];
    },
  },
  NAV_LINK_DEFAULT_CLASSES,
};
</script>

<template>
  <nav data-testid="search-filter">
    <gl-nav vertical pills>
      <gl-nav-item
        v-for="(item, scope, index) in navigation"
        :key="scope"
        :link-classes="linkClasses(scope)"
        class="gl-mb-1"
        :href="item.link"
        :active="urlQuery.scope ? urlQuery.scope === scope : index === 0"
        @click="handleClick(scope)"
        ><span>{{ item.label }}</span
        ><span v-if="item.count" class="gl-font-sm gl-font-weight-normal">
          {{ showFormatedCount(item.count) }}
        </span>
      </gl-nav-item>
    </gl-nav>
    <hr class="gl-mt-5 gl-mb-0 gl-border-gray-100 gl-md-display-none" />
  </nav>
</template>