@@ -4,7 +4,6 @@ import React from 'react';
44import MenuItemList from '@components/MenuItemList' ;
55import { usePersonalDetails } from '@components/OnyxListItemProvider' ;
66import { useProductTrainingContext } from '@components/ProductTrainingContext' ;
7- import type { SearchQueryJSON } from '@components/Search/types' ;
87import useDeleteSavedSearch from '@hooks/useDeleteSavedSearch' ;
98import useFeedKeysWithAssignedCards from '@hooks/useFeedKeysWithAssignedCards' ;
109import { useMemoizedLazyExpensifyIcons } from '@hooks/useLazyAsset' ;
@@ -17,20 +16,79 @@ import {setSearchContext} from '@libs/actions/Search';
1716import { mergeCardListWithWorkspaceFeeds } from '@libs/CardUtils' ;
1817import Navigation from '@libs/Navigation/Navigation' ;
1918import { getAllTaxRates } from '@libs/PolicyUtils' ;
20- import { buildSearchQueryJSON , buildUserReadableQueryString } from '@libs/SearchQueryUtils' ;
2119import type { SavedSearchMenuItem } from '@libs/SearchUIUtils' ;
2220import { createBaseSavedSearchMenuItem , getOverflowMenu as getOverflowMenuUtil } from '@libs/SearchUIUtils' ;
2321import variables from '@styles/variables' ;
2422import CONST from '@src/CONST' ;
2523import ONYXKEYS from '@src/ONYXKEYS' ;
2624import ROUTES from '@src/ROUTES' ;
2725import type { SaveSearchItem } from '@src/types/onyx/SaveSearch' ;
26+ import useSavedSearchTitles from './hooks/useSavedSearchTitles' ;
2827import SavedSearchItemThreeDotMenu from './SavedSearchItemThreeDotMenu' ;
2928
3029type SavedSearchListProps = {
3130 hash : number | undefined ;
3231} ;
3332
33+ type SavedSearchMenuItemBuilderParams = {
34+ item : SaveSearchItem ;
35+ key : string ;
36+ index : number ;
37+ hash : number | undefined ;
38+ title : string ;
39+ getOverflowMenu : ( itemName : string , itemHash : number , itemQuery : string ) => ReturnType < typeof getOverflowMenuUtil > ;
40+ shouldShowSavedSearchTooltip : boolean ;
41+ hideSavedSearchTooltip : ( ( ) => void ) | undefined ;
42+ renderSavedSearchTooltip : ( ) => React . JSX . Element ;
43+ itemStyle : SavedSearchMenuItem [ 'style' ] ;
44+ tooltipWrapperStyle : SavedSearchMenuItem [ 'tooltipWrapperStyle' ] ;
45+ } ;
46+
47+ function buildSavedSearchMenuItem ( {
48+ item,
49+ key,
50+ index,
51+ hash,
52+ title,
53+ getOverflowMenu,
54+ shouldShowSavedSearchTooltip,
55+ hideSavedSearchTooltip,
56+ renderSavedSearchTooltip,
57+ itemStyle,
58+ tooltipWrapperStyle,
59+ } : SavedSearchMenuItemBuilderParams ) : SavedSearchMenuItem {
60+ const isItemFocused = Number ( key ) === hash ;
61+ const baseMenuItem : SavedSearchMenuItem = createBaseSavedSearchMenuItem ( item , key , index , title , isItemFocused ) ;
62+
63+ return {
64+ ...baseMenuItem ,
65+ role : CONST . ROLE . TAB ,
66+ sentryLabel : CONST . SENTRY_LABEL . SEARCH . SAVED_SEARCH_MENU_ITEM ,
67+ onPress : ( ) => {
68+ setSearchContext ( false ) ;
69+ Navigation . navigate ( ROUTES . SEARCH_ROOT . getRoute ( { query : item ?. query ?? '' , name : item ?. name } ) ) ;
70+ } ,
71+ rightComponent : (
72+ < SavedSearchItemThreeDotMenu
73+ menuItems = { getOverflowMenu ( title , Number ( key ) , item . query ) }
74+ isDisabledItem = { item . pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE }
75+ hideProductTrainingTooltip = { index === 0 && shouldShowSavedSearchTooltip ? hideSavedSearchTooltip : undefined }
76+ shouldRenderTooltip = { index === 0 && shouldShowSavedSearchTooltip }
77+ renderTooltipContent = { renderSavedSearchTooltip }
78+ />
79+ ) ,
80+ style : itemStyle ,
81+ tooltipAnchorAlignment : {
82+ horizontal : CONST . MODAL . ANCHOR_ORIGIN_HORIZONTAL . RIGHT ,
83+ vertical : CONST . MODAL . ANCHOR_ORIGIN_VERTICAL . BOTTOM ,
84+ } ,
85+ tooltipShiftHorizontal : variables . savedSearchShiftHorizontal ,
86+ tooltipShiftVertical : variables . savedSearchShiftVertical ,
87+ tooltipWrapperStyle,
88+ renderTooltipContent : renderSavedSearchTooltip ,
89+ } ;
90+ }
91+
3492function SavedSearchList ( { hash} : SavedSearchListProps ) {
3593 const styles = useThemeStyles ( ) ;
3694 const { translate} = useLocalize ( ) ;
@@ -60,61 +118,42 @@ function SavedSearchList({hash}: SavedSearchListProps) {
60118 const taxRates = getAllTaxRates ( allPolicies ) ;
61119 const cardsForSavedSearchDisplay = mergeCardListWithWorkspaceFeeds ( workspaceCardList ?? CONST . EMPTY_OBJECT , cardList ) ;
62120
63- const getOverflowMenu = ( itemName : string , itemHash : number , itemQuery : string ) => getOverflowMenuUtil ( expensifyIcons , itemName , itemHash , itemQuery , translate , showDeleteModal ) ;
64-
65- const createSavedSearchMenuItem = ( item : SaveSearchItem , key : string , index : number ) => {
66- let title = item . name ;
67- if ( title === item . query ) {
68- const jsonQuery = buildSearchQueryJSON ( item . query ) ?? ( { } as SearchQueryJSON ) ;
69- title = buildUserReadableQueryString ( {
70- queryJSON : jsonQuery ,
71- PersonalDetails : personalDetails ,
72- reports,
73- taxRates,
74- cardList : cardsForSavedSearchDisplay ,
75- cardFeeds : allFeeds ,
76- policies : allPolicies ,
77- currentUserAccountID,
78- autoCompleteWithSpace : false ,
79- translate,
80- feedKeysWithCards,
81- reportAttributes,
82- } ) ;
83- }
121+ const savedSearchTitles = useSavedSearchTitles ( {
122+ savedSearches,
123+ PersonalDetails : personalDetails ,
124+ reports,
125+ taxRates,
126+ cardList : cardsForSavedSearchDisplay ,
127+ cardFeeds : allFeeds ,
128+ policies : allPolicies ,
129+ currentUserAccountID,
130+ translate,
131+ feedKeysWithCards,
132+ reportAttributes,
133+ } ) ;
84134
85- const isItemFocused = Number ( key ) === hash ;
86- const baseMenuItem : SavedSearchMenuItem = createBaseSavedSearchMenuItem ( item , key , index , title , isItemFocused ) ;
135+ const getOverflowMenu = ( itemName : string , itemHash : number , itemQuery : string ) => getOverflowMenuUtil ( expensifyIcons , itemName , itemHash , itemQuery , translate , showDeleteModal ) ;
87136
88- return {
89- ...baseMenuItem ,
90- role : CONST . ROLE . TAB ,
91- sentryLabel : CONST . SENTRY_LABEL . SEARCH . SAVED_SEARCH_MENU_ITEM ,
92- onPress : ( ) => {
93- setSearchContext ( false ) ;
94- Navigation . navigate ( ROUTES . SEARCH_ROOT . getRoute ( { query : item ?. query ?? '' , name : item ?. name } ) ) ;
95- } ,
96- rightComponent : (
97- < SavedSearchItemThreeDotMenu
98- menuItems = { getOverflowMenu ( title , Number ( key ) , item . query ) }
99- isDisabledItem = { item . pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE }
100- hideProductTrainingTooltip = { index === 0 && shouldShowSavedSearchTooltip ? hideSavedSearchTooltip : undefined }
101- shouldRenderTooltip = { index === 0 && shouldShowSavedSearchTooltip }
102- renderTooltipContent = { renderSavedSearchTooltip }
103- />
104- ) ,
105- style : [ styles . alignItemsCenter ] ,
106- tooltipAnchorAlignment : {
107- horizontal : CONST . MODAL . ANCHOR_ORIGIN_HORIZONTAL . RIGHT ,
108- vertical : CONST . MODAL . ANCHOR_ORIGIN_VERTICAL . BOTTOM ,
109- } ,
110- tooltipShiftHorizontal : variables . savedSearchShiftHorizontal ,
111- tooltipShiftVertical : variables . savedSearchShiftVertical ,
112- tooltipWrapperStyle : [ styles . mh4 , styles . pv2 , styles . productTrainingTooltipWrapper ] ,
113- renderTooltipContent : renderSavedSearchTooltip ,
114- } ;
115- } ;
137+ const itemStyle = [ styles . alignItemsCenter ] ;
138+ const tooltipWrapperStyle = [ styles . mh4 , styles . pv2 , styles . productTrainingTooltipWrapper ] ;
116139
117- const savedSearchesMenuItems = savedSearches ? Object . entries ( savedSearches ) . map ( ( [ key , item ] , index ) => createSavedSearchMenuItem ( item , key , index ) ) : [ ] ;
140+ const savedSearchesMenuItems = savedSearches
141+ ? Object . entries ( savedSearches ) . map ( ( [ key , item ] , index ) =>
142+ buildSavedSearchMenuItem ( {
143+ item,
144+ key,
145+ index,
146+ hash,
147+ title : item . name === item . query ? ( savedSearchTitles . get ( item . query ) ?? item . name ) : item . name ,
148+ getOverflowMenu,
149+ shouldShowSavedSearchTooltip,
150+ hideSavedSearchTooltip,
151+ renderSavedSearchTooltip,
152+ itemStyle,
153+ tooltipWrapperStyle,
154+ } ) ,
155+ )
156+ : [ ] ;
118157
119158 return (
120159 < MenuItemList
0 commit comments