Commit 0e1f4ce3 authored by Kushal Pandya's avatar Kushal Pandya

Fix bugs around history dropdown and token key

Fixes two bugs;
- Hide history dropdown entirely when recentSearchesStorageKey
is not provided.
- Fix duplicate keys error when same token value is selected multiple
times.
parent 13dc980d
......@@ -121,7 +121,9 @@ export default {
: __('Sort direction: Descending');
},
filteredRecentSearches() {
return this.recentSearches.filter(item => typeof item !== 'string');
return this.recentSearchesStorageKey
? this.recentSearches.filter(item => typeof item !== 'string')
: undefined;
},
},
watch: {
......@@ -280,7 +282,7 @@ export default {
<template #history-item="{ historyItem }">
<template v-for="(token, index) in historyItem">
<span v-if="typeof token === 'string'" :key="index" class="gl-px-1">"{{ token }}"</span>
<span v-else :key="`${token.type}-${token.value.data}`" class="gl-px-1">
<span v-else :key="`${index}-${token.type}-${token.value.data}`" class="gl-px-1">
<span v-if="tokenTitles[token.type]"
>{{ tokenTitles[token.type] }} :{{ token.value.operator }}</span
>
......
......@@ -130,6 +130,16 @@ describe('FilteredSearchBarRoot', () => {
expect(wrapper.vm.filteredRecentSearches).toHaveLength(1);
expect(wrapper.vm.filteredRecentSearches[0]).toEqual({ foo: 'bar' });
});
it('returns undefined when recentSearchesStorageKey prop is not set on component', async () => {
wrapper.setProps({
recentSearchesStorageKey: '',
});
await wrapper.vm.$nextTick();
expect(wrapper.vm.filteredRecentSearches).not.toBeDefined();
});
});
});
......
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