Skip to content

Commit 907ec86

Browse files
authored
Merge pull request #62275 from software-mansion-labs/korytko/correct-62002-and-61777
Correct PR #62002 & (reverted) #61777
2 parents 16a4d7b + 3b18f4a commit 907ec86

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/components/MoneyRequestReportView/MoneyRequestReportView.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
1818
import Log from '@libs/Log';
1919
import {selectAllTransactionsForReport, shouldDisplayReportTableView} from '@libs/MoneyRequestReportUtils';
2020
import navigationRef from '@libs/Navigation/navigationRef';
21-
import {getOneTransactionThreadReportID, isDeletedParentAction, isMoneyRequestAction} from '@libs/ReportActionsUtils';
21+
import {getFilteredReportActionsForReportView, getOneTransactionThreadReportID, isMoneyRequestAction} from '@libs/ReportActionsUtils';
2222
import {canEditReportAction, getReportOfflinePendingActionAndErrors, isReportTransactionThread} from '@libs/ReportUtils';
2323
import {buildCannedSearchQuery} from '@libs/SearchQueryUtils';
2424
import Navigation from '@navigation/Navigation';
@@ -95,8 +95,9 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
9595
const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`, {initialValue: false, canBeMissing: true});
9696
const {reportPendingAction, reportErrors} = getReportOfflinePendingActionAndErrors(report);
9797

98-
const {reportActions: reportActionsWithDeletedExpenses, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID);
99-
const reportActions = reportActionsWithDeletedExpenses.filter((value) => !isDeletedParentAction(value));
98+
const {reportActions: unfilteredReportActions, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID);
99+
const reportActions = getFilteredReportActionsForReportView(unfilteredReportActions);
100+
100101
const transactionThreadReportID = getOneTransactionThreadReportID(reportID, reportActions ?? [], isOffline);
101102

102103
const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {

src/libs/ReportActionsUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,17 @@ function filterOutDeprecatedReportActions(reportActions: OnyxEntry<ReportActions
10121012
.map((entry) => entry[1]);
10131013
}
10141014

1015+
/**
1016+
* Helper for filtering out Report Actions that are either:
1017+
* - ReportPreview with shouldShow set to false and without a pending action
1018+
* - Money request with parent action deleted
1019+
*/
1020+
function getFilteredReportActionsForReportView(actions: ReportAction[]) {
1021+
const isDeletedMoneyRequest = (action: ReportAction) => isDeletedParentAction(action) && isMoneyRequestAction(action);
1022+
const isHiddenReportPreviewWithoutPendingAction = (action: ReportAction) => isReportPreviewAction(action) && action.pendingAction === undefined && !action.shouldShow;
1023+
return actions.filter((action) => !isDeletedMoneyRequest(action) && !isHiddenReportPreviewWithoutPendingAction(action));
1024+
}
1025+
10151026
/**
10161027
* This method returns the report actions that are ready for display in the ReportActionsView.
10171028
* The report actions need to be sorted by created timestamp first, and reportActionID second
@@ -2533,6 +2544,7 @@ export {
25332544
getRemovedConnectionMessage,
25342545
getActionableJoinRequestPendingReportAction,
25352546
getReportActionsLength,
2547+
getFilteredReportActionsForReportView,
25362548
wasMessageReceivedWhileOffline,
25372549
shouldShowAddMissingDetails,
25382550
getJoinRequestMessage,

src/pages/home/ReportScreen.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
4040
import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils';
4141
import {
4242
getCombinedReportActions,
43+
getFilteredReportActionsForReportView,
4344
getOneTransactionThreadReportID,
4445
isCreatedAction,
4546
isDeletedParentAction,
@@ -266,14 +267,8 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
266267
const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: (value) => value?.accountID, canBeMissing: false});
267268
const [currentUserEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (value) => value?.email, canBeMissing: false});
268269
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
269-
const {
270-
reportActions: reportActionsWithDeletedExpenses,
271-
linkedAction,
272-
sortedAllReportActions,
273-
hasNewerActions,
274-
hasOlderActions,
275-
} = usePaginatedReportActions(reportID, reportActionIDFromRoute);
276-
const reportActions = reportActionsWithDeletedExpenses.filter((value) => !isDeletedParentAction(value));
270+
const {reportActions: unfilteredReportActions, linkedAction, sortedAllReportActions, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID, reportActionIDFromRoute);
271+
const reportActions = getFilteredReportActionsForReportView(unfilteredReportActions);
277272

278273
const [isBannerVisible, setIsBannerVisible] = useState(true);
279274
const [scrollPosition, setScrollPosition] = useState<ScrollPosition>({});

0 commit comments

Comments
 (0)