diff options
Diffstat (limited to 'app/assets/javascripts/search/topbar/components')
4 files changed, 80 insertions, 5 deletions
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..987735ed811 --- /dev/null +++ b/app/assets/javascripts/search/topbar/components/app.vue @@ -0,0 +1,73 @@ +<script> +import { GlForm, GlSearchBoxByType, GlButton } from '@gitlab/ui'; +import { mapState, mapActions } from 'vuex'; +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-lg-display-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..2acab4e805d 100644 --- a/app/assets/javascripts/search/topbar/components/group_filter.vue +++ b/app/assets/javascripts/search/topbar/components/group_filter.vue @@ -1,9 +1,9 @@ <script> -import { mapState, mapActions } from 'vuex'; import { isEmpty } from 'lodash'; +import { mapState, mapActions } from 'vuex'; import { visitUrl, setUrlParams } from '~/lib/utils/url_utility'; -import SearchableDropdown from './searchable_dropdown.vue'; import { ANY_OPTION, GROUP_DATA, PROJECT_DATA } from '../constants'; +import SearchableDropdown from './searchable_dropdown.vue'; export default { name: 'GroupFilter', @@ -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 3f1f3848ac7..b2dd79fcfa3 100644 --- a/app/assets/javascripts/search/topbar/components/project_filter.vue +++ b/app/assets/javascripts/search/topbar/components/project_filter.vue @@ -1,8 +1,8 @@ <script> import { mapState, mapActions } from 'vuex'; import { visitUrl, setUrlParams } from '~/lib/utils/url_utility'; -import SearchableDropdown from './searchable_dropdown.vue'; import { ANY_OPTION, GROUP_DATA, PROJECT_DATA } from '../constants'; +import SearchableDropdown from './searchable_dropdown.vue'; export default { name: 'ProjectFilter', @@ -27,7 +27,7 @@ export default { handleProjectChange(project) { // This determines if we need to update the group filter or not const queryParams = { - ...(project.namespace_id && { [GROUP_DATA.queryParam]: project.namespace_id }), + ...(project.namespace?.id && { [GROUP_DATA.queryParam]: project.namespace.id }), [PROJECT_DATA.queryParam]: project.id, }; @@ -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> |