Skip to content

Commit

Permalink
fix: remove flickering effect when loading one-expense reports
Browse files Browse the repository at this point in the history
  • Loading branch information
rinej committed Jun 26, 2024
1 parent ee436ca commit 0bda3e4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
27 changes: 19 additions & 8 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,22 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo
);
}

/**
* Returns filtered list for one transaction view
* Separated it from getCombinedReportActions, so it can be reused
*/
function getFilteredForOneTransactionView(reportActions: ReportAction[], isSelfDM = false): ReportAction[] {
const filteredReportActions = reportActions.filter((action) => {
const actionType = (action as OriginalMessageIOU).originalMessage?.type ?? '';
if (isSelfDM) {
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action);
}
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action);
});

return filteredReportActions;
}

/**
* Returns a sorted and filtered list of report actions from a report and it's associated child
* transaction thread report in order to correctly display reportActions from both reports in the one-transaction report view.
Expand All @@ -322,14 +338,7 @@ function getCombinedReportActions(reportActions: ReportAction[], transactionThre

const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM;
// Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports
const filteredReportActions = [...reportActions, ...filteredTransactionThreadReportActions].filter((action) => {
const actionType = (action as OriginalMessageIOU).originalMessage?.type ?? '';
if (isSelfDM) {
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action);
}
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action);
});
const filteredReportActions = getFilteredForOneTransactionView([...reportActions, ...filteredTransactionThreadReportActions], isSelfDM);

return getSortedReportActions(filteredReportActions, true);
}
Expand Down Expand Up @@ -877,6 +886,7 @@ function isTaskAction(reportAction: OnyxEntry<ReportAction>): boolean {
);
}

//maybe that?
/**
* Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions.
* Returns a reportID if there is exactly one transaction thread for the report, and null otherwise.
Expand Down Expand Up @@ -1322,6 +1332,7 @@ export {
wasActionTakenByCurrentUser,
isResolvedActionTrackExpense,
isTripPreview,
getFilteredForOneTransactionView,
};

export type {LastVisibleMessage};
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ function ReportActionItem({
<OfflineWithFeedback pendingAction={action.pendingAction}>
{transactionThreadReport && !isEmptyObject(transactionThreadReport) ? (
<>
{transactionCurrency !== report.currency && (
{!!transaction && transactionCurrency !== report.currency && (
<>
<MoneyReportView
report={report}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ function ReportActionsView({
createdAction.pendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE;
}

return [...actions, createdAction];
return moneyRequestActions.length === 1 ? ReportActionsUtils.getFilteredForOneTransactionView([...actions, createdAction]) : [...actions, createdAction];
}, [reportActions, report, transactionThreadReport]);

// Comments have not loaded at all yet do nothing
Expand Down

0 comments on commit 0bda3e4

Please sign in to comment.