Skip to content

Commit

Permalink
Merge pull request #43518 from kmbcook/fix/issue-41519-get-all-ancestors
Browse files Browse the repository at this point in the history
Reinstate fix get all ancestors in a thread
  • Loading branch information
marcochavezf authored Aug 6, 2024
2 parents aae2e01 + daacbd0 commit 9aa6134
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 59 deletions.
13 changes: 2 additions & 11 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6933,14 +6933,12 @@ function getAllAncestorReportActions(report: Report | null | undefined): Ancesto
let parentReportID = report.parentReportID;
let parentReportActionID = report.parentReportActionID;

// Store the child of parent report
let currentReport = report;

while (parentReportID) {
const parentReport = getReportOrDraftReport(parentReportID);
const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID ?? '-1');

if (
!parentReport ||
!parentReportAction ||
(ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportActionsUtils.isSentMoneyReportAction(parentReportAction)) ||
ReportActionsUtils.isReportPreviewAction(parentReportAction)
Expand All @@ -6950,20 +6948,13 @@ function getAllAncestorReportActions(report: Report | null | undefined): Ancesto

const isParentReportActionUnread = ReportActionsUtils.isCurrentActionUnread(parentReport, parentReportAction);
allAncestors.push({
report: currentReport,
report: parentReport,
reportAction: parentReportAction,
shouldDisplayNewMarker: isParentReportActionUnread,
});

if (!parentReport) {
break;
}

parentReportID = parentReport?.parentReportID;
parentReportActionID = parentReport?.parentReportActionID;
if (!isEmptyObject(parentReport)) {
currentReport = parentReport;
}
}

