diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index ed7d2e29ecfe6..4c6c8414bb778 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -431,6 +431,7 @@ function Search({ queryJSON, isActionLoadingSet, cardFeeds, + allTransactionViolations: violations, }); return [filteredData1, filteredData1.length, allLength]; }, [ @@ -449,6 +450,7 @@ function Search({ isActionLoadingSet, cardFeeds, bankAccountList, + violations, ]); useEffect(() => { diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 62f7138d2d048..21eacc585270e 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -145,6 +145,20 @@ type TransactionMemberGroupSorting = ColumnSortMapping; type TransactionWithdrawalIDGroupSorting = ColumnSortMapping; +type GetReportSectionsParams = { + data: OnyxTypes.SearchResults['data']; + currentSearch: SearchKey; + currentAccountID: number | undefined; + currentUserEmail: string; + translate: LocalizedTranslate; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + isActionLoadingSet: ReadonlySet | undefined; + allTransactionViolations: OnyxCollection; + bankAccountList: OnyxEntry; + reportActions?: Record; + shouldSkipActionFiltering?: boolean; +}; + const transactionColumnNamesToSortingProperty: TransactionSorting = { [CONST.SEARCH.TABLE_COLUMNS.TO]: 'formattedTo' as const, [CONST.SEARCH.TABLE_COLUMNS.FROM]: 'formattedFrom' as const, @@ -362,6 +376,7 @@ type GetSectionsParams = { queryJSON?: SearchQueryJSON; isActionLoadingSet?: ReadonlySet; cardFeeds?: OnyxCollection; + allTransactionViolations?: OnyxCollection; shouldSkipActionFiltering?: boolean; }; @@ -1701,18 +1716,19 @@ function getReportActionsSections(data: OnyxTypes.SearchResults['data']): [Repor * * Do not use directly, use only via `getSections()` facade. */ -function getReportSections( - data: OnyxTypes.SearchResults['data'], - currentSearch: SearchKey, - currentAccountID: number | undefined, - currentUserEmail: string, - translate: LocalizedTranslate, - formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], - isActionLoadingSet: ReadonlySet | undefined, - bankAccountList: OnyxEntry, - reportActions: Record = {}, +function getReportSections({ + data, + currentSearch, + currentAccountID, + currentUserEmail, + translate, + formatPhoneNumber, + isActionLoadingSet, + allTransactionViolations, + bankAccountList, + reportActions = {}, shouldSkipActionFiltering = false, -): [TransactionGroupListItemType[], number] { +}: GetReportSectionsParams): [TransactionGroupListItemType[], number] { const shouldShowMerchant = getShouldShowMerchant(data); const { @@ -1804,7 +1820,7 @@ function getReportSections( const hasAnyViolationsForReport = hasAnyViolations( reportItem.reportID, - allViolations, + allTransactionViolations ?? allViolations, currentAccountID ?? CONST.DEFAULT_NUMBER_ID, currentUserEmail, allReportTransactions, @@ -1813,7 +1829,14 @@ function getReportSections( ); const hasVisibleViolationsForReport = hasAnyViolationsForReport && - ViolationsUtils.hasVisibleViolationsForUser(reportItem, allViolations, currentUserEmail, currentAccountID ?? CONST.DEFAULT_NUMBER_ID, policy, allReportTransactions); + ViolationsUtils.hasVisibleViolationsForUser( + reportItem, + allTransactionViolations ?? allViolations, + currentUserEmail, + currentAccountID ?? CONST.DEFAULT_NUMBER_ID, + policy, + allReportTransactions, + ); reportIDToTransactions[reportKey] = { ...reportItem, @@ -2085,6 +2108,7 @@ function getSections({ queryJSON, isActionLoadingSet, cardFeeds, + allTransactionViolations, shouldSkipActionFiltering, }: GetSectionsParams) { if (type === CONST.SEARCH.DATA_TYPES.CHAT) { @@ -2095,7 +2119,7 @@ function getSections({ } if (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) { - return getReportSections( + return getReportSections({ data, currentSearch, currentAccountID, @@ -2103,10 +2127,11 @@ function getSections({ translate, formatPhoneNumber, isActionLoadingSet, + allTransactionViolations, bankAccountList, reportActions, shouldSkipActionFiltering, - ); + }); } if (groupBy) {