debian-mirror-gitlab/app/assets/javascripts/search/topbar/components/app.vue

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

131 lines
4 KiB
Vue
Raw Normal View History

2021-03-11 19:13:27 +05:30
<script>
2023-03-04 22:38:38 +05:30
import { GlSearchBoxByClick, GlButton } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mapState, mapActions } from 'vuex';
2022-05-07 20:08:51 +05:30
import { s__ } from '~/locale';
2022-11-25 23:54:43 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
2023-03-04 22:38:38 +05:30
import MarkdownDrawer from '~/vue_shared/components/markdown_drawer/markdown_drawer.vue';
import { SYNTAX_OPTIONS_DOCUMENT } from '../constants';
2021-03-11 19:13:27 +05:30
import GroupFilter from './group_filter.vue';
import ProjectFilter from './project_filter.vue';
export default {
name: 'GlobalSearchTopbar',
2022-05-07 20:08:51 +05:30
i18n: {
searchPlaceholder: s__(`GlobalSearch|Search for projects, issues, etc.`),
searchLabel: s__(`GlobalSearch|What are you searching for?`),
2023-03-04 22:38:38 +05:30
documentFetchErrorMessage: s__(
'GlobalSearch|There was an error fetching the "Syntax Options" document.',
),
searchFieldLabel: s__('GlobalSearch|What are you searching for?'),
syntaxOptionsLabel: s__('GlobalSearch|Syntax options'),
groupFieldLabel: s__('GlobalSearch|Group'),
projectFieldLabel: s__('GlobalSearch|Project'),
searchButtonLabel: s__('GlobalSearch|Search'),
closeButtonLabel: s__('GlobalSearch|Close'),
2022-05-07 20:08:51 +05:30
},
2021-03-11 19:13:27 +05:30
components: {
2023-03-04 22:38:38 +05:30
GlButton,
2022-05-07 20:08:51 +05:30
GlSearchBoxByClick,
2021-03-11 19:13:27 +05:30
GroupFilter,
ProjectFilter,
2023-03-04 22:38:38 +05:30
MarkdownDrawer,
2021-03-11 19:13:27 +05:30
},
props: {
2023-03-04 22:38:38 +05:30
groupInitialJson: {
2021-03-11 19:13:27 +05:30
type: Object,
required: false,
default: () => ({}),
},
2023-03-04 22:38:38 +05:30
projectInitialJson: {
2021-03-11 19:13:27 +05:30
type: Object,
required: false,
default: () => ({}),
},
2023-03-04 22:38:38 +05:30
elasticsearchEnabled: {
type: Boolean,
required: false,
default: false,
},
defaultBranchName: {
type: String,
required: false,
default: '',
},
2021-03-11 19:13:27 +05:30
},
computed: {
...mapState(['query']),
search: {
get() {
return this.query ? this.query.search : '';
},
set(value) {
this.setQuery({ key: 'search', value });
},
},
showFilters() {
2022-11-25 23:54:43 +05:30
return !parseBoolean(this.query.snippets);
},
2023-03-04 22:38:38 +05:30
showSyntaxOptions() {
return this.elasticsearchEnabled && this.isDefaultBranch;
},
isDefaultBranch() {
return !this.query.repository_ref || this.query.repository_ref === this.defaultBranchName;
},
2021-03-11 19:13:27 +05:30
},
2021-10-27 15:23:28 +05:30
created() {
this.preloadStoredFrequentItems();
},
2021-03-11 19:13:27 +05:30
methods: {
2021-10-27 15:23:28 +05:30
...mapActions(['applyQuery', 'setQuery', 'preloadStoredFrequentItems']),
2023-03-04 22:38:38 +05:30
onToggleDrawer() {
this.$refs.markdownDrawer.toggleDrawer();
},
2021-03-11 19:13:27 +05:30
},
2023-03-04 22:38:38 +05:30
SYNTAX_OPTIONS_DOCUMENT,
2021-03-11 19:13:27 +05:30
};
</script>
<template>
2022-11-25 23:54:43 +05:30
<section class="search-page-form gl-lg-display-flex gl-flex-direction-column">
<div class="gl-lg-display-flex gl-flex-direction-row gl-align-items-flex-end">
<div class="gl-flex-grow-1 gl-mb-4 gl-lg-mb-0 gl-lg-mr-2">
2023-03-04 22:38:38 +05:30
<div
class="gl-sm-display-flex gl-flex-direction-row gl-justify-content-space-between gl-mb-4 gl-md-mb-0"
>
<label>{{ $options.i18n.searchLabel }}</label>
<template v-if="showSyntaxOptions">
<gl-button
category="tertiary"
variant="link"
size="small"
button-text-classes="gl-font-sm!"
@click="onToggleDrawer"
>{{ $options.i18n.syntaxOptionsLabel }}
</gl-button>
<markdown-drawer
ref="markdownDrawer"
:document-path="$options.SYNTAX_OPTIONS_DOCUMENT"
/>
</template>
</div>
2022-11-25 23:54:43 +05:30
<gl-search-box-by-click
id="dashboard_search"
v-model="search"
name="search"
:placeholder="$options.i18n.searchPlaceholder"
@submit="applyQuery"
/>
</div>
2023-03-04 22:38:38 +05:30
<div v-if="showFilters" class="gl-mb-4 gl-lg-mb-0 gl-lg-mx-3">
<label class="gl-display-block">{{ $options.i18n.groupFieldLabel }}</label>
<group-filter :initial-data="groupInitialJson" />
2022-11-25 23:54:43 +05:30
</div>
2023-03-04 22:38:38 +05:30
<div v-if="showFilters" class="gl-mb-4 gl-lg-mb-0 gl-lg-ml-3">
<label class="gl-display-block">{{ $options.i18n.projectFieldLabel }}</label>
<project-filter :initial-data="projectInitialJson" />
2022-11-25 23:54:43 +05:30
</div>
2022-05-07 20:08:51 +05:30
</div>
2023-04-23 21:23:45 +05:30
<hr class="gl-mt-5 gl-mb-0 gl-border-gray-100" />
2022-05-07 20:08:51 +05:30
</section>
2021-03-11 19:13:27 +05:30
</template>