diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-22 12:08:53 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-22 12:08:53 +0300 |
commit | 4dff02cf71591bd7ab47e44f3e1f2206f61c06eb (patch) | |
tree | 70a7286bbc624c264a06c6693f5e94ebede93dd0 /app/assets/javascripts/search | |
parent | 16e3c34cac856092627cc41a8a9d9c69f3b26c03 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/search')
7 files changed, 97 insertions, 26 deletions
diff --git a/app/assets/javascripts/search/highlight_blob_search_result.js b/app/assets/javascripts/search/highlight_blob_search_result.js index 3c3ac3582d0..c553d5b14a0 100644 --- a/app/assets/javascripts/search/highlight_blob_search_result.js +++ b/app/assets/javascripts/search/highlight_blob_search_result.js @@ -1,7 +1,7 @@ -export default () => { +export default (search = '') => { const highlightLineClass = 'hll'; const contentBody = document.getElementById('content-body'); - const searchTerm = contentBody.querySelector('.js-search-input').value.toLowerCase(); + const searchTerm = search.toLowerCase(); const blobs = contentBody.querySelectorAll('.blob-result'); blobs.forEach((blob) => { diff --git a/app/assets/javascripts/search/index.js b/app/assets/javascripts/search/index.js index d2bb1ccfc44..0674bff2795 100644 --- a/app/assets/javascripts/search/index.js +++ b/app/assets/javascripts/search/index.js @@ -1,3 +1,6 @@ +import setHighlightClass from 'ee_else_ce/search/highlight_blob_search_result'; +import Project from '~/pages/projects/project'; +import refreshCounts from '~/pages/search/show/refresh_counts'; import { queryToObject } from '~/lib/utils/url_utility'; import createStore from './store'; import { initTopbar } from './topbar'; @@ -7,8 +10,14 @@ export const initSearchApp = () => { // Similar to url_utility.decodeUrlParameter // Our query treats + as %20. This replaces the query + symbols with %20. const sanitizedSearch = window.location.search.replace(/\+/g, '%20'); - const store = createStore({ query: queryToObject(sanitizedSearch) }); + const query = queryToObject(sanitizedSearch); + + const store = createStore({ query }); initTopbar(store); initSidebar(store); + + setHighlightClass(query.search); // Code Highlighting + refreshCounts(); // Other Scope Tab Counts + Project.initRefSwitcher(); // Code Search Branch Picker }; diff --git a/app/assets/javascripts/search/topbar/components/app.vue b/app/assets/javascripts/search/topbar/components/app.vue new file mode 100644 index 00000000000..8c9c4e58722 --- /dev/null +++ b/app/assets/javascripts/search/topbar/components/app.vue @@ -0,0 +1,73 @@ +<script> +import { mapState, mapActions } from 'vuex'; +import { GlForm, GlSearchBoxByType, GlButton } from '@gitlab/ui'; +import GroupFilter from './group_filter.vue'; +import ProjectFilter from './project_filter.vue'; + +export default { + name: 'GlobalSearchTopbar', + components: { + GlForm, + GlSearchBoxByType, + GroupFilter, + ProjectFilter, + GlButton, + }, + props: { + groupInitialData: { + type: Object, + required: false, + default: () => ({}), + }, + projectInitialData: { + type: Object, + required: false, + default: () => ({}), + }, + }, + computed: { + ...mapState(['query']), + search: { + get() { + return this.query ? this.query.search : ''; + }, + set(value) { + this.setQuery({ key: 'search', value }); + }, + }, + showFilters() { + return !this.query.snippets || this.query.snippets === 'false'; + }, + }, + methods: { + ...mapActions(['applyQuery', 'setQuery']), + }, +}; +</script> + +<template> + <gl-form class="search-page-form" @submit.prevent="applyQuery"> + <section class="gl-display-lg-flex gl-align-items-flex-end"> + <div class="gl-flex-fill-1 gl-mb-4 gl-lg-mb-0 gl-lg-mr-2"> + <label>{{ __('What are you searching for?') }}</label> + <gl-search-box-by-type + id="dashboard_search" + v-model="search" + name="search" + :placeholder="__(`Search for projects, issues, etc.`)" + /> + </div> + <div v-if="showFilters" class="gl-mb-4 gl-lg-mb-0 gl-lg-mx-2"> + <label class="gl-display-block">{{ __('Group') }}</label> + <group-filter :initial-data="groupInitialData" /> + </div> + <div v-if="showFilters" class="gl-mb-4 gl-lg-mb-0 gl-lg-mx-2"> + <label class="gl-display-block">{{ __('Project') }}</label> + <project-filter :initial-data="projectInitialData" /> + </div> + <gl-button class="btn-search gl-lg-ml-2" variant="success" type="submit">{{ + __('Search') + }}</gl-button> + </section> + </gl-form> +</template> diff --git a/app/assets/javascripts/search/topbar/components/group_filter.vue b/app/assets/javascripts/search/topbar/components/group_filter.vue index fce9ec17d23..efd753270f6 100644 --- a/app/assets/javascripts/search/topbar/components/group_filter.vue +++ b/app/assets/javascripts/search/topbar/components/group_filter.vue @@ -37,6 +37,7 @@ export default { <template> <searchable-dropdown + data-testid="group-filter" :header-text="$options.GROUP_DATA.headerText" :selected-display-value="$options.GROUP_DATA.selectedDisplayValue" :items-display-value="$options.GROUP_DATA.itemsDisplayValue" diff --git a/app/assets/javascripts/search/topbar/components/project_filter.vue b/app/assets/javascripts/search/topbar/components/project_filter.vue index effaafb72c1..52d5073cb07 100644 --- a/app/assets/javascripts/search/topbar/components/project_filter.vue +++ b/app/assets/javascripts/search/topbar/components/project_filter.vue @@ -40,6 +40,7 @@ export default { <template> <searchable-dropdown + data-testid="project-filter" :header-text="$options.PROJECT_DATA.headerText" :selected-display-value="$options.PROJECT_DATA.selectedDisplayValue" :items-display-value="$options.PROJECT_DATA.itemsDisplayValue" diff --git a/app/assets/javascripts/search/topbar/components/searchable_dropdown.vue b/app/assets/javascripts/search/topbar/components/searchable_dropdown.vue index 14577fd7d7a..5fb7217db74 100644 --- a/app/assets/javascripts/search/topbar/components/searchable_dropdown.vue +++ b/app/assets/javascripts/search/topbar/components/searchable_dropdown.vue @@ -101,7 +101,7 @@ export default { @keydown.enter.stop="resetDropdown" @click.stop="resetDropdown" > - <gl-icon name="clear" class="gl-text-gray-200! gl-hover-text-blue-800!" /> + <gl-icon name="clear" /> </gl-button> <gl-icon name="chevron-down" /> </template> diff --git a/app/assets/javascripts/search/topbar/index.js b/app/assets/javascripts/search/topbar/index.js index f0308109b32..87316e10e8d 100644 --- a/app/assets/javascripts/search/topbar/index.js +++ b/app/assets/javascripts/search/topbar/index.js @@ -1,44 +1,31 @@ import Vue from 'vue'; import Translate from '~/vue_shared/translate'; -import GroupFilter from './components/group_filter.vue'; -import ProjectFilter from './components/project_filter.vue'; +import GlobalSearchTopbar from './components/app.vue'; Vue.use(Translate); -const mountSearchableDropdown = (store, { id, component }) => { - const el = document.getElementById(id); +export const initTopbar = (store) => { + const el = document.getElementById('js-search-topbar'); if (!el) { return false; } - let { initialData } = el.dataset; + let { groupInitialData, projectInitialData } = el.dataset; - initialData = JSON.parse(initialData); + groupInitialData = JSON.parse(groupInitialData); + projectInitialData = JSON.parse(projectInitialData); return new Vue({ el, store, render(createElement) { - return createElement(component, { + return createElement(GlobalSearchTopbar, { props: { - initialData, + groupInitialData, + projectInitialData, }, }); }, }); }; - -const searchableDropdowns = [ - { - id: 'js-search-group-dropdown', - component: GroupFilter, - }, - { - id: 'js-search-project-dropdown', - component: ProjectFilter, - }, -]; - -export const initTopbar = (store) => - searchableDropdowns.map((dropdown) => mountSearchableDropdown(store, dropdown)); |