All files / app/assets/javascripts/search index.js

73.07% Statements 19/26
62.5% Branches 5/8
100% Functions 3/3
72% Lines 18/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                  1x 7x 7x                                             1x 7x   7x 7x             1x 7x 7x             7x   7x   7x                   7x 7x 7x   7x 7x    
import setHighlightClass from 'ee_else_ce/search/highlight_blob_search_result';
import { queryToObject } from '~/lib/utils/url_utility';
import syntaxHighlight from '~/syntax_highlight';
import { initSidebar } from './sidebar';
import { initSearchSort } from './sort';
import createStore from './store';
import { initTopbar } from './topbar';
import { initBlobRefSwitcher } from './under_topbar';
 
const sidebarInitState = () => {
  const el = document.getElementById('js-search-sidebar');
  Eif (!el) return {};
 
  const {
    navigationJson,
    searchType,
    searchLevel,
    groupInitialJson,
    projectInitialJson,
  } = el.dataset;
 
  const navigationJsonParsed = JSON.parse(navigationJson);
  const groupInitialJsonParsed = JSON.parse(groupInitialJson);
  const projectInitialJsonParsed = JSON.parse(projectInitialJson);
 
  return {
    navigationJsonParsed,
    searchType,
    searchLevel,
    groupInitialJsonParsed,
    projectInitialJsonParsed,
  };
};
 
const topBarInitState = () => {
  const el = document.getElementById('js-search-topbar');
 
  Eif (!el) {
    return false;
  }
 
  const { defaultBranchName } = el.dataset;
  return { defaultBranchName };
};
 
export const initSearchApp = () => {
  syntaxHighlight(document.querySelectorAll('.js-search-results'));
  const query = queryToObject(window.location.search, { gatherArrays: true });
  const {
    navigationJsonParsed: navigation,
    searchType,
    searchLevel,
    groupInitialJsonParsed: groupInitialJson,
    projectInitialJsonParsed: projectInitialJson,
  } = sidebarInitState() || {};
 
  const { defaultBranchName } = topBarInitState() || {};
 
  const store = createStore({
    query,
    navigation,
    searchType,
    searchLevel,
    groupInitialJson,
    projectInitialJson,
    defaultBranchName,
  });
 
  initTopbar(store);
  initSidebar(store);
  initSearchSort(store);
 
  setHighlightClass(query.search); // Code Highlighting
  initBlobRefSwitcher(); // Code Search Branch Picker
};