Commit bb8a6477 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch 'peterhegman/vue-group-members-filter-bar-fix-recent-items-label' into 'master'

Fix rendering of history items in members filter bar

See merge request gitlab-org/gitlab!49650
parents 2050e54d ede27136
...@@ -286,6 +286,7 @@ export default { ...@@ -286,6 +286,7 @@ export default {
handleFilterSubmit() { handleFilterSubmit() {
const filterTokens = uniqueTokens(this.filterValue); const filterTokens = uniqueTokens(this.filterValue);
this.filterValue = filterTokens; this.filterValue = filterTokens;
if (this.recentSearchesStorageKey) { if (this.recentSearchesStorageKey) {
this.recentSearchesPromise this.recentSearchesPromise
.then(() => { .then(() => {
...@@ -302,6 +303,17 @@ export default { ...@@ -302,6 +303,17 @@ export default {
this.blurSearchInput(); this.blurSearchInput();
this.$emit('onFilter', this.removeQuotesEnclosure(filterTokens)); this.$emit('onFilter', this.removeQuotesEnclosure(filterTokens));
}, },
historyTokenOptionTitle(historyToken) {
const tokenOption = this.tokens
.find(token => token.type === historyToken.type)
?.options?.find(option => option.value === historyToken.value.data);
if (!tokenOption?.title) {
return historyToken.value.data;
}
return tokenOption.title;
},
}, },
}; };
</script> </script>
...@@ -333,7 +345,7 @@ export default { ...@@ -333,7 +345,7 @@ export default {
<span v-if="tokenTitles[token.type]" <span v-if="tokenTitles[token.type]"
>{{ tokenTitles[token.type] }} :{{ token.value.operator }}</span >{{ tokenTitles[token.type] }} :{{ token.value.operator }}</span
> >
<strong>{{ tokenSymbols[token.type] }}{{ token.value.data }}</strong> <strong>{{ tokenSymbols[token.type] }}{{ historyTokenOptionTitle(token) }}</strong>
</span> </span>
</template> </template>
</template> </template>
......
...@@ -17,11 +17,14 @@ import RecentSearchesService from '~/filtered_search/services/recent_searches_se ...@@ -17,11 +17,14 @@ import RecentSearchesService from '~/filtered_search/services/recent_searches_se
import { import {
mockAvailableTokens, mockAvailableTokens,
mockMembershipToken,
mockMembershipTokenOptionsWithoutTitles,
mockSortOptions, mockSortOptions,
mockHistoryItems, mockHistoryItems,
tokenValueAuthor, tokenValueAuthor,
tokenValueLabel, tokenValueLabel,
tokenValueMilestone, tokenValueMilestone,
tokenValueMembership,
} from './mock_data'; } from './mock_data';
jest.mock('~/vue_shared/components/filtered_search_bar/filtered_search_utils', () => ({ jest.mock('~/vue_shared/components/filtered_search_bar/filtered_search_utils', () => ({
...@@ -412,6 +415,42 @@ describe('FilteredSearchBarRoot', () => { ...@@ -412,6 +415,42 @@ describe('FilteredSearchBarRoot', () => {
wrapperFullMount.destroy(); wrapperFullMount.destroy();
}); });
describe('when token options have `title` attribute defined', () => {
it('renders search history items using the provided `title` attribute', async () => {
const wrapperFullMount = createComponent({
sortOptions: mockSortOptions,
tokens: [mockMembershipToken],
shallow: false,
});
wrapperFullMount.vm.recentSearchesStore.addRecentSearch([tokenValueMembership]);
await wrapperFullMount.vm.$nextTick();
expect(wrapperFullMount.find(GlDropdownItem).text()).toBe('Membership := Direct');
wrapperFullMount.destroy();
});
});
describe('when token options have do not have `title` attribute defined', () => {
it('renders search history items using the provided `value` attribute', async () => {
const wrapperFullMount = createComponent({
sortOptions: mockSortOptions,
tokens: [mockMembershipTokenOptionsWithoutTitles],
shallow: false,
});
wrapperFullMount.vm.recentSearchesStore.addRecentSearch([tokenValueMembership]);
await wrapperFullMount.vm.$nextTick();
expect(wrapperFullMount.find(GlDropdownItem).text()).toBe('Membership := exclude');
wrapperFullMount.destroy();
});
});
it('renders sort dropdown component', () => { it('renders sort dropdown component', () => {
expect(wrapper.find(GlButtonGroup).exists()).toBe(true); expect(wrapper.find(GlButtonGroup).exists()).toBe(true);
expect(wrapper.find(GlDropdown).exists()).toBe(true); expect(wrapper.find(GlDropdown).exists()).toBe(true);
......
import { GlFilteredSearchToken } from '@gitlab/ui';
import { mockLabels } from 'jest/vue_shared/components/sidebar/labels_select_vue/mock_data'; import { mockLabels } from 'jest/vue_shared/components/sidebar/labels_select_vue/mock_data';
import Api from '~/api'; import Api from '~/api';
import AuthorToken from '~/vue_shared/components/filtered_search_bar/tokens/author_token.vue'; import AuthorToken from '~/vue_shared/components/filtered_search_bar/tokens/author_token.vue';
...@@ -102,6 +103,21 @@ export const mockMilestoneToken = { ...@@ -102,6 +103,21 @@ export const mockMilestoneToken = {
fetchMilestones: () => Promise.resolve({ data: mockMilestones }), fetchMilestones: () => Promise.resolve({ data: mockMilestones }),
}; };
export const mockMembershipToken = {
type: 'with_inherited_permissions',
icon: 'group',
title: 'Membership',
token: GlFilteredSearchToken,
unique: true,
operators: [{ value: '=', description: 'is' }],
options: [{ value: 'exclude', title: 'Direct' }, { value: 'only', title: 'Inherited' }],
};
export const mockMembershipTokenOptionsWithoutTitles = {
...mockMembershipToken,
options: [{ value: 'exclude' }, { value: 'only' }],
};
export const mockAvailableTokens = [mockAuthorToken, mockLabelToken, mockMilestoneToken]; export const mockAvailableTokens = [mockAuthorToken, mockLabelToken, mockMilestoneToken];
export const tokenValueAuthor = { export const tokenValueAuthor = {
...@@ -128,6 +144,14 @@ export const tokenValueMilestone = { ...@@ -128,6 +144,14 @@ export const tokenValueMilestone = {
}, },
}; };
export const tokenValueMembership = {
type: 'with_inherited_permissions',
value: {
operator: '=',
data: 'exclude',
},
};
export const tokenValuePlain = { export const tokenValuePlain = {
type: 'filtered-search-term', type: 'filtered-search-term',
value: { data: 'foo' }, value: { data: 'foo' },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment