From 3e8c8a4a9e0cad201896fcbfdb6dab22bea5af12 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 11 Oct 2024 11:42:24 -0600 Subject: [PATCH] sort filters --- src/pages/Search/AdvancedSearchFilters.tsx | 72 +++++++++++----------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index 1a97092adf2d..54b62a61724d 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -274,42 +274,44 @@ function AdvancedSearchFilters() { applyFiltersAndNavigate(); }; - const filters = typeFiltersKeys[currentType].map((key) => { - const onPress = singleExecution(waitForNavigate(() => Navigation.navigate(baseFilterConfig[key].route))); - let filterTitle; - if ( - key === CONST.SEARCH.SYNTAX_FILTER_KEYS.DATE || - key === CONST.SEARCH.SYNTAX_FILTER_KEYS.AMOUNT || - key === CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY || - key === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY || - key === CONST.SEARCH.SYNTAX_FILTER_KEYS.DESCRIPTION || - key === CONST.SEARCH.SYNTAX_FILTER_KEYS.MERCHANT || - key === CONST.SEARCH.SYNTAX_FILTER_KEYS.REPORT_ID || - key === CONST.SEARCH.SYNTAX_FILTER_KEYS.KEYWORD || - key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG - ) { - filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, key, translate); - } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID) { - if (Object.keys(cardList).length === 0) { - return undefined; + const filters = typeFiltersKeys[currentType] + .map((key) => { + const onPress = singleExecution(waitForNavigate(() => Navigation.navigate(baseFilterConfig[key].route))); + let filterTitle; + if ( + key === CONST.SEARCH.SYNTAX_FILTER_KEYS.DATE || + key === CONST.SEARCH.SYNTAX_FILTER_KEYS.AMOUNT || + key === CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY || + key === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY || + key === CONST.SEARCH.SYNTAX_FILTER_KEYS.DESCRIPTION || + key === CONST.SEARCH.SYNTAX_FILTER_KEYS.MERCHANT || + key === CONST.SEARCH.SYNTAX_FILTER_KEYS.REPORT_ID || + key === CONST.SEARCH.SYNTAX_FILTER_KEYS.KEYWORD || + key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG + ) { + filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, key, translate); + } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID) { + if (Object.keys(cardList).length === 0) { + return undefined; + } + filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, cardList); + } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE) { + filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, taxRates); + } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE) { + filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, translate); + } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM || key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TO) { + filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters[key] ?? [], personalDetails); + } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN) { + filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, translate, reports); } - filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, cardList); - } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE) { - filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, taxRates); - } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE) { - filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, translate); - } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM || key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TO) { - filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters[key] ?? [], personalDetails); - } else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN) { - filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, translate, reports); - } - return { - key, - title: filterTitle, - description: translate(baseFilterConfig[key].description), - onPress, - }; - }); + return { + key, + title: filterTitle, + description: translate(baseFilterConfig[key].description), + onPress, + }; + }) + .sort((a, b) => (a?.description ?? '')?.localeCompare(b?.description ?? '')); const displaySearchButton = queryJSON && !SearchUtils.isCannedSearchQuery(queryJSON);