From ef7f1744564d046d2abaece4b9a1dfae146042b9 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 16 Sep 2024 12:49:32 +0900 Subject: [PATCH] Merge pull request #49235 from Expensify/cmartins-fixQueryName [CP Staging] Fix saved search names (cherry picked from commit 14b5ccc38534683a4d96460ee5266732a65f3b0a) (CP triggered by luacmartins) --- src/pages/Search/SearchTypeMenu.tsx | 110 ++++++++++++++-------------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/src/pages/Search/SearchTypeMenu.tsx b/src/pages/Search/SearchTypeMenu.tsx index 3ef8188a3a43..ce30c0a8d782 100644 --- a/src/pages/Search/SearchTypeMenu.tsx +++ b/src/pages/Search/SearchTypeMenu.tsx @@ -96,63 +96,65 @@ function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) { [showDeleteModal], ); - const createSavedSearchMenuItem = useCallback( - (item: SaveSearchItem, key: string, isNarrow: boolean) => { - const baseMenuItem: SavedSearchMenuItem = { - key, - title: item.name, - hash: key, - query: item.query, - shouldShowRightComponent: true, - focused: Number(key) === hash, - onPress: () => { - SearchActions.clearAllFilters(); - Navigation.navigate(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query: item?.query ?? ''})); + const createSavedSearchMenuItem = (item: SaveSearchItem, key: string, isNarrow: boolean) => { + let title = item.name; + if (title === item.query) { + const jsonQuery = SearchUtils.buildSearchQueryJSON(item.query) ?? ({} as SearchQueryJSON); + title = SearchUtils.getSearchHeaderTitle(jsonQuery, personalDetails, cardList, reports, taxRates); + } + const baseMenuItem: SavedSearchMenuItem = { + key, + title, + hash: key, + query: item.query, + shouldShowRightComponent: true, + focused: Number(key) === hash, + onPress: () => { + SearchActions.clearAllFilters(); + Navigation.navigate(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query: item?.query ?? ''})); + }, + rightComponent: ( + + ), + styles: [styles.alignItemsCenter], + }; + + if (!isNarrow) { + return { + ...baseMenuItem, + shouldRenderTooltip: !shouldHideSavedSearchRenameTooltip, + tooltipAnchorAlignment: { + horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, + vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM, + }, + tooltipShiftHorizontal: -32, + tooltipShiftVertical: 15, + tooltipWrapperStyle: [styles.bgPaleGreen, styles.mh4, styles.pv2], + renderTooltipContent: () => { + SearchActions.dismissSavedSearchRenameTooltip(); + return ( + + + {translate('search.saveSearchTooltipText')} + + ); }, - rightComponent: ( - - ), - styles: [styles.alignItemsCenter], }; + } - if (!isNarrow) { - return { - ...baseMenuItem, - shouldRenderTooltip: !shouldHideSavedSearchRenameTooltip, - tooltipAnchorAlignment: { - horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, - vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM, - }, - tooltipShiftHorizontal: -32, - tooltipShiftVertical: 15, - tooltipWrapperStyle: [styles.bgPaleGreen, styles.mh4, styles.pv2], - renderTooltipContent: () => { - SearchActions.dismissSavedSearchRenameTooltip(); - return ( - - - {translate('search.saveSearchTooltipText')} - - ); - }, - }; - } - - return baseMenuItem; - }, - [hash, styles, getOverflowMenu, translate, shouldHideSavedSearchRenameTooltip], - ); + return baseMenuItem; + }; const savedSearchesMenuItems = () => { if (!savedSearches) {