Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search v2.3] [Saved Searches] Fix duplicate saved searches #49243

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ function buildSearchQueryString(queryJSON?: SearchQueryJSON) {
* Given object with chosen search filters builds correct query string from them
*/
function buildQueryStringFromFilterValues(filterValues: Partial<SearchAdvancedFiltersForm>) {
let expenseFilter = '';
lakchote marked this conversation as resolved.
Show resolved Hide resolved
let statusFilter = '';
const filtersString = Object.entries(filterValues).map(([filterKey, filterValue]) => {
if ((filterKey === FILTER_KEYS.MERCHANT || filterKey === FILTER_KEYS.DESCRIPTION || filterKey === FILTER_KEYS.REPORT_ID) && filterValue) {
const keyInCorrectForm = (Object.keys(CONST.SEARCH.SYNTAX_FILTER_KEYS) as FilterKeys[]).find((key) => CONST.SEARCH.SYNTAX_FILTER_KEYS[key] === filterKey);
Expand All @@ -534,10 +536,10 @@ function buildQueryStringFromFilterValues(filterValues: Partial<SearchAdvancedFi
return `${value}`;
}
if (filterKey === FILTER_KEYS.TYPE && filterValue) {
return `${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${sanitizeString(filterValue as string)}`;
expenseFilter = `${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${sanitizeString(filterValue as string)}`;
}
if (filterKey === FILTER_KEYS.STATUS && filterValue) {
return `${CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS}:${sanitizeString(filterValue as string)}`;
statusFilter = `${CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS}:${sanitizeString(filterValue as string)}`;
lakchote marked this conversation as resolved.
Show resolved Hide resolved
}
if (
(filterKey === FILTER_KEYS.CATEGORY ||
Expand Down Expand Up @@ -568,6 +570,15 @@ function buildQueryStringFromFilterValues(filterValues: Partial<SearchAdvancedFi
const amountFilter = buildAmountFilterQuery(filterValues);
filtersString.push(amountFilter);

// Ensure consistent filters order with expense and status filters at the beginning of the query
// To maintain hashes consistency for saved searches
if (statusFilter) {
filtersString.unshift(statusFilter);
}
if (expenseFilter) {
filtersString.unshift(expenseFilter);
}

return filtersString.filter(Boolean).join(' ');
}

Expand Down
Loading