diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-05 15:09:39 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-05 15:09:39 +0300 |
commit | 8dbc985bec96cad1e9a3315f38be27eb2374e5dc (patch) | |
tree | 4a4b010ebb11d110b3144d12f32bac0c9ad4dde8 /app/assets/javascripts/search | |
parent | dea522994156f9d427b1acc0a22b0e75ffe92c68 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/search')
10 files changed, 246 insertions, 67 deletions
diff --git a/app/assets/javascripts/search/sidebar/components/app.vue b/app/assets/javascripts/search/sidebar/components/app.vue index 317145d4cd1..af4d93dc033 100644 --- a/app/assets/javascripts/search/sidebar/components/app.vue +++ b/app/assets/javascripts/search/sidebar/components/app.vue @@ -4,13 +4,13 @@ import ScopeNavigation from '~/search/sidebar/components/scope_navigation.vue'; import ScopeNewNavigation from '~/search/sidebar/components/scope_new_navigation.vue'; import SidebarPortal from '~/super_sidebar/components/sidebar_portal.vue'; import { SCOPE_ISSUES, SCOPE_MERGE_REQUESTS, SCOPE_BLOB } from '../constants'; -import ResultsFilters from './results_filters.vue'; +import IssuesFilters from './issues_filters.vue'; import LanguageFilter from './language_filter/index.vue'; export default { name: 'GlobalSearchSidebar', components: { - ResultsFilters, + IssuesFilters, ScopeNavigation, ScopeNewNavigation, LanguageFilter, @@ -25,6 +25,9 @@ export default { showBlobFilter() { return this.currentScope === SCOPE_BLOB; }, + showLabelFilter() { + return this.currentScope === SCOPE_ISSUES; + }, showOldNavigation() { return Boolean(this.currentScope); }, @@ -36,7 +39,7 @@ export default { <section v-if="useNewNavigation"> <sidebar-portal> <scope-new-navigation /> - <results-filters v-if="showIssueAndMergeFilters" /> + <issues-filters v-if="showIssueAndMergeFilters" /> <language-filter v-if="showBlobFilter" /> </sidebar-portal> </section> @@ -45,7 +48,7 @@ export default { class="search-sidebar gl-display-flex gl-flex-direction-column gl-md-mr-5 gl-mb-6 gl-mt-5" > <scope-navigation /> - <results-filters v-if="showIssueAndMergeFilters" /> + <issues-filters v-if="showIssueAndMergeFilters" /> <language-filter v-if="showBlobFilter" /> </section> </template> diff --git a/app/assets/javascripts/search/sidebar/components/confidentiality_filter.vue b/app/assets/javascripts/search/sidebar/components/confidentiality_filter.vue index 56e44d454a1..2a7988cd4c6 100644 --- a/app/assets/javascripts/search/sidebar/components/confidentiality_filter.vue +++ b/app/assets/javascripts/search/sidebar/components/confidentiality_filter.vue @@ -19,7 +19,7 @@ export default { <template> <div> - <radio-filter class="gl-px-5" :filter-data="$options.confidentialFilterData" /> + <radio-filter :filter-data="$options.confidentialFilterData" /> <hr v-if="!useNewNavigation" :class="$options.HR_DEFAULT_CLASSES" /> </div> </template> diff --git a/app/assets/javascripts/search/sidebar/components/issues_filters.vue b/app/assets/javascripts/search/sidebar/components/issues_filters.vue new file mode 100644 index 00000000000..2ab5dfb8dea --- /dev/null +++ b/app/assets/javascripts/search/sidebar/components/issues_filters.vue @@ -0,0 +1,73 @@ +<script> +import { GlButton, GlLink } from '@gitlab/ui'; +import { mapActions, mapState, mapGetters } from 'vuex'; +import Tracking from '~/tracking'; +import { + HR_DEFAULT_CLASSES, + TRACKING_ACTION_CLICK, + TRACKING_LABEL_APPLY, + TRACKING_CATEGORY, + TRACKING_LABEL_RESET, +} from '../constants/index'; +import { confidentialFilterData } from '../constants/confidential_filter_data'; +import { stateFilterData } from '../constants/state_filter_data'; +import ConfidentialityFilter from './confidentiality_filter.vue'; +import StatusFilter from './status_filter.vue'; + +export default { + name: 'IssuesFilters', + components: { + GlButton, + GlLink, + StatusFilter, + ConfidentialityFilter, + }, + computed: { + ...mapState(['urlQuery', 'sidebarDirty', 'useNewNavigation']), + ...mapGetters(['currentScope']), + showReset() { + return this.urlQuery.state || this.urlQuery.confidential || this.urlQuery.labels; + }, + showConfidentialityFilter() { + return Object.values(confidentialFilterData.scopes).includes(this.currentScope); + }, + showStatusFilter() { + return Object.values(stateFilterData.scopes).includes(this.currentScope); + }, + hrClasses() { + return [...HR_DEFAULT_CLASSES, 'gl-display-none', 'gl-md-display-block']; + }, + }, + methods: { + ...mapActions(['applyQuery', 'resetQuery']), + applyQueryWithTracking() { + Tracking.event(TRACKING_ACTION_CLICK, TRACKING_LABEL_APPLY, { + label: TRACKING_CATEGORY, + }); + this.applyQuery(); + }, + resetQueryWithTracking() { + Tracking.event(TRACKING_ACTION_CLICK, TRACKING_LABEL_RESET, { + label: TRACKING_CATEGORY, + }); + this.resetQuery(); + }, + }, +}; +</script> + +<template> + <form class="issue-filters gl-px-5 gl-pt-0" @submit.prevent="applyQueryWithTracking"> + <hr v-if="!useNewNavigation" :class="hrClasses" /> + <status-filter v-if="showStatusFilter" class="gl-mb-5" /> + <confidentiality-filter v-if="showConfidentialityFilter" class="gl-mb-5" /> + <div class="gl-display-flex gl-align-items-center gl-mt-5"> + <gl-button category="primary" variant="confirm" type="submit" :disabled="!sidebarDirty"> + {{ __('Apply') }} + </gl-button> + <gl-link v-if="showReset" class="gl-ml-auto" @click="resetQueryWithTracking">{{ + __('Reset filters') + }}</gl-link> + </div> + </form> +</template> diff --git a/app/assets/javascripts/search/sidebar/components/language_filter/checkbox_filter.vue b/app/assets/javascripts/search/sidebar/components/language_filter/checkbox_filter.vue new file mode 100644 index 00000000000..b820ca837bc --- /dev/null +++ b/app/assets/javascripts/search/sidebar/components/language_filter/checkbox_filter.vue @@ -0,0 +1,91 @@ +<script> +import Vue from 'vue'; +import { GlFormCheckboxGroup, GlFormCheckbox } from '@gitlab/ui'; +import { mapState, mapActions, mapGetters } from 'vuex'; +import { intersection } from 'lodash'; +import Tracking from '~/tracking'; +import { NAV_LINK_COUNT_DEFAULT_CLASSES, LABEL_DEFAULT_CLASSES } from '../../constants'; +import { formatSearchResultCount } from '../../../store/utils'; + +export const TRACKING_LABEL_SET = 'set'; +export const TRACKING_LABEL_CHECKBOX = 'checkbox'; + +export default { + name: 'CheckboxFilter', + components: { + GlFormCheckboxGroup, + GlFormCheckbox, + }, + props: { + filtersData: { + type: Object, + required: true, + }, + trackingNamespace: { + type: String, + required: true, + }, + }, + computed: { + ...mapState(['query', 'useNewNavigation']), + ...mapGetters(['queryLanguageFilters']), + dataFilters() { + return Object.values(this.filtersData?.filters || []); + }, + flatDataFilterValues() { + return this.dataFilters.map(({ value }) => value); + }, + selectedFilter: { + get() { + return intersection(this.flatDataFilterValues, this.queryLanguageFilters); + }, + async set(value) { + this.setQuery({ key: this.filtersData?.filterParam, value }); + + await Vue.nextTick(); + this.trackSelectCheckbox(); + }, + }, + labelCountClasses() { + return [...NAV_LINK_COUNT_DEFAULT_CLASSES, 'gl-text-gray-500']; + }, + }, + methods: { + ...mapActions(['setQuery']), + getFormattedCount(count) { + return formatSearchResultCount(count); + }, + trackSelectCheckbox() { + Tracking.event(this.trackingNamespace, TRACKING_LABEL_CHECKBOX, { + label: TRACKING_LABEL_SET, + property: this.selectedFilter, + }); + }, + }, + NAV_LINK_COUNT_DEFAULT_CLASSES, + LABEL_DEFAULT_CLASSES, +}; +</script> + +<template> + <gl-form-checkbox-group v-model="selectedFilter"> + <gl-form-checkbox + v-for="f in dataFilters" + :key="f.label" + :value="f.label" + class="gl-flex-grow-1 gl-display-inline-flex gl-justify-content-space-between gl-w-full" + :class="$options.LABEL_DEFAULT_CLASSES" + > + <span + class="gl-flex-grow-1 gl-display-inline-flex gl-justify-content-space-between gl-w-full" + > + <span data-testid="label"> + {{ f.label }} + </span> + <span v-if="f.count" :class="labelCountClasses" data-testid="labelCount"> + {{ getFormattedCount(f.count) }} + </span> + </span> + </gl-form-checkbox> + </gl-form-checkbox-group> +</template> diff --git a/app/assets/javascripts/search/sidebar/components/language_filter/index.vue b/app/assets/javascripts/search/sidebar/components/language_filter/index.vue index 40b50f657f0..e531abf523b 100644 --- a/app/assets/javascripts/search/sidebar/components/language_filter/index.vue +++ b/app/assets/javascripts/search/sidebar/components/language_filter/index.vue @@ -5,7 +5,7 @@ import { __, s__, sprintf } from '~/locale'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import { HR_DEFAULT_CLASSES, ONLY_SHOW_MD } from '../../constants'; import { convertFiltersData } from '../../utils'; -import CheckboxFilter from '../checkbox_filter.vue'; +import CheckboxFilter from './checkbox_filter.vue'; import { trackShowMore, trackShowHasOverMax, @@ -14,7 +14,7 @@ import { TRACKING_ACTION_SELECT, } from './tracking'; -import { DEFAULT_ITEM_LENGTH, MAX_ITEM_LENGTH } from './data'; +import { DEFAULT_ITEM_LENGTH, MAX_ITEM_LENGTH, languageFilterData } from './data'; export default { name: 'LanguageFilter', @@ -65,22 +65,25 @@ export default { hasOverMax() { return this.languageAggregationBuckets.length > MAX_ITEM_LENGTH; }, - dividerClasses() { + dividerClassesTop() { return [...HR_DEFAULT_CLASSES, ...ONLY_SHOW_MD]; }, + dividerClassesBottom() { + return [...HR_DEFAULT_CLASSES, 'gl-mt-5']; + }, hasQueryFilters() { return this.queryLanguageFilters.length > 0; }, }, async created() { - await this.fetchLanguageAggregation(); + await this.fetchAllAggregation(); }, methods: { ...mapActions([ 'applyQuery', 'resetLanguageQuery', 'resetLanguageQueryWithRedirect', - 'fetchLanguageAggregation', + 'fetchAllAggregation', ]), onShowMore() { this.showAll = true; @@ -108,69 +111,73 @@ export default { }, HR_DEFAULT_CLASSES, TRACKING_ACTION_SELECT, + languageFilterData, }; </script> <template> - <gl-form - v-if="hasBuckets" - class="gl-pt-5 gl-md-pt-0 language-filter-checkbox" - @submit.prevent="submitQuery" - > - <hr v-if="!useNewNavigation" :class="dividerClasses" /> - <div - v-if="!aggregations.error" - class="gl-overflow-x-hidden gl-overflow-y-auto" - :class="{ 'language-filter-max-height': showAll }" + <div> + <gl-form + v-if="hasBuckets" + class="gl-m-5 gl-my-0 language-filter-checkbox" + @submit.prevent="submitQuery" > - <checkbox-filter - :filters-data="filtersData" - :tracking-namespace="$options.TRACKING_ACTION_SELECT" - /> - <span v-if="showAll && hasOverMax" data-testid="has-over-max-text">{{ - $options.i18n.showingMax - }}</span> - </div> - <gl-alert v-else class="gl-mx-5" variant="danger" :dismissible="false">{{ - $options.i18n.loadError - }}</gl-alert> - <div v-if="hasShowMore && !showAll" class="gl-px-5 language-filter-show-all"> - <gl-button - data-testid="show-more-button" - category="tertiary" - variant="link" - size="small" - button-text-classes="gl-font-sm" - @click="onShowMore" - > - {{ $options.i18n.showMore }} - </gl-button> - </div> - <div v-if="!aggregations.error"> - <hr v-if="!useNewNavigation" :class="$options.HR_DEFAULT_CLASSES" /> + <hr v-if="!useNewNavigation" :class="dividerClassesTop" /> + <h5 class="gl-mt-0 gl-mb-5" :class="{ 'gl-font-sm': useNewNavigation }"> + {{ $options.languageFilterData.header }} + </h5> <div - class="gl-display-flex gl-align-items-center gl-justify-content-space-between gl-mt-4 gl-mx-5" + v-if="!aggregations.error" + class="gl-overflow-x-hidden gl-overflow-y-auto" + :class="{ 'language-filter-max-height': showAll }" > + <checkbox-filter + :filters-data="filtersData" + :tracking-namespace="$options.TRACKING_ACTION_SELECT" + /> + <span v-if="showAll && hasOverMax" data-testid="has-over-max-text">{{ + $options.i18n.showingMax + }}</span> + </div> + <gl-alert v-else class="gl-mx-5" variant="danger" :dismissible="false">{{ + $options.i18n.loadError + }}</gl-alert> + <div v-if="hasShowMore && !showAll" class="gl-px-5 language-filter-show-all"> <gl-button - category="primary" - variant="confirm" - type="submit" - :disabled="!sidebarDirty" - data-testid="apply-button" - > - {{ $options.i18n.apply }} - </gl-button> - <gl-button + data-testid="show-more-button" category="tertiary" variant="link" size="small" - :disabled="!hasQueryFilters && !sidebarDirty" - data-testid="reset-button" - @click="cleanResetFilters" + button-text-classes="gl-font-sm" + @click="onShowMore" > - {{ $options.i18n.reset }} + {{ $options.i18n.showMore }} </gl-button> </div> - </div> - </gl-form> + <div v-if="!aggregations.error"> + <hr v-if="!useNewNavigation" :class="dividerClassesBottom" /> + <div class="gl-display-flex gl-align-items-center gl-justify-content-space-between gl-mt-4"> + <gl-button + category="primary" + variant="confirm" + type="submit" + :disabled="!sidebarDirty" + data-testid="apply-button" + > + {{ $options.i18n.apply }} + </gl-button> + <gl-button + v-if="hasQueryFilters && sidebarDirty" + category="tertiary" + variant="link" + size="small" + data-testid="reset-button" + @click="cleanResetFilters" + > + {{ $options.i18n.reset }} + </gl-button> + </div> + </div> + </gl-form> + </div> </template> diff --git a/app/assets/javascripts/search/sidebar/components/radio_filter.vue b/app/assets/javascripts/search/sidebar/components/radio_filter.vue index 477ba37dab7..10ece1b82eb 100644 --- a/app/assets/javascripts/search/sidebar/components/radio_filter.vue +++ b/app/assets/javascripts/search/sidebar/components/radio_filter.vue @@ -56,7 +56,9 @@ export default { <template> <div> - <h5 class="gl-mt-0" :class="{ 'gl-font-sm': useNewNavigation }">{{ filterData.header }}</h5> + <h5 class="gl-mt-0 gl-mb-5" :class="{ 'gl-font-sm': useNewNavigation }"> + {{ filterData.header }} + </h5> <gl-form-radio-group v-model="selectedFilter"> <gl-form-radio v-for="f in filtersArray" :key="f.value" :value="f.value"> {{ radioLabel(f) }} diff --git a/app/assets/javascripts/search/sidebar/components/scope_navigation.vue b/app/assets/javascripts/search/sidebar/components/scope_navigation.vue index fc41baee831..b29a8d13425 100644 --- a/app/assets/javascripts/search/sidebar/components/scope_navigation.vue +++ b/app/assets/javascripts/search/sidebar/components/scope_navigation.vue @@ -80,6 +80,6 @@ export default { </span> </gl-nav-item> </gl-nav> - <hr class="gl-mt-5 gl-mx-5 gl-mb-0 gl-border-gray-100 gl-md-display-none" /> + <hr class="gl-mt-3 gl-mb-5 gl-border-gray-100 gl-md-display-none" /> </nav> </template> diff --git a/app/assets/javascripts/search/sidebar/components/status_filter.vue b/app/assets/javascripts/search/sidebar/components/status_filter.vue index 44d6b537b7b..2a3d9ede982 100644 --- a/app/assets/javascripts/search/sidebar/components/status_filter.vue +++ b/app/assets/javascripts/search/sidebar/components/status_filter.vue @@ -19,7 +19,7 @@ export default { <template> <div> - <radio-filter class="gl-px-5" :filter-data="$options.stateFilterData" /> + <radio-filter :filter-data="$options.stateFilterData" /> <hr v-if="!useNewNavigation" :class="$options.HR_DEFAULT_CLASSES" /> </div> </template> diff --git a/app/assets/javascripts/search/sidebar/constants/index.js b/app/assets/javascripts/search/sidebar/constants/index.js index 9519154a571..99d8821db61 100644 --- a/app/assets/javascripts/search/sidebar/constants/index.js +++ b/app/assets/javascripts/search/sidebar/constants/index.js @@ -12,7 +12,10 @@ export const NAV_LINK_DEFAULT_CLASSES = [ 'gl-justify-content-space-between', ]; export const NAV_LINK_COUNT_DEFAULT_CLASSES = ['gl-font-sm', 'gl-font-weight-normal']; -export const HR_DEFAULT_CLASSES = ['gl-my-5', 'gl-mx-5', 'gl-border-gray-100']; +export const HR_DEFAULT_CLASSES = ['hr-x', 'gl-border-gray-100']; export const ONLY_SHOW_MD = ['gl-display-none', 'gl-md-display-block']; -export const TRACKING_LABEL_CHECKBOX = 'Checkbox'; +export const TRACKING_ACTION_CLICK = 'search:filters:click'; +export const TRACKING_LABEL_APPLY = 'Apply Filters'; +export const TRACKING_LABEL_RESET = 'Reset Filters'; +export const TRACKING_CATEGORY = 'Issue filters'; diff --git a/app/assets/javascripts/search/store/actions.js b/app/assets/javascripts/search/store/actions.js index 3d6ca2a6eee..3fdc4165baf 100644 --- a/app/assets/javascripts/search/store/actions.js +++ b/app/assets/javascripts/search/store/actions.js @@ -136,7 +136,7 @@ export const fetchSidebarCount = ({ commit, state }) => { return Promise.all(promises); }; -export const fetchLanguageAggregation = ({ commit, state }) => { +export const fetchAllAggregation = ({ commit, state }) => { commit(types.REQUEST_AGGREGATIONS); return axios .get(getAggregationsUrl()) |