87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
import Vue from 'vue';
|
|
import VueApollo from 'vue-apollo';
|
|
import createDefaultClient from '~/lib/graphql';
|
|
import { convertObjectPropsToCamelCase, parseBoolean } from '~/lib/utils/common_utils';
|
|
import { initStatusTriggers } from '../header';
|
|
import { JS_TOGGLE_EXPAND_CLASS } from './constants';
|
|
import createStore from './components/global_search/store';
|
|
import {
|
|
bindSuperSidebarCollapsedEvents,
|
|
initSuperSidebarCollapsedState,
|
|
} from './super_sidebar_collapsed_state_manager';
|
|
import SuperSidebar from './components/super_sidebar.vue';
|
|
import SuperSidebarToggle from './components/super_sidebar_toggle.vue';
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
const apolloProvider = new VueApollo({
|
|
defaultClient: createDefaultClient(),
|
|
});
|
|
|
|
export const initSuperSidebar = () => {
|
|
const el = document.querySelector('.js-super-sidebar');
|
|
|
|
if (!el) return false;
|
|
|
|
bindSuperSidebarCollapsedEvents();
|
|
initSuperSidebarCollapsedState();
|
|
|
|
const { rootPath, sidebar, toggleNewNavEndpoint } = el.dataset;
|
|
const sidebarData = JSON.parse(sidebar);
|
|
const searchData = convertObjectPropsToCamelCase(sidebarData.search);
|
|
|
|
const { searchPath, issuesPath, mrPath, autocompletePath, searchContext } = searchData;
|
|
const isImpersonating = parseBoolean(sidebarData.is_impersonating);
|
|
|
|
return new Vue({
|
|
el,
|
|
name: 'SuperSidebarRoot',
|
|
apolloProvider,
|
|
provide: {
|
|
rootPath,
|
|
toggleNewNavEndpoint,
|
|
isImpersonating,
|
|
},
|
|
store: createStore({
|
|
searchPath,
|
|
issuesPath,
|
|
mrPath,
|
|
autocompletePath,
|
|
searchContext,
|
|
search: '',
|
|
}),
|
|
render(h) {
|
|
return h(SuperSidebar, {
|
|
props: {
|
|
sidebarData,
|
|
},
|
|
});
|
|
},
|
|
});
|
|
};
|
|
|
|
/**
|
|
* 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 });
|
|
},
|
|
});
|
|
};
|
|
|
|
requestIdleCallback(initStatusTriggers);
|