Commit fcebe5c4 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '322755-save-visited-url-filter' into 'master'

Save visited URL filters to recent searches and update weight token list

See merge request gitlab-org/gitlab!66361
parents 4d9b43f1 94b4363b
...@@ -2,6 +2,7 @@ import { __ } from '~/locale'; ...@@ -2,6 +2,7 @@ import { __ } from '~/locale';
export const DEBOUNCE_DELAY = 200; export const DEBOUNCE_DELAY = 200;
export const MAX_RECENT_TOKENS_SIZE = 3; export const MAX_RECENT_TOKENS_SIZE = 3;
export const WEIGHT_TOKEN_SUGGESTIONS_SIZE = 21;
export const FILTER_NONE = 'None'; export const FILTER_NONE = 'None';
export const FILTER_ANY = 'Any'; export const FILTER_ANY = 'Any';
......
...@@ -16,7 +16,7 @@ import createFlash from '~/flash'; ...@@ -16,7 +16,7 @@ import createFlash from '~/flash';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { SortDirection } from './constants'; import { SortDirection } from './constants';
import { stripQuotes, uniqueTokens } from './filtered_search_utils'; import { filterEmptySearchTerm, stripQuotes, uniqueTokens } from './filtered_search_utils';
export default { export default {
components: { components: {
...@@ -223,9 +223,14 @@ export default { ...@@ -223,9 +223,14 @@ export default {
// Put any searches that may have come in before // Put any searches that may have come in before
// we fetched the saved searches ahead of the already saved ones // we fetched the saved searches ahead of the already saved ones
const resultantSearches = this.recentSearchesStore.setRecentSearches( let resultantSearches = this.recentSearchesStore.setRecentSearches(
this.recentSearchesStore.state.recentSearches.concat(searches), this.recentSearchesStore.state.recentSearches.concat(searches),
); );
// If visited URL has search params, add them to recent search store
if (filterEmptySearchTerm(this.filterValue).length) {
resultantSearches = this.recentSearchesStore.addRecentSearch(this.filterValue);
}
this.recentSearchesService.save(resultantSearches); this.recentSearchesService.save(resultantSearches);
this.recentSearches = resultantSearches; this.recentSearches = resultantSearches;
}); });
......
...@@ -247,3 +247,12 @@ export function setTokenValueToRecentlyUsed(recentSuggestionsStorageKey, tokenVa ...@@ -247,3 +247,12 @@ export function setTokenValueToRecentlyUsed(recentSuggestionsStorageKey, tokenVa
); );
} }
} }
/**
* Removes `FILTERED_SEARCH_TERM` tokens with empty data
*
* @param filterTokens array of filtered search tokens
* @return {Array} array of filtered search tokens
*/
export const filterEmptySearchTerm = (filterTokens = []) =>
filterTokens.filter((token) => token.type === FILTERED_SEARCH_TERM && token.value.data);
<script> <script>
import { GlDropdownDivider, GlFilteredSearchSuggestion, GlFilteredSearchToken } from '@gitlab/ui'; import { GlDropdownDivider, GlFilteredSearchSuggestion, GlFilteredSearchToken } from '@gitlab/ui';
import { DEFAULT_NONE_ANY } from '../constants'; import { DEFAULT_NONE_ANY, WEIGHT_TOKEN_SUGGESTIONS_SIZE } from '../constants';
const weights = Array.from(Array(WEIGHT_TOKEN_SUGGESTIONS_SIZE), (_, index) => index.toString());
export default { export default {
baseWeights: ['0', '1', '2', '3', '4', '5'],
components: { components: {
GlDropdownDivider, GlDropdownDivider,
GlFilteredSearchSuggestion, GlFilteredSearchSuggestion,
...@@ -21,14 +22,14 @@ export default { ...@@ -21,14 +22,14 @@ export default {
}, },
data() { data() {
return { return {
weights: this.$options.baseWeights, weights,
defaultWeights: this.config.defaultWeights || DEFAULT_NONE_ANY, defaultWeights: this.config.defaultWeights || DEFAULT_NONE_ANY,
}; };
}, },
methods: { methods: {
updateWeights({ data }) { updateWeights({ data }) {
const weight = parseInt(data, 10); const weight = parseInt(data, 10);
this.weights = Number.isNaN(weight) ? this.$options.baseWeights : [String(weight)]; this.weights = Number.isNaN(weight) ? weights : [String(weight)];
}, },
}, },
}; };
......
...@@ -32,6 +32,9 @@ jest.mock('~/vue_shared/components/filtered_search_bar/filtered_search_utils', ( ...@@ -32,6 +32,9 @@ jest.mock('~/vue_shared/components/filtered_search_bar/filtered_search_utils', (
stripQuotes: jest.requireActual( stripQuotes: jest.requireActual(
'~/vue_shared/components/filtered_search_bar/filtered_search_utils', '~/vue_shared/components/filtered_search_bar/filtered_search_utils',
).stripQuotes, ).stripQuotes,
filterEmptySearchTerm: jest.requireActual(
'~/vue_shared/components/filtered_search_bar/filtered_search_utils',
).filterEmptySearchTerm,
})); }));
const createComponent = ({ const createComponent = ({
......
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