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

Fix trip summary for nested threads #56767

Merged
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
9 changes: 7 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ import {
isThreadParentMessage,
isTrackExpenseAction,
isTransactionThread,
isTripPreview,
isUnapprovedAction,
isWhisperAction,
wasActionTakenByCurrentUser,
Expand Down Expand Up @@ -4465,10 +4466,9 @@ function getReportNameInternal({
const modifiedMessage = ModifiedExpenseMessage.getForReportAction({reportOrID: report?.reportID, reportAction: parentReportAction, searchReports: reports});
return formatReportLastMessageText(modifiedMessage);
}
if (isTripRoom(report)) {
if (isTripRoom(report) && report?.reportName !== CONST.REPORT.DEFAULT_REPORT_NAME) {
return report?.reportName ?? '';
}

if (isCardIssuedAction(parentReportAction)) {
return getCardIssuedMessage({reportAction: parentReportAction, personalDetails});
}
Expand Down Expand Up @@ -8424,6 +8424,11 @@ function getAllAncestorReportActions(report: Report | null | undefined, currentU
break;
}

// For threads, we don't want to display trip summary
if (isTripPreview(parentReportAction) && allAncestors.length > 0) {
break;
}

const isParentReportActionUnread = isCurrentActionUnread(parentReport, parentReportAction);
allAncestors.push({
report: parentReport,
Expand Down
6 changes: 6 additions & 0 deletions src/pages/home/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ import ReportActionItemMessageEdit from './ReportActionItemMessageEdit';
import ReportActionItemSingle from './ReportActionItemSingle';
import ReportActionItemThread from './ReportActionItemThread';
import ReportAttachmentsContext from './ReportAttachmentsContext';
import TripSummary from './TripSummary';

type PureReportActionItemProps = {
/** Report for this action */
Expand Down Expand Up @@ -1117,6 +1118,11 @@ function PureReportActionItem({
/>
);
}

if (isTripPreview(action) && isThreadReportParentAction) {
return <TripSummary reportID={getOriginalMessage(action)?.linkedReportID} />;
}

if (isChronosOOOListAction(action)) {
return (
<ChronosOOOListActions
Expand Down
14 changes: 9 additions & 5 deletions src/pages/home/report/ReportActionItemParentAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import onyxSubscribe from '@libs/onyxSubscribe';
import {shouldReportActionBeVisible} from '@libs/ReportActionsUtils';
import {isTripPreview, shouldReportActionBeVisible} from '@libs/ReportActionsUtils';
import type {Ancestor} from '@libs/ReportUtils';
import {canCurrentUserOpenReport, canUserPerformWriteAction as canUserPerformWriteActionReportUtils, getAllAncestorReportActionIDs, getAllAncestorReportActions} from '@libs/ReportUtils';
import {navigateToConciergeChatAndDeleteReport} from '@userActions/Report';
Expand Down Expand Up @@ -111,6 +111,8 @@ function ReportActionItemParentAction({
{allAncestors.map((ancestor) => {
const ancestorReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${ancestor.report.reportID}`];
const canUserPerformWriteAction = canUserPerformWriteActionReportUtils(ancestorReport);
const shouldDisplayThreadDivider = !isTripPreview(ancestor.reportAction);

return (
<OfflineWithFeedback
key={ancestor.reportAction.reportActionID}
Expand All @@ -120,10 +122,12 @@ function ReportActionItemParentAction({
errorRowStyles={[styles.ml10, styles.mr2]}
onClose={() => navigateToConciergeChatAndDeleteReport(ancestor.report.reportID)}
>
<ThreadDivider
ancestor={ancestor}
isLinkDisabled={!canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.reportID])}
/>
{shouldDisplayThreadDivider && (
<ThreadDivider
ancestor={ancestor}
isLinkDisabled={!canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.reportID])}
/>
)}
<ReportActionItem
onPress={
canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.reportID])
Expand Down
8 changes: 1 addition & 7 deletions src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, {memo, useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {getOriginalMessage, isSentMoneyReportAction, isTransactionThread} from '@libs/ReportActionsUtils';
import {isChatThread, isInvoiceRoom, isPolicyExpenseChat, isTripRoom} from '@libs/ReportUtils';
import {isChatThread, isInvoiceRoom, isPolicyExpenseChat} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import type {Report, ReportAction} from '@src/types/onyx';
import ReportActionItem from './ReportActionItem';
import ReportActionItemParentAction from './ReportActionItemParentAction';
import TripSummary from './TripSummary';

type ReportActionsListItemRendererProps = {
/** All the data of the action item */
Expand Down Expand Up @@ -144,11 +143,6 @@ function ReportActionsListItemRenderer({

const shouldDisplayParentAction =
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED && (!isTransactionThread(parentReportAction) || isSentMoneyReportAction(parentReportAction));
const shouldDisplayTripSummary = shouldDisplayParentAction && isTripRoom(report);

if (shouldDisplayTripSummary) {
return <TripSummary report={report} />;
}

if (shouldDisplayParentAction && isChatThread(report)) {
return (
Expand Down
39 changes: 16 additions & 23 deletions src/pages/home/report/TripSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
import React from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import TripDetailsView from '@components/ReportActionItem/TripDetailsView';
import useThemeStyles from '@hooks/useThemeStyles';
import useTripTransactions from '@hooks/useTripTransactions';
import type * as OnyxTypes from '@src/types/onyx';
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground';
import RepliesDivider from './RepliesDivider';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

type TripSummaryProps = {
/** The current report is displayed */
report: OnyxEntry<OnyxTypes.Report>;
/** The report ID */
reportID: string | undefined;
};

function TripSummary({report}: TripSummaryProps) {
const styles = useThemeStyles();
const tripTransactions = useTripTransactions(report?.reportID);
function TripSummary({reportID}: TripSummaryProps) {
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID ?? CONST.DEFAULT_NUMBER_ID}`);
const tripTransactions = useTripTransactions(reportID);

if (!report?.reportID) {
if (!reportID || tripTransactions.length === 0) {
return null;
}

return (
<View style={[styles.pRelative]}>
<AnimatedEmptyStateBackground />
<OfflineWithFeedback pendingAction={report.pendingAction}>
<TripDetailsView
tripRoomReportID={report.reportID}
tripTransactions={tripTransactions}
shouldShowHorizontalRule={false}
/>
</OfflineWithFeedback>
<RepliesDivider shouldHideThreadDividerLine={false} />
</View>
<OfflineWithFeedback pendingAction={report?.pendingAction}>
<TripDetailsView
tripRoomReportID={reportID}
tripTransactions={tripTransactions}
shouldShowHorizontalRule={false}
/>
</OfflineWithFeedback>
);
}

Expand Down
Loading