Skip to content

Commit

Permalink
Merge pull request #38267 from dukenv0307/fix/37448-incorrect-title-f…
Browse files Browse the repository at this point in the history
…or-edit-request-message

Fix/37448: Incorrect title thread
  • Loading branch information
cristipaval authored Mar 25, 2024
2 parents 9726cfb + f5a2eff commit a35ccc6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {PolicyTagList, ReportAction} from '@src/types/onyx';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import getReportPolicyID from './getReportPolicyID';
import * as Localize from './Localize';
import * as PolicyUtils from './PolicyUtils';
import * as ReportUtils from './ReportUtils';
import type {ExpenseOriginalMessage} from './ReportUtils';
import * as TransactionUtils from './TransactionUtils';

Expand Down Expand Up @@ -97,12 +97,12 @@ function getForDistanceRequest(newDistance: string, oldDistance: string, newAmou
* ModifiedExpense::getNewDotComment in Web-Expensify should match this.
* If we change this function be sure to update the backend as well.
*/
function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry<ReportAction>): string {
function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry<ReportAction> | ReportAction | Record<string, never>): string {
if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE) {
return '';
}
const reportActionOriginalMessage = reportAction?.originalMessage as ExpenseOriginalMessage | undefined;
const policyID = ReportUtils.getReportPolicyID(reportID) ?? '';
const policyID = getReportPolicyID(reportID) ?? '';

const removalFragments: string[] = [];
const setFragments: string[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function isReportPreviewAction(reportAction: OnyxEntry<ReportAction>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW;
}

function isModifiedExpenseAction(reportAction: OnyxEntry<ReportAction>): boolean {
function isModifiedExpenseAction(reportAction: OnyxEntry<ReportAction> | ReportAction | Record<string, never>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE;
}

Expand Down
7 changes: 6 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ import * as store from './actions/ReimbursementAccount/store';
import * as CollectionUtils from './CollectionUtils';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import originalGetReportPolicyID from './getReportPolicyID';
import isReportMessageAttachment from './isReportMessageAttachment';
import localeCompare from './LocaleCompare';
import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Localize from './Localize';
import {isEmailPublicDomain} from './LoginUtils';
import ModifiedExpenseMessage from './ModifiedExpenseMessage';
import linkingConfig from './Navigation/linkingConfig';
import Navigation from './Navigation/Navigation';
import * as NumberUtils from './NumberUtils';
Expand Down Expand Up @@ -2772,6 +2774,9 @@ function getReportName(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> = nu
if (parentReportActionMessage && isArchivedRoom(report)) {
return `${parentReportActionMessage} (${Localize.translateLocal('common.archived')})`;
}
if (ReportActionsUtils.isModifiedExpenseAction(parentReportAction)) {
return ModifiedExpenseMessage.getForReportAction(report?.reportID, parentReportAction);
}
return parentReportActionMessage;
}

Expand Down Expand Up @@ -4619,7 +4624,7 @@ function getReportIDFromLink(url: string | null): string {
* Get the report policyID given a reportID
*/
function getReportPolicyID(reportID?: string): string | undefined {
return getReport(reportID)?.policyID;
return originalGetReportPolicyID(reportID);
}

/**
Expand Down
33 changes: 33 additions & 0 deletions src/libs/getReportPolicyID.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report} from '@src/types/onyx';
import type {EmptyObject} from '@src/types/utils/EmptyObject';

let allReports: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => (allReports = value),
});

/**
* Get the report given a reportID
*/
function getReport(reportID: string | undefined): OnyxEntry<Report> | EmptyObject {
if (!allReports) {
return {};
}

return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? {};
}

/**
* Get the report policyID given a reportID.
* We need to define this method in a separate file to avoid cyclic dependency.
*/
function getReportPolicyID(reportID?: string): string | undefined {
return getReport(reportID)?.policyID;
}

export default getReportPolicyID;

0 comments on commit a35ccc6

Please sign in to comment.