diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx index 8c4e1d452ea8d..64c2c890146d9 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx @@ -18,7 +18,7 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; import Log from '@libs/Log'; import {selectAllTransactionsForReport, shouldDisplayReportTableView} from '@libs/MoneyRequestReportUtils'; import navigationRef from '@libs/Navigation/navigationRef'; -import {getOneTransactionThreadReportID, isDeletedParentAction, isMoneyRequestAction} from '@libs/ReportActionsUtils'; +import {getFilteredReportActionsForReportView, getOneTransactionThreadReportID, isMoneyRequestAction} from '@libs/ReportActionsUtils'; import {canEditReportAction, getReportOfflinePendingActionAndErrors, isReportTransactionThread} from '@libs/ReportUtils'; import {buildCannedSearchQuery} from '@libs/SearchQueryUtils'; import Navigation from '@navigation/Navigation'; @@ -95,8 +95,9 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`, {initialValue: false, canBeMissing: true}); const {reportPendingAction, reportErrors} = getReportOfflinePendingActionAndErrors(report); - const {reportActions: reportActionsWithDeletedExpenses, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID); - const reportActions = reportActionsWithDeletedExpenses.filter((value) => !isDeletedParentAction(value)); + const {reportActions: unfilteredReportActions, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID); + const reportActions = getFilteredReportActionsForReportView(unfilteredReportActions); + const transactionThreadReportID = getOneTransactionThreadReportID(reportID, reportActions ?? [], isOffline); const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 25aa61f87b3ea..55f4aa483d1e7 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1012,6 +1012,15 @@ function filterOutDeprecatedReportActions(reportActions: OnyxEntry entry[1]); } +/** + * Helper for filtering out Report Actions that are either: + * - ReportPreview with shouldShow set to false + * - Action with parent action deleted + */ +function getFilteredReportActionsForReportView(actions: ReportAction[]) { + return actions.filter((action) => !isDeletedParentAction(action) && (!isReportPreviewAction(action) || action.shouldShow)); +} + /** * This method returns the report actions that are ready for display in the ReportActionsView. * The report actions need to be sorted by created timestamp first, and reportActionID second @@ -2533,6 +2542,7 @@ export { getRemovedConnectionMessage, getActionableJoinRequestPendingReportAction, getReportActionsLength, + getFilteredReportActionsForReportView, wasMessageReceivedWhileOffline, shouldShowAddMissingDetails, getJoinRequestMessage, diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index e7c7ec6efca2c..536997bad08db 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -40,6 +40,7 @@ import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils'; import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils'; import { getCombinedReportActions, + getFilteredReportActionsForReportView, getOneTransactionThreadReportID, isCreatedAction, isDeletedParentAction, @@ -266,14 +267,8 @@ function ReportScreen({route, navigation}: ReportScreenProps) { const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: (value) => value?.accountID, canBeMissing: false}); const [currentUserEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (value) => value?.email, canBeMissing: false}); const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); - const { - reportActions: reportActionsWithDeletedExpenses, - linkedAction, - sortedAllReportActions, - hasNewerActions, - hasOlderActions, - } = usePaginatedReportActions(reportID, reportActionIDFromRoute); - const reportActions = reportActionsWithDeletedExpenses.filter((value) => !isDeletedParentAction(value)); + const {reportActions: unfilteredReportActions, linkedAction, sortedAllReportActions, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID, reportActionIDFromRoute); + const reportActions = getFilteredReportActionsForReportView(unfilteredReportActions); const [isBannerVisible, setIsBannerVisible] = useState(true); const [scrollPosition, setScrollPosition] = useState({});