debian-mirror-gitlab/app/assets/javascripts/super_sidebar/super_sidebar_bundle.js

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

88 lines
2.3 KiB
JavaScript
Raw Normal View History

2023-03-17 16:20:25 +05:30
import Vue from 'vue';
2023-05-27 22:25:52 +05:30
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
2023-06-20 00:43:36 +05:30
import { convertObjectPropsToCamelCase, parseBoolean } from '~/lib/utils/common_utils';
2023-05-27 22:25:52 +05:30
import { initStatusTriggers } from '../header';
2023-06-20 00:43:36 +05:30
import { JS_TOGGLE_EXPAND_CLASS } from './constants';
import createStore from './components/global_search/store';
2023-05-27 22:25:52 +05:30
import {
bindSuperSidebarCollapsedEvents,
initSuperSidebarCollapsedState,
} from './super_sidebar_collapsed_state_manager';
2023-03-17 16:20:25 +05:30
import SuperSidebar from './components/super_sidebar.vue';
2023-06-20 00:43:36 +05:30
import SuperSidebarToggle from './components/super_sidebar_toggle.vue';
2023-03-17 16:20:25 +05:30
2023-05-27 22:25:52 +05:30
Vue.use(VueApollo);
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(),
});
2023-03-17 16:20:25 +05:30
export const initSuperSidebar = () => {
const el = document.querySelector('.js-super-sidebar');
if (!el) return false;
2023-05-27 22:25:52 +05:30
bindSuperSidebarCollapsedEvents();
initSuperSidebarCollapsedState();
2023-03-17 16:20:25 +05:30
const { rootPath, sidebar, toggleNewNavEndpoint } = el.dataset;
2023-06-20 00:43:36 +05:30
const sidebarData = JSON.parse(sidebar);
const searchData = convertObjectPropsToCamelCase(sidebarData.search);
const { searchPath, issuesPath, mrPath, autocompletePath, searchContext } = searchData;
const isImpersonating = parseBoolean(sidebarData.is_impersonating);
2023-03-17 16:20:25 +05:30
return new Vue({
el,
name: 'SuperSidebarRoot',
2023-05-27 22:25:52 +05:30
apolloProvider,
2023-03-17 16:20:25 +05:30
provide: {
rootPath,
toggleNewNavEndpoint,
2023-06-20 00:43:36 +05:30
isImpersonating,
2023-03-17 16:20:25 +05:30
},
2023-06-20 00:43:36 +05:30
store: createStore({
searchPath,
issuesPath,
mrPath,
autocompletePath,
searchContext,
search: '',
}),
2023-03-17 16:20:25 +05:30
render(h) {
return h(SuperSidebar, {
props: {
2023-06-20 00:43:36 +05:30
sidebarData,
2023-03-17 16:20:25 +05:30
},
});
},
});
};
2023-05-27 22:25:52 +05:30
2023-06-20 00:43:36 +05:30
/**
* Guard against multiple instantiations, since the js-* class is persisted
* in the Vue component.
*/
let toggleInstantiated = false;
export const initSuperSidebarToggle = () => {
const el = document.querySelector(`.${JS_TOGGLE_EXPAND_CLASS}`);
if (!el || toggleInstantiated) return false;
toggleInstantiated = true;
return new Vue({
el,
name: 'SuperSidebarToggleRoot',
render(h) {
// Copy classes from HAML-defined button to ensure same positioning,
// including JS_TOGGLE_EXPAND_CLASS.
return h(SuperSidebarToggle, { class: el.className });
},
});
};
2023-05-27 22:25:52 +05:30
requestIdleCallback(initStatusTriggers);