Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate fix get all ancestors in a thread #43518

Merged
Merged
Show file tree
Hide file tree
Changes from 15 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
13 changes: 2 additions & 11 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6687,14 +6687,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 @@ -6704,20 +6702,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 RenameAction from '@components/ReportActionItem/RenameAction';
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 @@ -156,6 +155,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 @@ -180,6 +181,7 @@ function ReportActionItem({
isFirstVisibleReportAction = false,
shouldUseThreadDividerLine = false,
linkedTransactionRouteError,
hideThreadReplies = false,
shouldDisplayContextMenu = true,
parentReportActionForTransactionThread,
}: ReportActionItemProps) {
Expand Down Expand Up @@ -719,7 +721,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 @@ -811,19 +813,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
63 changes: 37 additions & 26 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 @@ -111,34 +112,44 @@ 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));
}
}
}
: 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 @@ -49,10 +49,10 @@ function ThreadDivider({ancestor, isLinkDisabled = false}: ThreadDividerProps) {
onPress={() => {
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 @@ -898,10 +898,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
Loading