Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/components/Search/hooks/useSearchKeyParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useRootNavigationState from '@hooks/useRootNavigationState';
import Navigation, {getDeepestFocusedScreen} from '@libs/Navigation/Navigation';
import type {SearchKey} from '@libs/SearchKeyUtils';
import {getSearchKeyForDataType, isExistingSearchKey, savedSearchIDToSearchKey, searchKeyToSavedSearchID} from '@libs/SearchKeyUtils';
import {buildSearchQueryJSON, doesQueryMatchDefaultFilterKeysAndType} from '@libs/SearchQueryUtils';
import {buildSearchQueryJSON, doesQueryMatchDefaultFilterKeysAndType, normalizeDatePresetsInQuery} from '@libs/SearchQueryUtils';
import type {SearchTypeMenuItem} from '@libs/SearchUIUtils';
import {getLastSearchQuery} from '@libs/SearchUIUtils';

Expand Down Expand Up @@ -72,7 +72,7 @@ function useSearchKeyParam(currentSearchQueryJSON: SearchQueryJSON | undefined,
const lastSavedSearchQuery = getLastSearchQuery(searchFilters, savedSearchIDToSearchKey(id));

return (
(savedSearchQuery ? buildSearchQueryJSON(savedSearchQuery)?.hash === queryJSON?.hash : false) ||
(savedSearchQuery ? buildSearchQueryJSON(normalizeDatePresetsInQuery(savedSearchQuery))?.hash === queryJSON?.hash : false) ||
(lastSavedSearchQuery ? buildSearchQueryJSON(lastSavedSearchQuery)?.hash === queryJSON?.hash : false)
);
});
Expand All @@ -91,7 +91,7 @@ function useSearchKeyParam(currentSearchQueryJSON: SearchQueryJSON | undefined,

const savedSearchID = searchKeyToSavedSearchID(searchKey);
const defaultSearchQueryString = savedSearchID ? savedSearches?.[savedSearchID]?.query : suggestedSearches[searchKey]?.searchQuery;
return defaultSearchQueryString ? buildSearchQueryJSON(defaultSearchQueryString) : undefined;
return defaultSearchQueryString ? buildSearchQueryJSON(normalizeDatePresetsInQuery(defaultSearchQueryString)) : undefined;
};

