Skip to content
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
12 changes: 12 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,17 @@ function getParentReport(report: OnyxEntry<Report>): OnyxEntry<Report> {
return getReport(report.parentReportID, allReports);
}

/**
* Returns the appropriate report to use for display.
* For invoice chat threads, returns the parent invoice report.
* For other cases, returns the provided report.
*/
function getReportForHeader(report: OnyxEntry<Report>): OnyxEntry<Report> {
const parentReport = getParentReport(report);
const isParentInvoiceAndIsChatThread = isChatThread(report) && isInvoiceReport(parentReport);
return isParentInvoiceAndIsChatThread ? parentReport : report;
}

/**
* Returns the root parentReport if the given report is nested.
* Uses recursion to iterate any depth of nested reports.
Expand Down Expand Up @@ -13325,6 +13336,7 @@ export {
isOneTransactionReport,
isTrackExpenseReportNew,
shouldHideSingleReportField,
getReportForHeader,
};

export type {
Expand Down
7 changes: 5 additions & 2 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
getParticipantsList,
getReportDescription,
getReportFieldKey,
getReportForHeader,
isAdminOwnerApproverOrReportOwner,
isArchivedNonExpenseReport,
isCanceledTaskReport as isCanceledTaskReportUtil,
Expand Down Expand Up @@ -342,8 +343,10 @@

const shouldShowLeaveButton = canLeaveChat(report, policy, !!reportNameValuePairs?.private_isArchived);
const shouldShowGoToWorkspace = shouldShowPolicy(policy, false, currentUserPersonalDetails?.email) && !policy?.isJoinRequestPending;

const reportName = isGroupChat ? getReportNameFromReportNameUtils(report, reportAttributes) : Parser.htmlToText(getReportNameFromReportNameUtils(report, reportAttributes));
const reportForHeader = useMemo(() => getReportForHeader(report), [report]);
const reportName = isGroupChat
? getReportNameFromReportNameUtils(reportForHeader, reportAttributes)
: Parser.htmlToText(getReportNameFromReportNameUtils(reportForHeader, reportAttributes));
const additionalRoomDetails =
(isPolicyExpenseChat && !!report?.isOwnPolicyExpenseChat) || isExpenseReportUtil(report) || isPolicyExpenseChat || isInvoiceRoom
? chatRoomSubtitle
Expand Down Expand Up @@ -879,7 +882,7 @@
deleteTransactions([iouTransactionID], duplicateTransactions, duplicateTransactionViolations, currentSearchHash, isSingleTransactionView);
removeTransaction(iouTransactionID);
}
}, [

Check warning on line 885 in src/pages/ReportDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has a missing dependency: 'allTransactionViolations'. Either include it or remove the dependency array
ancestors,
caseID,
requestParentReportAction,
Expand Down
13 changes: 11 additions & 2 deletions src/pages/RoomMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ import Parser from '@libs/Parser';
import {getDisplayNameOrDefault, getPersonalDetailsByIDs} from '@libs/PersonalDetailsUtils';
import {isPolicyEmployee as isPolicyEmployeeUtils, isUserPolicyAdmin} from '@libs/PolicyUtils';
import {getReportAction} from '@libs/ReportActionsUtils';
import {getReportName, getReportPersonalDetailsParticipants, isChatThread, isDefaultRoom, isPolicyExpenseChat as isPolicyExpenseChatUtils, isUserCreatedPolicyRoom} from '@libs/ReportUtils';
import {
getReportForHeader,
getReportName,
getReportPersonalDetailsParticipants,
isChatThread,
isDefaultRoom,
isPolicyExpenseChat as isPolicyExpenseChatUtils,
isUserCreatedPolicyRoom,
} from '@libs/ReportUtils';
import StringUtils from '@libs/StringUtils';
import {clearAddRoomMemberError, openRoomMembersPage, removeFromRoom} from '@userActions/Report';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -71,6 +79,7 @@ function RoomMembersPage({report, policy}: RoomMembersPageProps) {
const isPolicyExpenseChat = useMemo(() => isPolicyExpenseChatUtils(report), [report]);
const backTo = route.params.backTo;
const isReportArchived = useReportIsArchived(report.reportID);
const reportForSubtitle = useMemo(() => getReportForHeader(report), [report]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be I missed earlier, we defined this but I don't see it being used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.


const {chatParticipants: participants, personalDetailsParticipants} = useMemo(
() => getReportPersonalDetailsParticipants(report, personalDetails, reportMetadata, true),
Expand Down Expand Up @@ -417,7 +426,7 @@ function RoomMembersPage({report, policy}: RoomMembersPageProps) {
<HeaderWithBackButton
title={selectionModeHeader ? translate('common.selectMultiple') : translate('workspace.common.members')}
// eslint-disable-next-line @typescript-eslint/no-deprecated
subtitle={StringUtils.lineBreaksToSpaces(shouldParserToHTML ? Parser.htmlToText(getReportName(report)) : getReportName(report))}
subtitle={StringUtils.lineBreaksToSpaces(shouldParserToHTML ? Parser.htmlToText(getReportName(reportForSubtitle)) : getReportName(reportForSubtitle))}
onBackButtonPress={() => {
if (isMobileSelectionModeEnabled) {
setSelectedMembers([]);
Expand Down
5 changes: 4 additions & 1 deletion src/pages/ShareCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getParentNavigationSubtitle,
getParticipantsAccountIDsForDisplay,
getPolicyName,
getReportForHeader,
getReportName,
isExpenseReport,
isMoneyRequestReport,
Expand Down Expand Up @@ -99,8 +100,10 @@ function ShareCodePage({report, policy, backTo}: ShareCodePageProps) {
return currentUserPersonalDetails.login;
}, [report, currentUserPersonalDetails.login, isReport, isReportArchived, isParentReportArchived, formatPhoneNumber]);

const reportForTitle = useMemo(() => getReportForHeader(report), [report]);

// eslint-disable-next-line @typescript-eslint/no-deprecated
const title = isReport ? getReportName(report) : (currentUserPersonalDetails.displayName ?? '');
const title = isReport ? getReportName(reportForTitle) : (currentUserPersonalDetails.displayName ?? '');
const urlWithTrailingSlash = addTrailingForwardSlash(environmentURL);
const url = isReport
? `${urlWithTrailingSlash}${ROUTES.REPORT_WITH_ID.getRoute(report.reportID)}`
Expand Down
15 changes: 14 additions & 1 deletion src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import {
getPolicyName,
getReportDescription,
getReportName,
getReportStatusColorStyle,
getReportStatusTranslation,
hasReportNameError,
isAdminRoom,
isArchivedReport,
Expand All @@ -59,6 +61,7 @@ import {
isDeprecatedGroupDM,
isExpenseRequest,
isGroupChat as isGroupChatReportUtils,
isInvoiceReport,
isInvoiceRoom,
isOneTransactionThread,
isOpenTaskReport,
Expand Down Expand Up @@ -139,7 +142,9 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
const isChatRoom = isChatRoomReportUtils(report);
const isPolicyExpenseChat = isPolicyExpenseChatReportUtils(report);
const isTaskReport = isTaskReportReportUtils(report);
const reportHeaderData = !isTaskReport && !isChatThread && report?.parentReportID ? parentReport : report;
// This is used to check if the report is a chat thread and has a parent invoice report.
const isParentInvoiceAndIsChatThread = isChatThread && !!parentReport && isInvoiceReport(parentReport);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible to simplify this to use util?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though this too to move in util but this has another logic too to decide whether to pick the parent report or not and I didn't want to break anything that's why I left HeaderView as it is.

Even if we move this to util then we do need isParentInvoiceAndIsChatThread here as there are two factors to decide whether to pick the parent report or not in HeaderView, other locations has only one.

const reportHeaderData = (!isTaskReport && !isChatThread && report?.parentReportID) || isParentInvoiceAndIsChatThread ? parentReport : report;
const isParentOneTransactionThread = isOneTransactionThread(parentReport, grandParentReport, grandParentReportActions?.[`${parentReport?.parentReportActionID}`]);
const parentNavigationReport = isParentOneTransactionThread ? parentReport : reportHeaderData;
const isReportHeaderDataArchived = useReportIsArchived(reportHeaderData?.reportID);
Expand All @@ -148,6 +153,11 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
// eslint-disable-next-line @typescript-eslint/no-deprecated
const title = getReportName(reportHeaderData, policy, parentReportAction, personalDetails, invoiceReceiverPolicy, undefined, undefined, isReportHeaderDataArchived);
const subtitle = getChatRoomSubtitle(reportHeaderData, false, isReportHeaderDataArchived);
// This is used to get the status badge for invoice report subtitle.
const statusTextForInvoiceReport = isParentInvoiceAndIsChatThread
? getReportStatusTranslation({stateNum: reportHeaderData?.stateNum, statusNum: reportHeaderData?.statusNum, translate})
: undefined;
const statusColorForInvoiceReport = isParentInvoiceAndIsChatThread ? getReportStatusColorStyle(theme, reportHeaderData?.stateNum, reportHeaderData?.statusNum) : {};
const isParentReportHeaderDataArchived = useReportIsArchived(reportHeaderData?.parentReportID);
const parentNavigationSubtitleData = getParentNavigationSubtitle(parentNavigationReport, isParentReportHeaderDataArchived);
const reportDescription = Parser.htmlToText(getReportDescription(report));
Expand Down Expand Up @@ -320,6 +330,9 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
</CaretWrapper>
{!isEmptyObject(parentNavigationSubtitleData) && (
<ParentNavigationSubtitle
statusText={statusTextForInvoiceReport}
statusTextColor={statusColorForInvoiceReport?.textColor}
statusTextBackgroundColor={statusColorForInvoiceReport?.backgroundColor}
parentNavigationSubtitleData={parentNavigationSubtitleData}
reportID={parentNavigationReport?.reportID}
parentReportID={parentNavigationReport?.parentReportID}
Expand Down
Loading