debian-mirror-gitlab/app/assets/javascripts/search/sidebar/components/scope_navigation.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.5 KiB
Vue
Raw Normal View History

2023-01-13 00:05:48 +05:30
<script>
2023-03-04 22:38:38 +05:30
import { GlNav, GlNavItem, GlIcon } from '@gitlab/ui';
2023-01-13 00:05:48 +05:30
import { mapActions, mapState } from 'vuex';
2023-03-17 16:20:25 +05:30
import { s__ } from '~/locale';
2023-01-13 00:05:48 +05:30
import Tracking from '~/tracking';
2023-06-20 00:43:36 +05:30
import { formatSearchResultCount, addCountOverLimit } from '~/search/store/utils';
2023-03-17 16:20:25 +05:30
import { NAV_LINK_DEFAULT_CLASSES, NAV_LINK_COUNT_DEFAULT_CLASSES } from '../constants';
2023-04-23 21:23:45 +05:30
import { slugifyWithUnderscore } from '../../../lib/utils/text_utility';
2023-01-13 00:05:48 +05:30
export default {
name: 'ScopeNavigation',
2023-03-04 22:38:38 +05:30
i18n: {
countOverLimitLabel: s__('GlobalSearch|Result count is over limit.'),
},
2023-01-13 00:05:48 +05:30
components: {
GlNav,
GlNavItem,
2023-03-04 22:38:38 +05:30
GlIcon,
2023-01-13 00:05:48 +05:30
},
mixins: [Tracking.mixin()],
computed: {
...mapState(['navigation', 'urlQuery']),
},
created() {
2023-06-20 00:43:36 +05:30
if (this.urlQuery?.search) {
this.fetchSidebarCount();
}
2023-01-13 00:05:48 +05:30
},
methods: {
...mapActions(['fetchSidebarCount']),
2023-06-20 00:43:36 +05:30
showFormatedCount(countString) {
return formatSearchResultCount(countString);
2023-01-13 00:05:48 +05:30
},
2023-06-20 00:43:36 +05:30
isCountOverLimit(countString) {
return Boolean(addCountOverLimit(countString));
2023-03-04 22:38:38 +05:30
},
2023-01-13 00:05:48 +05:30
handleClick(scope) {
this.track('click_menu_item', { label: `vertical_navigation_${scope}` });
},
2023-03-04 22:38:38 +05:30
linkClasses(isHighlighted) {
return [...this.$options.NAV_LINK_DEFAULT_CLASSES, { 'gl-font-weight-bold': isHighlighted }];
},
countClasses(isHighlighted) {
2023-01-13 00:05:48 +05:30
return [
2023-03-04 22:38:38 +05:30
...this.$options.NAV_LINK_COUNT_DEFAULT_CLASSES,
isHighlighted ? 'gl-text-gray-900' : 'gl-text-gray-500',
2023-01-13 00:05:48 +05:30
];
},
2023-04-23 21:23:45 +05:30
qaSelectorValue(item) {
return `${slugifyWithUnderscore(item.label)}_tab`;
},
2023-01-13 00:05:48 +05:30
},
NAV_LINK_DEFAULT_CLASSES,
2023-03-04 22:38:38 +05:30
NAV_LINK_COUNT_DEFAULT_CLASSES,
2023-01-13 00:05:48 +05:30
};
</script>
<template>
<nav data-testid="search-filter">
<gl-nav vertical pills>
<gl-nav-item
2023-05-27 22:25:52 +05:30
v-for="(item, scope) in navigation"
2023-01-13 00:05:48 +05:30
:key="scope"
2023-05-27 22:25:52 +05:30
:link-classes="linkClasses(item.active)"
2023-01-13 00:05:48 +05:30
class="gl-mb-1"
:href="item.link"
2023-05-27 22:25:52 +05:30
:active="item.active"
2023-04-23 21:23:45 +05:30
:data-qa-selector="qaSelectorValue(item)"
2023-05-27 22:25:52 +05:30
:data-testid="qaSelectorValue(item)"
2023-01-13 00:05:48 +05:30
@click="handleClick(scope)"
2023-05-27 22:25:52 +05:30
><span data-testid="label">{{ item.label }}</span
><span v-if="item.count" data-testid="count" :class="countClasses(item.active)">
2023-03-04 22:38:38 +05:30
{{ showFormatedCount(item.count)
}}<gl-icon
v-if="isCountOverLimit(item.count)"
name="plus"
:aria-label="$options.i18n.countOverLimitLabel"
:size="8"
/>
2023-01-13 00:05:48 +05:30
</span>
</gl-nav-item>
</gl-nav>
2023-03-17 16:20:25 +05:30
<hr class="gl-mt-5 gl-mx-5 gl-mb-0 gl-border-gray-100 gl-md-display-none" />
2023-01-13 00:05:48 +05:30
</nav>
</template>