Skip to content

Commit e522b41

Browse files
committed
refactor code
1 parent f73eeab commit e522b41

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/libs/ReportActionsUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,13 +1249,16 @@ const isIOUActionMatchingTransactionList = (
12491249
/**
12501250
* Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions.
12511251
* Returns a reportID if there is exactly one transaction thread for the report, and null otherwise.
1252+
*
1253+
* @param ignoreAllDeletedReportActions Filter out all deleted reportActions, even if they have visible childActions.
12521254
*/
12531255
function getOneTransactionThreadReportID(
12541256
report: OnyxEntry<Report>,
12551257
chatReport: OnyxEntry<Report>,
12561258
reportActions: OnyxEntry<ReportActions> | ReportAction[],
12571259
isOffline: boolean | undefined = undefined,
12581260
reportTransactionIDs?: string[],
1261+
ignoreAllDeletedReportActions = false,
12591262
): string | undefined {
12601263
// If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report.
12611264
if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) {
@@ -1294,7 +1297,7 @@ function getOneTransactionThreadReportID(
12941297
// - the action is pending deletion and the user is offline
12951298
(!!originalMessage?.IOUTransactionID ||
12961299
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
1297-
(isMessageDeleted(action) && action.childVisibleActionCount) ||
1300+
(ignoreAllDeletedReportActions ? !isMessageDeleted(action) : isMessageDeleted(action) && action.childVisibleActionCount) ||
12981301
(action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && (isOffline ?? isNetworkOffline)))
12991302
) {
13001303
iouRequestActions.push(action);

src/libs/ReportUtils.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8872,18 +8872,16 @@ function navigateToLinkedReportAction(ancestor: Ancestor, isInNarrowPaneModal: b
88728872
let newAncestor = ancestor;
88738873
// If `parentReport` is an money report with one transaction, navigate directly to `parentReport`,
88748874
// preventing redundant navigation when threading back to the parent chat thread
8875-
if (parentReport && parentReportAction) {
8876-
const allParentReportActions = getReportActions(parentReport);
8877-
const visibleParentReportActions = Object.values(allParentReportActions ?? {}).filter(
8878-
(action) => !isMessageDeleted(action) || (action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && isOffline),
8879-
);
8880-
if (getOneTransactionThreadReportID(parentReport, getReportOrDraftReport(parentReport.chatReportID), visibleParentReportActions)) {
8881-
newAncestor = {
8882-
...ancestor,
8883-
report: parentReport,
8884-
reportAction: parentReportAction,
8885-
};
8886-
}
8875+
if (
8876+
parentReport &&
8877+
parentReportAction &&
8878+
getOneTransactionThreadReportID(parentReport, getReportOrDraftReport(parentReport.chatReportID), getReportActions(parentReport), isOffline, undefined, true)
8879+
) {
8880+
newAncestor = {
8881+
...ancestor,
8882+
report: parentReport,
8883+
reportAction: parentReportAction,
8884+
};
88878885
}
88888886

88898887
if (isInNarrowPaneModal) {

src/pages/home/HeaderView.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
3636
import Navigation from '@libs/Navigation/Navigation';
3737
import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
3838
import Parser from '@libs/Parser';
39-
import {getOneTransactionThreadReportID, getReportActions, isMessageDeleted} from '@libs/ReportActionsUtils';
39+
import {getOneTransactionThreadReportID, getReportActions} from '@libs/ReportActionsUtils';
4040
import {
4141
canJoinChat,
4242
canUserPerformWriteAction,
@@ -142,18 +142,17 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
142142
const isTaskReport = isTaskReportReportUtils(report);
143143
const [parentOfParentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReport?.parentReportID}`, {canBeMissing: true});
144144
const {isOffline} = useNetwork();
145-
const visibleParentOfParentReportActions = useMemo(() => {
146-
if (!parentOfParentReport) {
147-
return;
148-
}
149-
150-
const allReportActions = getReportActions(parentOfParentReport);
151-
return Object.values(allReportActions ?? {}).filter((action) => !isMessageDeleted(action) || (action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && isOffline));
152-
}, [parentOfParentReport, isOffline]);
153145
const reportHeaderData =
154146
((!isTaskReport && !isChatThread) ||
155147
(parentOfParentReport &&
156-
!!getOneTransactionThreadReportID(parentOfParentReport, getReportOrDraftReport(parentOfParentReport?.chatReportID), visibleParentOfParentReportActions))) &&
148+
!!getOneTransactionThreadReportID(
149+
parentOfParentReport,
150+
getReportOrDraftReport(parentOfParentReport?.chatReportID),
151+
getReportActions(parentOfParentReport),
152+
isOffline,
153+
undefined,
154+
true,
155+
))) &&
157156
report?.parentReportID
158157
? parentReport
159158
: report;

0 commit comments

Comments
 (0)