return allAncestors.reverse();
Expand Down
19 changes: 4 additions & 15 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import MoneyRequestAction from '@components/ReportActionItem/MoneyRequestAction'
import ReportPreview from '@components/ReportActionItem/ReportPreview';
import TaskAction from '@components/ReportActionItem/TaskAction';
import TaskPreview from '@components/ReportActionItem/TaskPreview';
import TripDetailsView from '@components/ReportActionItem/TripDetailsView';
import TripRoomPreview from '@components/ReportActionItem/TripRoomPreview';
import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
import Text from '@components/Text';
Expand Down Expand Up @@ -153,6 +152,8 @@ type ReportActionItemProps = {
/** IF the thread divider line will be used */
shouldUseThreadDividerLine?: boolean;

hideThreadReplies?: boolean;

/** Whether context menu should be displayed */
shouldDisplayContextMenu?: boolean;
} & ReportActionItemOnyxProps;
Expand All @@ -176,6 +177,7 @@ function ReportActionItem({
isFirstVisibleReportAction = false,
shouldUseThreadDividerLine = false,
linkedTransactionRouteError,
hideThreadReplies = false,
shouldDisplayContextMenu = true,
parentReportActionForTransactionThread,
}: ReportActionItemProps) {
Expand Down Expand Up @@ -725,7 +727,7 @@ function ReportActionItem({
}
const numberOfThreadReplies = action.childVisibleActionCount ?? 0;

const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(action, report.reportID);
const shouldDisplayThreadReplies = !hideThreadReplies && ReportUtils.shouldDisplayThreadReplies(action, report.reportID);
const oldestFourAccountIDs =
action.childOldestFourAccountIDs
?.split(',')
Expand Down Expand Up @@ -817,19 +819,6 @@ function ReportActionItem({
return <ReportActionItemGrouped wrapperStyle={isWhisper ? styles.pt1 : {}}>{content}</ReportActionItemGrouped>;
};

if (action.actionName === CONST.REPORT.ACTIONS.TYPE.TRIPPREVIEW) {
if (ReportUtils.isTripRoom(report)) {
return (
<OfflineWithFeedback pendingAction={action.pendingAction}>
<TripDetailsView
tripRoomReportID={report.reportID}
shouldShowHorizontalRule={false}
/>
</OfflineWithFeedback>
);
}
}

if (action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) {
const transactionID = ReportActionsUtils.isMoneyRequestAction(parentReportActionForTransactionThread)
? ReportActionsUtils.getOriginalMessage(parentReportActionForTransactionThread)?.IOUTransactionID
Expand Down
65 changes: 38 additions & 27 deletions src/pages/home/report/ReportActionItemParentAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import TripDetailsView from '@components/ReportActionItem/TripDetailsView';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -113,35 +114,45 @@ function ReportActionItemParentAction({
>
<ThreadDivider
ancestor={ancestor}
isLinkDisabled={!ReportUtils.canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.parentReportID ?? '-1'])}
isLinkDisabled={!ReportUtils.canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.reportID ?? '-1'])}
/>
<ReportActionItem
onPress={
ReportUtils.canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.parentReportID ?? '-1'])
? () => {
const isVisibleAction = ReportActionsUtils.shouldReportActionBeVisible(ancestor.reportAction, ancestor.reportAction.reportActionID ?? '-1');
// Pop the thread report screen before navigating to the chat report.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.parentReportID ?? '-1'));
if (isVisibleAction && !isOffline) {
// Pop the chat report screen before navigating to the linked report action.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.parentReportID ?? '-1', ancestor.reportAction.reportActionID));
{ReportActionsUtils.isTripPreview(ancestor?.reportAction) ? (
<OfflineWithFeedback pendingAction={ancestor.reportAction.pendingAction}>
<TripDetailsView
tripRoomReportID={ReportActionsUtils.getOriginalMessage(ancestor.reportAction)?.linkedReportID ?? '-1'}
shouldShowHorizontalRule={false}
/>
</OfflineWithFeedback>
) : (
<ReportActionItem
onPress={
ReportUtils.canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.parentReportID ?? '-1'])
? () => {
const isVisibleAction = ReportActionsUtils.shouldReportActionBeVisible(ancestor.reportAction, ancestor.reportAction.reportActionID ?? '-1');
// Pop the thread report screen before navigating to the chat report.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.parentReportID ?? '-1'));
if (isVisibleAction && !isOffline) {
// Pop the chat report screen before navigating to the linked report action.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.parentReportID ?? '-1', ancestor.reportAction.reportActionID));
}
Timing.start(CONST.TIMING.SWITCH_REPORT);
}
Timing.start(CONST.TIMING.SWITCH_REPORT);
}
: undefined
}
parentReportAction={parentReportAction}
report={ancestor.report}
reportActions={reportActions}
transactionThreadReport={transactionThreadReport}
action={ancestor.reportAction}
displayAsGroup={false}
isMostRecentIOUReportAction={false}
shouldDisplayNewMarker={ancestor.shouldDisplayNewMarker}
index={index}
isFirstVisibleReportAction={isFirstVisibleReportAction}
shouldUseThreadDividerLine={shouldUseThreadDividerLine}
/>
: undefined
}
parentReportAction={parentReportAction}
report={ancestor.report}
reportActions={reportActions}
transactionThreadReport={transactionThreadReport}
action={ancestor.reportAction}
displayAsGroup={false}
isMostRecentIOUReportAction={false}
shouldDisplayNewMarker={ancestor.shouldDisplayNewMarker}
index={index}
isFirstVisibleReportAction={isFirstVisibleReportAction}
shouldUseThreadDividerLine={shouldUseThreadDividerLine}
hideThreadReplies
/>
)}
</OfflineWithFeedback>
))}
{shouldDisplayReplyDivider && <RepliesDivider shouldHideThreadDividerLine={shouldHideThreadDividerLine} />}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ThreadDivider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ function ThreadDivider({ancestor, isLinkDisabled = false}: ThreadDividerProps) {
Timing.start(CONST.TIMING.SWITCH_REPORT);
const isVisibleAction = ReportActionsUtils.shouldReportActionBeVisible(ancestor.reportAction, ancestor.reportAction.reportActionID ?? '-1');
// Pop the thread report screen before navigating to the chat report.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.parentReportID ?? '-1'));
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.reportID ?? '-1'));
if (isVisibleAction && !isOffline) {
// Pop the chat report screen before navigating to the linked report action.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.parentReportID ?? '-1', ancestor.reportAction.reportActionID));
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.reportID ?? '-1', ancestor.reportAction.reportActionID));
}
}}
accessibilityLabel={translate('threads.thread')}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,10 @@ describe('ReportUtils', () => {

it('should return correctly all ancestors of a thread report', () => {
const resultAncestors = [
{report: reports[1], reportAction: reportActions[0], shouldDisplayNewMarker: false},
{report: reports[2], reportAction: reportActions[1], shouldDisplayNewMarker: false},
{report: reports[3], reportAction: reportActions[2], shouldDisplayNewMarker: false},
{report: reports[4], reportAction: reportActions[3], shouldDisplayNewMarker: false},
{report: reports[0], reportAction: reportActions[0], shouldDisplayNewMarker: false},
{report: reports[1], reportAction: reportActions[1], shouldDisplayNewMarker: false},
{report: reports[2], reportAction: reportActions[2], shouldDisplayNewMarker: false},
{report: reports[3], reportAction: reportActions[3], shouldDisplayNewMarker: false},
];

expect(ReportUtils.getAllAncestorReportActions(reports[4])).toEqual(resultAncestors);
Expand Down

0 comments on commit 9aa6134

Please sign in to comment.