// The `searchKey` param is sticky: it survives a `Navigation.setParams({q})`, so tweaking a filter keeps the
Expand Down
2 changes: 1 addition & 1 deletion src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10745,7 +10745,7 @@ Fügen Sie weitere Ausgabelimits hinzu, um den Cashflow Ihres Unternehmens zu sc
[CONST.SEARCH.DATE_PRESETS.NEVER]: 'Nie',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: 'Letzter Monat',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: 'Diesen Monat',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Laufendes Jahr',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Dieses Jahr',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: 'Letzte 12 Monate',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: 'Diese Woche',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: 'Letzte Woche',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10953,7 +10953,7 @@ ${reportName}`,
[CONST.SEARCH.DATE_PRESETS.NEVER]: 'Ποτέ',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: 'Τον προηγούμενο μήνα',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: 'Αυτόν τον μήνα',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Έως σήμερα μέσα στο έτος',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Φέτος',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: 'Τελευταίοι 12 μήνες',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: 'Αυτή την εβδομάδα',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: 'Την προηγούμενη εβδομάδα',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11013,7 +11013,7 @@ const translations = {
[CONST.SEARCH.DATE_PRESETS.NEVER]: 'Never',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: 'Last month',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: 'This month',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Year to date',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'This year',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: 'Last 12 months',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: 'This week',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: 'Last week',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10599,7 +10599,7 @@ ${reportName}`,
[CONST.SEARCH.DATE_PRESETS.NEVER]: 'Nunca',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: 'El mes pasado',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: 'Este mes',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Año hasta la fecha',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Este año',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: 'Últimos 12 meses',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: 'Esta semana',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: 'La semana pasada',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10772,7 +10772,7 @@ Ajoutez davantage de règles de dépenses pour protéger la trésorerie de l’e
[CONST.SEARCH.DATE_PRESETS.NEVER]: 'Jamais',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: 'Mois dernier',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: 'Ce mois-ci',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Depuis le début de l’année',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Cette année',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: '12 derniers mois',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: 'Cette semaine',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: 'Semaine dernière',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10698,7 +10698,7 @@ Aggiungi altre regole di spesa per proteggere il flusso di cassa aziendale.`,
[CONST.SEARCH.DATE_PRESETS.NEVER]: 'Mai',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: 'Il mese scorso',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: 'Questo mese',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Da inizio anno',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Quest’anno',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: 'Ultimi 12 mesi',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: 'Questa settimana',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: 'La settimana scorsa',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10542,7 +10542,7 @@ ${reportName}`,
[CONST.SEARCH.DATE_PRESETS.NEVER]: '決してない',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: '先月',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: '今月',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: '年初来(累計)',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: '今年',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: '過去12か月',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: '今週',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: '先週',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10667,7 +10667,7 @@ er bestedingsregels toe om de kasstroom van het bedrijf te beschermen.`,
[CONST.SEARCH.DATE_PRESETS.NEVER]: 'Nooit',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: 'Vorige maand',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: 'Deze maand',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Jaar tot nu toe',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Dit jaar',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: 'Laatste 12 maanden',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: 'Deze week',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: 'Vorige week',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10689,7 +10689,7 @@ Dodaj więcej zasad wydatków, żeby chronić płynność finansową firmy.`,
[CONST.SEARCH.DATE_PRESETS.NEVER]: 'Nigdy',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: 'W zeszłym miesiącu',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: 'Ten miesiąc',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Od początku roku',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Ten rok',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: 'Ostatnie 12 miesięcy',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: 'Ten tydzień',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: 'W zeszłym tygodniu',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10669,7 +10669,7 @@ Adicione mais regras de gasto para proteger o fluxo de caixa da empresa.`,
[CONST.SEARCH.DATE_PRESETS.NEVER]: 'Nunca',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: 'Mês passado',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: 'Este mês',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Ano até agora',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: 'Este ano',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: 'Últimos 12 meses',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: 'Esta semana',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: 'Semana passada',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10271,7 +10271,7 @@ ${reportName}`,
[CONST.SEARCH.DATE_PRESETS.NEVER]: '从不',
[CONST.SEARCH.DATE_PRESETS.LAST_MONTH]: '上个月',
[CONST.SEARCH.DATE_PRESETS.THIS_MONTH]: '本月',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: '本年度至今',
[CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE]: '今年',
[CONST.SEARCH.DATE_PRESETS.LAST_12_MONTHS]: '过去 12 个月',
[CONST.SEARCH.DATE_PRESETS.THIS_WEEK]: '本周',
[CONST.SEARCH.DATE_PRESETS.LAST_WEEK]: '上周',
Expand Down
68 changes: 57 additions & 11 deletions src/libs/SearchQueryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,9 @@ function getQueryHashWithoutFilters(query: SearchQueryJSON, exclude: ReadonlySet
const flatFilters = query.flatFilters
.map((filter) => {
const filterKey = filter.key;
const filters = cloneDeep(filter.filters);
const filters = cloneDeep(filter.filters).map((queryFilter) =>
canFilterValueBeDatePreset(filterKey, queryFilter.operator) ? {...queryFilter, value: normalizeDatePreset(queryFilter.value.toString())} : queryFilter,
);
filters.sort((a, b) => customCollator.compare(a.value.toString(), b.value.toString()));
return {filterString: buildFilterValuesString(filterKey, filters), filterKey};
})
Expand Down Expand Up @@ -1080,6 +1082,45 @@ function isSearchDatePreset(date: string | undefined): date is SearchDatePreset
return Object.values(CONST.SEARCH.DATE_PRESETS).some((datePreset) => datePreset === date);
}

/**
* Maps the deprecated Year to date preset to This year, which the date picker lists in its place
*/
function normalizeDatePreset(date: string): string {
return date === CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE ? CONST.SEARCH.DATE_PRESETS.THIS_YEAR : date;
Comment thread
c3024 marked this conversation as resolved.
Resolved
}

/**
* Whether a filter value can hold a date preset. The filter form reads equal-to report field values as dates and negated ones as text.
*/
function canFilterValueBeDatePreset(filterKey: string, operator: ASTNode['operator']) {
return (
(DATE_FILTER_KEYS as readonly string[]).includes(filterKey) || (filterKey.startsWith(CONST.SEARCH.REPORT_FIELD.DEFAULT_PREFIX) && operator === CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO)
);
}

/**
* Maps the deprecated Year to date preset to This year in a filter value that can hold a date preset
*/
function normalizeDatePresetFilterValue(filterKey: SyntaxFilterKey, filterValue: string | string[], operator: ASTNode['operator']): string | string[] {
if (!canFilterValueBeDatePreset(filterKey, operator)) {
return filterValue;
}
return Array.isArray(filterValue) ? filterValue.map(normalizeDatePreset) : normalizeDatePreset(filterValue);
}

