debian-mirror-gitlab/app/assets/javascripts/super_sidebar/components/context_switcher.vue

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

138 lines
3.5 KiB
Vue
Raw Normal View History

2023-03-17 16:20:25 +05:30
<script>
2023-05-27 22:25:52 +05:30
import * as Sentry from '@sentry/browser';
import { GlSearchBoxByType } from '@gitlab/ui';
2023-03-17 16:20:25 +05:30
import { s__ } from '~/locale';
2023-05-27 22:25:52 +05:30
import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants';
import searchUserProjectsAndGroups from '../graphql/queries/search_user_groups_and_projects.query.graphql';
2023-03-17 16:20:25 +05:30
import { contextSwitcherItems } from '../mock_data';
2023-05-27 22:25:52 +05:30
import { trackContextAccess, formatContextSwitcherItems } from '../utils';
2023-03-17 16:20:25 +05:30
import NavItem from './nav_item.vue';
2023-05-27 22:25:52 +05:30
import ProjectsList from './projects_list.vue';
import GroupsList from './groups_list.vue';
2023-03-17 16:20:25 +05:30
export default {
2023-05-27 22:25:52 +05:30
i18n: {
contextNavigation: s__('Navigation|Context navigation'),
switchTo: s__('Navigation|Switch to...'),
searchPlaceholder: s__('Navigation|Search for projects or groups'),
},
apollo: {
groupsAndProjects: {
query: searchUserProjectsAndGroups,
debounce: DEFAULT_DEBOUNCE_AND_THROTTLE_MS,
manual: true,
variables() {
return {
username: this.username,
search: this.searchString,
};
},
result(response) {
try {
const {
data: {
projects: { nodes: projects },
user: {
groups: { nodes: groups },
},
},
} = response;
this.projects = formatContextSwitcherItems(projects);
this.groups = formatContextSwitcherItems(groups);
} catch (e) {
Sentry.captureException(e);
}
},
error(e) {
Sentry.captureException(e);
},
skip() {
return !this.searchString;
},
},
},
2023-03-17 16:20:25 +05:30
components: {
GlSearchBoxByType,
NavItem,
2023-05-27 22:25:52 +05:30
ProjectsList,
GroupsList,
2023-03-17 16:20:25 +05:30
},
2023-05-27 22:25:52 +05:30
props: {
username: {
type: String,
required: true,
},
projectsPath: {
type: String,
required: true,
},
groupsPath: {
type: String,
required: true,
},
currentContext: {
type: Object,
required: false,
default: () => ({}),
},
2023-03-17 16:20:25 +05:30
},
2023-05-27 22:25:52 +05:30
data() {
return {
searchString: '',
projects: [],
groups: [],
};
2023-03-17 16:20:25 +05:30
},
2023-05-27 22:25:52 +05:30
computed: {
isSearch() {
return Boolean(this.searchString);
},
},
contextSwitcherItems,
created() {
if (this.currentContext.namespace) {
trackContextAccess(this.username, this.currentContext);
}
2023-03-17 16:20:25 +05:30
},
};
</script>
<template>
<div>
2023-05-27 22:25:52 +05:30
<div class="gl-p-1 gl-border-b gl-border-gray-50 gl-bg-white">
<gl-search-box-by-type
v-model="searchString"
class="context-switcher-search-box"
:placeholder="$options.i18n.searchPlaceholder"
borderless
/>
</div>
2023-03-17 16:20:25 +05:30
<nav :aria-label="$options.i18n.contextNavigation">
<ul class="gl-p-0 gl-list-style-none">
2023-05-27 22:25:52 +05:30
<li v-if="!isSearch">
2023-03-17 16:20:25 +05:30
<div aria-hidden="true" class="gl-font-weight-bold gl-px-3 gl-py-3">
{{ $options.i18n.switchTo }}
</div>
<ul :aria-label="$options.i18n.switchTo" class="gl-p-0">
<nav-item :item="$options.contextSwitcherItems.yourWork" />
2023-05-27 22:25:52 +05:30
<nav-item :item="$options.contextSwitcherItems.explore" />
2023-03-17 16:20:25 +05:30
</ul>
</li>
2023-05-27 22:25:52 +05:30
<projects-list
:username="username"
:view-all-link="projectsPath"
:is-search="isSearch"
:search-results="projects"
/>
<groups-list
:username="username"
:view-all-link="groupsPath"
:is-search="isSearch"
:search-results="groups"
/>
2023-03-17 16:20:25 +05:30
</ul>
</nav>
</div>
</template>