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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
import Vue from 'vue';
import { GlToast } from '@gitlab/ui';
import VueApollo from 'vue-apollo';
import { convertObjectPropsToCamelCase, parseBoolean } from '~/lib/utils/common_utils';
import createDefaultClient from '~/lib/graphql';
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(GlToast);
Vue.use(VueApollo);
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(),
});
const getTrialStatusWidgetData = (sidebarData) => {
if (sidebarData.trial_status_widget_data_attrs && sidebarData.trial_status_popover_data_attrs) {
const {
containerId,
trialDaysUsed,
trialDuration,
navIconImagePath,
percentageComplete,
planName,
plansHref,
} = convertObjectPropsToCamelCase(sidebarData.trial_status_widget_data_attrs);
const {
daysRemaining,
targetId,
trialEndDate,
namespaceId,
userName,
firstName,
lastName,
companyName,
glmContent,
createHandRaiseLeadPath,
trackAction,
trackLabel,
} = convertObjectPropsToCamelCase(sidebarData.trial_status_popover_data_attrs);
return {
showTrialStatusWidget: true,
containerId,
trialDaysUsed: Number(trialDaysUsed),
trialDuration: Number(trialDuration),
navIconImagePath,
percentageComplete: Number(percentageComplete),
planName,
plansHref,
daysRemaining,
targetId,
createHandRaiseLeadPath,
trackAction,
trackLabel,
trialEndDate: new Date(trialEndDate),
user: { namespaceId, userName, firstName, lastName, companyName, glmContent },
};
}
return { showTrialStatusWidget: false };
};
export const initSuperSidebar = () => {
const el = document.querySelector('.js-super-sidebar');
if (!el) return false;
const { rootPath, sidebar, forceDesktopExpandedSidebar, commandPalette } = el.dataset;
bindSuperSidebarCollapsedEvents(forceDesktopExpandedSidebar);
initSuperSidebarCollapsedState(parseBoolean(forceDesktopExpandedSidebar));
const sidebarData = JSON.parse(sidebar);
const searchData = convertObjectPropsToCamelCase(sidebarData.search);
const projectsPath = sidebarData.projects_path;
const groupsPath = sidebarData.groups_path;
const commandPaletteData = JSON.parse(commandPalette);
const projectFilesPath = commandPaletteData.project_files_url;
const projectBlobPath = commandPaletteData.project_blob_url;
const commandPaletteCommands = sidebarData.create_new_menu_groups || [];
const commandPaletteLinks = convertObjectPropsToCamelCase(sidebarData.current_menu_items || []);
const contextSwitcherLinks = sidebarData.context_switcher_links;
const { searchPath, issuesPath, mrPath, autocompletePath, searchContext } = searchData;
const isImpersonating = parseBoolean(sidebarData.is_impersonating);
return new Vue({
el,
name: 'SuperSidebarRoot',
apolloProvider,
provide: {
rootPath,
isImpersonating,
...getTrialStatusWidgetData(sidebarData),
commandPaletteCommands,
commandPaletteLinks,
contextSwitcherLinks,
autocompletePath,
searchContext,
projectFilesPath,
projectBlobPath,
projectsPath,
groupsPath,
},
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 });
},
});
};
|