2018-02-21 22:20:51 +00:00
|
|
|
<script>
|
|
|
|
import eventHub from '../event_hub';
|
|
|
|
import FilteredSearchTokenizer from '../filtered_search_tokenizer';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'RecentSearchesDropdownContent',
|
|
|
|
props: {
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isLocalStorageAvailable: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
allowedKeys: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
2020-08-10 18:09:54 +00:00
|
|
|
/**
|
|
|
|
* Both Epic and Roadmap pages share same recents store
|
|
|
|
* and with https://gitlab.com/gitlab-org/gitlab/-/merge_requests/36421
|
|
|
|
* Roadmap started using `GlFilteredSearch` which is not compatible
|
|
|
|
* with string tokens stored in recents, so this is a temporary
|
|
|
|
* fix by ignoring non-string recents while in Epic page.
|
|
|
|
*/
|
|
|
|
compatibleItems() {
|
2020-12-23 21:10:24 +00:00
|
|
|
return this.items.filter((item) => typeof item === 'string');
|
2020-08-10 18:09:54 +00:00
|
|
|
},
|
2018-02-21 22:20:51 +00:00
|
|
|
processedItems() {
|
2020-12-23 21:10:24 +00:00
|
|
|
return this.compatibleItems.map((item) => {
|
2018-10-10 06:18:49 +00:00
|
|
|
const { tokens, searchToken } = FilteredSearchTokenizer.processTokens(
|
|
|
|
item,
|
|
|
|
this.allowedKeys,
|
|
|
|
);
|
2018-02-21 22:20:51 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
const resultantTokens = tokens.map((token) => ({
|
2018-02-21 22:20:51 +00:00
|
|
|
prefix: `${token.key}:`,
|
2020-01-02 13:03:23 +00:00
|
|
|
operator: token.operator,
|
2018-02-21 22:20:51 +00:00
|
|
|
suffix: `${token.symbol}${token.value}`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return {
|
|
|
|
text: item,
|
|
|
|
tokens: resultantTokens,
|
|
|
|
searchToken,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
hasItems() {
|
2020-08-10 18:09:54 +00:00
|
|
|
return this.compatibleItems.length > 0;
|
2018-02-21 22:20:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onItemActivated(text) {
|
|
|
|
eventHub.$emit('recentSearchesItemSelected', text);
|
|
|
|
},
|
|
|
|
onRequestClearRecentSearches(e) {
|
|
|
|
// Stop the dropdown from closing
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
eventHub.$emit('requestClearRecentSearches');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<div>
|
2020-01-23 18:08:53 +00:00
|
|
|
<div v-if="!isLocalStorageAvailable" ref="localStorageNote" class="dropdown-info-note">
|
2019-07-01 11:42:51 +00:00
|
|
|
{{ __('This feature requires local storage to be enabled') }}
|
2018-02-21 22:20:51 +00:00
|
|
|
</div>
|
|
|
|
<ul v-else-if="hasItems">
|
2020-01-23 18:08:53 +00:00
|
|
|
<li
|
|
|
|
v-for="(item, index) in processedItems"
|
|
|
|
ref="dropdownItem"
|
|
|
|
:key="`processed-items-${index}`"
|
|
|
|
>
|
2018-02-21 22:20:51 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
2020-01-23 18:08:53 +00:00
|
|
|
class="filtered-search-history-dropdown-item js-dropdown-button"
|
2019-01-10 21:56:37 +00:00
|
|
|
@click="onItemActivated(item.text)"
|
2018-11-16 20:07:38 +00:00
|
|
|
>
|
2018-02-21 22:20:51 +00:00
|
|
|
<span>
|
|
|
|
<span
|
2018-09-20 06:13:50 +00:00
|
|
|
v-for="(token, tokenIndex) in item.tokens"
|
|
|
|
:key="`dropdown-token-${tokenIndex}`"
|
2020-01-23 18:08:53 +00:00
|
|
|
class="filtered-search-history-dropdown-token js-dropdown-token"
|
2018-02-21 22:20:51 +00:00
|
|
|
>
|
|
|
|
<span class="name">{{ token.prefix }}</span>
|
2020-01-02 13:03:23 +00:00
|
|
|
<span class="name">{{ token.operator }}</span>
|
2018-02-21 22:20:51 +00:00
|
|
|
<span class="value">{{ token.suffix }}</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
2020-08-10 18:09:54 +00:00
|
|
|
<span class="filtered-search-history-dropdown-search-token">{{ item.searchToken }}</span>
|
2018-02-21 22:20:51 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li class="divider"></li>
|
|
|
|
<li>
|
|
|
|
<button
|
2020-01-23 18:08:53 +00:00
|
|
|
ref="clearButton"
|
2018-02-21 22:20:51 +00:00
|
|
|
type="button"
|
|
|
|
class="filtered-search-history-clear-button"
|
2019-01-10 21:56:37 +00:00
|
|
|
@click="onRequestClearRecentSearches($event)"
|
2018-11-16 20:07:38 +00:00
|
|
|
>
|
2019-07-01 11:42:51 +00:00
|
|
|
{{ __('Clear recent searches') }}
|
2018-02-21 22:20:51 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2020-01-23 18:08:53 +00:00
|
|
|
<div v-else ref="dropdownNote" class="dropdown-info-note">
|
|
|
|
{{ __("You don't have any recent searches") }}
|
|
|
|
</div>
|
2018-02-21 22:20:51 +00:00
|
|
|
</div>
|
|
|
|
</template>
|