debian-mirror-gitlab/app/assets/javascripts/header_search/index.js

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

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-11-11 11:23:49 +05:30
import Vue from 'vue';
2023-04-23 21:23:45 +05:30
import * as Sentry from '@sentry/browser';
2021-11-11 11:23:49 +05:30
import Translate from '~/vue_shared/translate';
import HeaderSearchApp from './components/app.vue';
import createStore from './store';
2023-04-23 21:23:45 +05:30
import { SEARCH_INPUT_FIELD_MAX_WIDTH } from './constants';
2021-11-11 11:23:49 +05:30
Vue.use(Translate);
2022-05-07 20:08:51 +05:30
export const initHeaderSearchApp = (search = '') => {
2021-11-11 11:23:49 +05:30
const el = document.getElementById('js-header-search');
2023-04-23 21:23:45 +05:30
const headerEl = document.querySelector('.header-content');
2021-11-11 11:23:49 +05:30
2023-04-23 21:23:45 +05:30
if (!el && !headerEl) {
2021-11-11 11:23:49 +05:30
return false;
}
2023-04-23 21:23:45 +05:30
const searchContainer = headerEl.querySelector('.global-search-container');
const newHeader = headerEl.querySelector('.header-search-new');
2021-11-18 22:05:49 +05:30
const { searchPath, issuesPath, mrPath, autocompletePath } = el.dataset;
2021-11-11 11:23:49 +05:30
let { searchContext } = el.dataset;
2023-04-23 21:23:45 +05:30
try {
searchContext = JSON.parse(searchContext);
newHeader.style.maxWidth = SEARCH_INPUT_FIELD_MAX_WIDTH;
} catch (error) {
Sentry.captureException(error);
}
2021-11-11 11:23:49 +05:30
return new Vue({
el,
2022-05-07 20:08:51 +05:30
store: createStore({ searchPath, issuesPath, mrPath, autocompletePath, searchContext, search }),
2021-11-11 11:23:49 +05:30
render(createElement) {
2022-07-16 23:28:13 +05:30
return createElement(HeaderSearchApp, {
on: {
2022-08-27 11:52:29 +05:30
expandSearchBar: () => {
2023-04-23 21:23:45 +05:30
searchContainer.style.flexGrow = '1';
2022-08-27 11:52:29 +05:30
},
collapseSearchBar: () => {
2023-04-23 21:23:45 +05:30
searchContainer.style.flexGrow = '0';
2022-07-16 23:28:13 +05:30
},
},
});
2021-11-11 11:23:49 +05:30
},
});
};