From 65e331775c208c93eccae685ae696f258cfb95d6 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 23 Sep 2025 22:28:43 +0800 Subject: [PATCH 1/2] fix search page footer briefly shows after submit/approve/pay report --- src/components/MoneyReportHeader.tsx | 6 ++- src/components/Search/index.tsx | 38 +--------------- src/hooks/useSearchShouldCalculateTotals.ts | 50 +++++++++++++++++++++ 3 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 src/hooks/useSearchShouldCalculateTotals.ts diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 74dff42e4715..e2309fa524cc 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -15,6 +15,7 @@ import usePaymentAnimations from '@hooks/usePaymentAnimations'; import usePaymentOptions from '@hooks/usePaymentOptions'; import useReportIsArchived from '@hooks/useReportIsArchived'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import useSearchShouldCalculateTotals from '@hooks/useSearchShouldCalculateTotals'; import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsActions'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -322,6 +323,7 @@ function MoneyReportHeader({ const [isRejectEducationalModalVisible, setIsRejectEducationalModalVisible] = useState(false); const {selectedTransactionIDs, removeTransaction, clearSelectedTransactions, currentSearchQueryJSON, currentSearchKey} = useSearchContext(); + const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, currentSearchQueryJSON?.similarSearchHash, true); const beginExportWithTemplate = useCallback( (templateName: string, templateType: string, transactionIDList: string[], policyID?: string) => { @@ -429,7 +431,7 @@ function MoneyReportHeader({ if (currentSearchQueryJSON) { search({ searchKey: currentSearchKey, - shouldCalculateTotals: true, + shouldCalculateTotals, offset: 0, queryJSON: currentSearchQueryJSON, }); @@ -775,7 +777,7 @@ function MoneyReportHeader({ if (currentSearchQueryJSON) { search({ searchKey: currentSearchKey, - shouldCalculateTotals: true, + shouldCalculateTotals, offset: 0, queryJSON: currentSearchQueryJSON, }); diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 58f80dbc8a7e..54c161df4e4f 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -16,6 +16,7 @@ import useOnyx from '@hooks/useOnyx'; import usePrevious from '@hooks/usePrevious'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useSearchHighlightAndScroll from '@hooks/useSearchHighlightAndScroll'; +import useSearchShouldCalculateTotals from '@hooks/useSearchShouldCalculateTotals'; import useThemeStyles from '@hooks/useThemeStyles'; import {turnOffMobileSelectionMode, turnOnMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; import {openSearch} from '@libs/actions/Search'; @@ -28,7 +29,6 @@ import Performance from '@libs/Performance'; import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils'; import {canEditFieldOfMoneyRequest, selectArchivedReportsIdSet, selectFilteredReportActions} from '@libs/ReportUtils'; import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; -import type {SearchKey} from '@libs/SearchUIUtils'; import { createAndOpenSearchTransactionThread, getColumnsToShow, @@ -217,7 +217,6 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true}); const previousTransactions = usePrevious(transactions); const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: true}); - const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {canBeMissing: true}); const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID, {canBeMissing: true}); const [violations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); @@ -239,41 +238,8 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS const {type, status, sortBy, sortOrder, hash, similarSearchHash, groupBy} = queryJSON; const searchKey = useMemo(() => Object.values(suggestedSearches).find((search) => search.similarSearchHash === similarSearchHash)?.key, [suggestedSearches, similarSearchHash]); - const shouldCalculateTotals = useMemo(() => { - if (offset !== 0) { - return false; - } - - const savedSearchValues = Object.values(savedSearches ?? {}); - - if (!savedSearchValues.length && !searchKey) { - return false; - } - - const eligibleSearchKeys: Partial = [ - CONST.SEARCH.SEARCH_KEYS.SUBMIT, - CONST.SEARCH.SEARCH_KEYS.APPROVE, - CONST.SEARCH.SEARCH_KEYS.PAY, - CONST.SEARCH.SEARCH_KEYS.EXPORT, - CONST.SEARCH.SEARCH_KEYS.STATEMENTS, - CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CASH, - CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD, - CONST.SEARCH.SEARCH_KEYS.RECONCILIATION, - ]; - - if (eligibleSearchKeys.includes(searchKey)) { - return true; - } - - for (const savedSearch of savedSearchValues) { - const searchData = buildSearchQueryJSON(savedSearch.query); - if (searchData && searchData.similarSearchHash === similarSearchHash) { - return true; - } - } - return false; - }, [offset, savedSearches, searchKey, similarSearchHash]); + const shouldCalculateTotals = useSearchShouldCalculateTotals(searchKey, similarSearchHash, offset === 0); const previousReportActions = usePrevious(reportActions); const reportActionsArray = useMemo( diff --git a/src/hooks/useSearchShouldCalculateTotals.ts b/src/hooks/useSearchShouldCalculateTotals.ts new file mode 100644 index 000000000000..c7f10905f1d2 --- /dev/null +++ b/src/hooks/useSearchShouldCalculateTotals.ts @@ -0,0 +1,50 @@ +import {useMemo} from 'react'; +import {buildSearchQueryJSON} from '@libs/SearchQueryUtils'; +import type {SearchKey} from '@libs/SearchUIUtils'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import useOnyx from './useOnyx'; + +function useSearchShouldCalculateTotals(searchKey: SearchKey | undefined, similarSearchHash: number | undefined, enabled: boolean) { + const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {canBeMissing: true}); + + const shouldCalculateTotals = useMemo(() => { + if (!enabled) { + return false; + } + + const savedSearchValues = Object.values(savedSearches ?? {}); + + if (!savedSearchValues.length && !searchKey) { + return false; + } + + const eligibleSearchKeys: Partial = [ + CONST.SEARCH.SEARCH_KEYS.SUBMIT, + CONST.SEARCH.SEARCH_KEYS.APPROVE, + CONST.SEARCH.SEARCH_KEYS.PAY, + CONST.SEARCH.SEARCH_KEYS.EXPORT, + CONST.SEARCH.SEARCH_KEYS.STATEMENTS, + CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CASH, + CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD, + CONST.SEARCH.SEARCH_KEYS.RECONCILIATION, + ]; + + if (eligibleSearchKeys.includes(searchKey)) { + return true; + } + + for (const savedSearch of savedSearchValues) { + const searchData = buildSearchQueryJSON(savedSearch.query); + if (searchData && searchData.similarSearchHash === similarSearchHash) { + return true; + } + } + + return false; + }, [enabled, savedSearches, searchKey, similarSearchHash]); + + return shouldCalculateTotals; +} + +export default useSearchShouldCalculateTotals; From b6b31c35ed101db95cd6fc526629afe8d7550a72 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 23 Sep 2025 22:41:22 +0800 Subject: [PATCH 2/2] lint --- src/components/MoneyReportHeader.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index e2309fa524cc..24eb54155df7 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -447,6 +447,7 @@ function MoneyReportHeader({ moneyRequestReport, startAnimation, existingB2BInvoiceReport, + shouldCalculateTotals, currentSearchQueryJSON, currentSearchKey, ],