11import { useDeferredValue } from 'react' ;
22import { buildSearchQueryJSON , buildUserReadableQueryString } from '@libs/SearchQueryUtils' ;
3+ import type { BuildUserReadableQueryStringParams } from '@libs/SearchQueryUtils' ;
34import type { SaveSearchItem } from '@src/types/onyx/SaveSearch' ;
45
56type SavedSearchCollection = Record < string , SaveSearchItem > ;
6- type UserReadableQueryParams = Parameters < typeof buildUserReadableQueryString > [ 0 ] ;
77
8- type SavedSearchTitlesHookParams = {
8+ type SavedSearchTitlesHookParams = Omit < BuildUserReadableQueryStringParams , 'queryJSON' | 'autoCompleteWithSpace' > & {
99 savedSearches : SavedSearchCollection | undefined ;
10- personalDetails : UserReadableQueryParams [ 'PersonalDetails' ] ;
11- reports : UserReadableQueryParams [ 'reports' ] ;
12- taxRates : UserReadableQueryParams [ 'taxRates' ] ;
13- cardsForSavedSearchDisplay : UserReadableQueryParams [ 'cardList' ] ;
14- allFeeds : UserReadableQueryParams [ 'cardFeeds' ] ;
15- allPolicies : UserReadableQueryParams [ 'policies' ] ;
16- currentUserAccountID : number ;
17- translate : UserReadableQueryParams [ 'translate' ] ;
18- feedKeysWithCards : UserReadableQueryParams [ 'feedKeysWithCards' ] ;
19- reportAttributes : UserReadableQueryParams [ 'reportAttributes' ] ;
2010 enabled ?: boolean ;
2111} ;
2212
23- function useSavedSearchTitles ( {
24- savedSearches,
25- personalDetails,
26- reports,
27- taxRates,
28- cardsForSavedSearchDisplay,
29- allFeeds,
30- allPolicies,
31- currentUserAccountID,
32- translate,
33- feedKeysWithCards,
34- reportAttributes,
35- enabled = true ,
36- } : SavedSearchTitlesHookParams ) : Map < string , string > {
37- const deferredReports = useDeferredValue ( reports ) ;
38- const deferredPolicies = useDeferredValue ( allPolicies ) ;
39- const deferredPersonalDetails = useDeferredValue ( personalDetails ) ;
40- const deferredReportAttributes = useDeferredValue ( reportAttributes ) ;
41- const deferredTaxRates = useDeferredValue ( taxRates ) ;
42- const deferredCardsForSavedSearchDisplay = useDeferredValue ( cardsForSavedSearchDisplay ) ;
43- const deferredAllFeeds = useDeferredValue ( allFeeds ) ;
44- const deferredFeedKeysWithCards = useDeferredValue ( feedKeysWithCards ) ;
13+ function useSavedSearchTitles ( { savedSearches, translate, enabled = true , ...rest } : SavedSearchTitlesHookParams ) : Map < string , string > {
14+ // `savedSearches` and `translate` are intentionally excluded from the deferred object.
15+ // `savedSearches` drives which items appear in the list — deferring it would cause a flash
16+ // `translate` is a stable function reference that never triggers heavy re-computation on its own.
17+ const deferredRest = useDeferredValue ( rest ) ;
18+ const { PersonalDetails, reports, taxRates, cardList, cardFeeds, policies, currentUserAccountID, feedKeysWithCards, reportAttributes} = deferredRest ;
4519
4620 const titles = new Map < string , string > ( ) ;
4721
@@ -61,17 +35,17 @@ function useSavedSearchTitles({
6135
6236 const title = buildUserReadableQueryString ( {
6337 queryJSON : itemJsonQuery ,
64- PersonalDetails : deferredPersonalDetails ,
65- reports : deferredReports ,
66- taxRates : deferredTaxRates ,
67- cardList : deferredCardsForSavedSearchDisplay ,
68- cardFeeds : deferredAllFeeds ,
69- policies : deferredPolicies ,
38+ PersonalDetails,
39+ reports,
40+ taxRates,
41+ cardList,
42+ cardFeeds,
43+ policies,
7044 currentUserAccountID,
7145 autoCompleteWithSpace : false ,
7246 translate,
73- feedKeysWithCards : deferredFeedKeysWithCards ,
74- reportAttributes : deferredReportAttributes ,
47+ feedKeysWithCards,
48+ reportAttributes,
7549 } ) ;
7650 titles . set ( item . query , title ) ;
7751 }
0 commit comments