/**
* Maps the deprecated Year to date preset to This year in a query, so a search saved with it opens and saves with This year
*/
function normalizeDatePresetsInQuery(query: SearchQueryString): SearchQueryString {
const queryJSON = query ? buildSearchQueryJSON(query) : undefined;
const hasYearToDate = queryJSON?.flatFilters.some((filter) => filter.filters.some((queryFilter) => queryFilter.value === CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE));
if (!queryJSON || !hasYearToDate) {
return query;
}

return buildSearchQueryString(traverseAndUpdatedQuery(queryJSON, normalizeDatePresetFilterValue));
}

/**
* Returns whether a given search filter is supported in a given search data type
*/
Expand Down Expand Up @@ -1810,18 +1851,16 @@ function getDateRangeForPreset(preset: SearchDatePreset): {start: string; end: s
start = startOfQuarter(lastQuarter);
end = endOfQuarter(lastQuarter);
break;
// Year to date is deprecated and kept as an alias of this year, so saved searches and links still resolve.
case CONST.SEARCH.DATE_PRESETS.THIS_YEAR:
case CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE:
start = startOfYear(now);
end = endOfYear(now);
break;
case CONST.SEARCH.DATE_PRESETS.LAST_YEAR:
start = startOfYear(lastYear);
end = endOfYear(lastYear);
break;
case CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE:
start = startOfYear(now);
end = now;
break;
case CONST.SEARCH.DATE_PRESETS.LAST_30_DAYS:
start = subDays(now, 29);
end = now;
Expand Down Expand Up @@ -2062,8 +2101,8 @@ function buildFilterFormValuesFromQuery(

filtersForm[beforeKey] = getEarlierDate(beforeFilter?.value.toString(), filtersForm[beforeKey]);
filtersForm[afterKey] = getLaterDate(afterFilter?.value.toString(), filtersForm[afterKey]);
filtersForm[onKey] = onFilter?.value.toString() ?? filtersForm[onKey];
filtersForm[negatedKey] = negatedFilter?.value.toString() ?? filtersForm[negatedKey];
filtersForm[onKey] = onFilter ? normalizeDatePreset(onFilter.value.toString()) : filtersForm[onKey];
filtersForm[negatedKey] = negatedFilter ? normalizeDatePreset(negatedFilter.value.toString()) : filtersForm[negatedKey];

if (rangeValue) {
filtersForm[rangeKey] = rangeValue;
Expand Down Expand Up @@ -2151,7 +2190,7 @@ function buildFilterFormValuesFromQuery(

filtersForm[textKey] = textFilter?.value.toString() ?? filtersForm[textKey];
filtersForm[negatedKey] = negatedFilter?.value.toString() ?? filtersForm[negatedKey];
filtersForm[dateOnKey] = dateOnFilter?.value.toString() ?? filtersForm[dateOnKey];
filtersForm[dateOnKey] = dateOnFilter ? normalizeDatePreset(dateOnFilter.value.toString()) : filtersForm[dateOnKey];
filtersForm[dateBeforeKey] = getEarlierDate(dateBeforeFilter?.value.toString(), filtersForm[dateBeforeKey]);
filtersForm[dateAfterKey] = getLaterDate(dateAfterFilter?.value.toString(), filtersForm[dateAfterKey]);

Expand Down Expand Up @@ -2737,7 +2776,10 @@ const sortOptionsWithEmptyValue = (a: string, b: string, localeCompare: LocaleCo
/**
* Given a search query, this function will standardize the query by replacing display values with their corresponding IDs.
*/
function traverseAndUpdatedQuery(queryJSON: SearchQueryJSON | Readonly<SearchQueryJSON>, computeNodeValue: (left: SyntaxFilterKey, right: string | string[]) => string | string[]) {
function traverseAndUpdatedQuery(
queryJSON: SearchQueryJSON | Readonly<SearchQueryJSON>,
computeNodeValue: (left: SyntaxFilterKey, right: string | string[], operator: ASTNode['operator']) => string | string[],
) {
const standardQuery = cloneDeep(queryJSON) as SearchQueryJSON;
const filters = standardQuery.filters;
const traverse = (node: ASTNode) => {
Expand All @@ -2753,7 +2795,7 @@ function traverseAndUpdatedQuery(queryJSON: SearchQueryJSON | Readonly<SearchQue

if (typeof node.left !== 'object' && (Array.isArray(node.right) || typeof node.right === 'string')) {
// eslint-disable-next-line no-param-reassign
node.right = computeNodeValue(node.left, node.right);
node.right = computeNodeValue(node.left, node.right, node.operator);
}
};

Expand All @@ -2774,6 +2816,7 @@ function getKeywordQueryWithCurrentSearchContext(queryString: SearchQueryString,
/**
* Returns new string query, after parsing it and traversing to update some filter values.
* If there are any personal emails, it will try to substitute them with accountIDs
* The deprecated Year to date preset is mapped to This year
*/
function getQueryWithUpdatedValues(query: string, shouldSkipAmountConversion = false, policies?: OnyxCollection<OnyxTypes.Policy>) {
const queryJSON = buildSearchQueryJSON(query);
Expand All @@ -2783,7 +2826,8 @@ function getQueryWithUpdatedValues(query: string, shouldSkipAmountConversion = f
return;
}

const computeNodeValue = (left: SyntaxFilterKey, right: string | string[]) => getUpdatedFilterValue(left, right, shouldSkipAmountConversion, policies);
const computeNodeValue = (left: SyntaxFilterKey, right: string | string[], operator: ASTNode['operator']) =>
normalizeDatePresetFilterValue(left, getUpdatedFilterValue(left, right, shouldSkipAmountConversion, policies), operator);
const standardizedQuery = traverseAndUpdatedQuery(queryJSON, computeNodeValue);
const rawFilterList = getRawFilterListFromQuery(query);
const hasInFilter = rawFilterList?.some((filter) => !filter.isDefault && filter.key === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN) ?? false;
Expand Down Expand Up @@ -3270,6 +3314,8 @@ export {
hasFiltersChangedFromDefault,
isSearchQuerySavable,
isSearchDatePreset,
normalizeDatePreset,
normalizeDatePresetsInQuery,
getDateRangeForPreset,
getDateFilterRange,
isSearchBeforeViolationsSnapshotStarted,
Expand Down
1 change: 0 additions & 1 deletion src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5725,7 +5725,6 @@ function getDatePresets(filterKey: SearchDateFilterKeys, hasFeed: boolean): Sear
CONST.SEARCH.DATE_PRESETS.THIS_MONTH,
CONST.SEARCH.DATE_PRESETS.THIS_QUARTER,
CONST.SEARCH.DATE_PRESETS.THIS_YEAR,
Comment thread
c3024 marked this conversation as resolved.
Resolved
CONST.SEARCH.DATE_PRESETS.YEAR_TO_DATE,
CONST.SEARCH.DATE_PRESETS.LAST_WEEK,
CONST.SEARCH.DATE_PRESETS.LAST_MONTH,
CONST.SEARCH.DATE_PRESETS.LAST_QUARTER,
Expand Down
10 changes: 6 additions & 4 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import {
} from '@libs/ReportUtils';
import type {SearchKey} from '@libs/SearchKeyUtils';
import {savedSearchIDToSearchKey} from '@libs/SearchKeyUtils';
import {buildSearchQueryJSON, buildSearchQueryString, getFooterSelectionFromQuery, serializeQueryJSONForBackend} from '@libs/SearchQueryUtils';
import {buildSearchQueryJSON, buildSearchQueryString, getFooterSelectionFromQuery, normalizeDatePresetsInQuery, serializeQueryJSONForBackend} from '@libs/SearchQueryUtils';
import {getExpenseReportIDs, TODO_SEARCH_KEYS} from '@libs/SearchUIUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {cancelSpan, endSpan, startSpan} from '@libs/telemetry/activeSpans';
Expand Down Expand Up @@ -900,8 +900,10 @@ function getOnyxLoadingData(
}

function saveSearch({id, queryJSON, newName}: {id: string; queryJSON: Readonly<SearchQueryJSON>; newName?: string}) {
const saveSearchName = newName ?? queryJSON?.inputQuery ?? '';
const jsonQuery = JSON.stringify(queryJSON);
const normalizedQuery = normalizeDatePresetsInQuery(queryJSON.inputQuery);
const savedQueryJSON = normalizedQuery === queryJSON.inputQuery ? queryJSON : (buildSearchQueryJSON(normalizedQuery) ?? queryJSON);
Comment thread
c3024 marked this conversation as resolved.
Resolved
const saveSearchName = newName ?? savedQueryJSON?.inputQuery ?? '';
const jsonQuery = JSON.stringify(savedQueryJSON);

const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.SAVED_SEARCHES>> = [
{
Expand All @@ -911,7 +913,7 @@ function saveSearch({id, queryJSON, newName}: {id: string; queryJSON: Readonly<S
[id]: {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
name: saveSearchName,
query: queryJSON.inputQuery,
query: savedQueryJSON.inputQuery,
},
},
},
Expand Down
Loading
Loading