Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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, {
Expand Down
12 changes: 12 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,17 @@ function filterOutDeprecatedReportActions(reportActions: OnyxEntry<ReportActions
.map((entry) => entry[1]);
}

/**
* Helper for filtering out Report Actions that are either:
* - ReportPreview with shouldShow set to false and without a pending action
* - Money request with parent action deleted
*/
function getFilteredReportActionsForReportView(actions: ReportAction[]) {
const isDeletedMoneyRequest = (action: ReportAction) => isDeletedParentAction(action) && isMoneyRequestAction(action);
const isHiddenReportPreviewWithoutPendingAction = (action: ReportAction) => isReportPreviewAction(action) && action.pendingAction === undefined && !action.shouldShow;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from 72547# checklist:

PR correct the filter logic to !action.shouldShow However, !action.shouldShow treats null and undefined as falsy values, incorrectly hiding valid ReportPreview actions where shouldShow is not explicitly set. so we need update toshouldShow = false

return actions.filter((action) => !isDeletedMoneyRequest(action) && !isHiddenReportPreviewWithoutPendingAction(action));
}

/**
* 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
Expand Down Expand Up @@ -2533,6 +2544,7 @@ export {
getRemovedConnectionMessage,
getActionableJoinRequestPendingReportAction,
getReportActionsLength,
getFilteredReportActionsForReportView,
wasMessageReceivedWhileOffline,
shouldShowAddMissingDetails,
getJoinRequestMessage,
Expand Down
11 changes: 3 additions & 8 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils';
import {
getCombinedReportActions,
getFilteredReportActionsForReportView,
getOneTransactionThreadReportID,
isCreatedAction,
isDeletedParentAction,
Expand Down Expand Up @@ -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<ScrollPosition>({});
Expand Down