Skip to content

Commit a35ccc6

Browse files
authored
Merge pull request #38267 from dukenv0307/fix/37448-incorrect-title-for-edit-request-message
Fix/37448: Incorrect title thread
2 parents 9726cfb + f5a2eff commit a35ccc6

4 files changed

+43
-5
lines changed

src/libs/ModifiedExpenseMessage.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import ONYXKEYS from '@src/ONYXKEYS';
55
import type {PolicyTagList, ReportAction} from '@src/types/onyx';
66
import * as CurrencyUtils from './CurrencyUtils';
77
import DateUtils from './DateUtils';
8+
import getReportPolicyID from './getReportPolicyID';
89
import * as Localize from './Localize';
910
import * as PolicyUtils from './PolicyUtils';
10-
import * as ReportUtils from './ReportUtils';
1111
import type {ExpenseOriginalMessage} from './ReportUtils';
1212
import * as TransactionUtils from './TransactionUtils';
1313

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

107107
const removalFragments: string[] = [];
108108
const setFragments: string[] = [];

src/libs/ReportActionsUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function isReportPreviewAction(reportAction: OnyxEntry<ReportAction>): boolean {
135135
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW;
136136
}
137137

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

src/libs/ReportUtils.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ import * as store from './actions/ReimbursementAccount/store';
5555
import * as CollectionUtils from './CollectionUtils';
5656
import * as CurrencyUtils from './CurrencyUtils';
5757
import DateUtils from './DateUtils';
58+
import originalGetReportPolicyID from './getReportPolicyID';
5859
import isReportMessageAttachment from './isReportMessageAttachment';
5960
import localeCompare from './LocaleCompare';
6061
import * as LocalePhoneNumber from './LocalePhoneNumber';
6162
import * as Localize from './Localize';
6263
import {isEmailPublicDomain} from './LoginUtils';
64+
import ModifiedExpenseMessage from './ModifiedExpenseMessage';
6365
import linkingConfig from './Navigation/linkingConfig';
6466
import Navigation from './Navigation/Navigation';
6567
import * as NumberUtils from './NumberUtils';
@@ -2772,6 +2774,9 @@ function getReportName(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> = nu
27722774
if (parentReportActionMessage && isArchivedRoom(report)) {
27732775
return `${parentReportActionMessage} (${Localize.translateLocal('common.archived')})`;
27742776
}
2777+
if (ReportActionsUtils.isModifiedExpenseAction(parentReportAction)) {
2778+
return ModifiedExpenseMessage.getForReportAction(report?.reportID, parentReportAction);
2779+
}
27752780
return parentReportActionMessage;
27762781
}
27772782

@@ -4619,7 +4624,7 @@ function getReportIDFromLink(url: string | null): string {
46194624
* Get the report policyID given a reportID
46204625
*/
46214626
function getReportPolicyID(reportID?: string): string | undefined {
4622-
return getReport(reportID)?.policyID;
4627+
return originalGetReportPolicyID(reportID);
46234628
}
46244629

46254630
/**

src/libs/getReportPolicyID.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
2+
import Onyx from 'react-native-onyx';
3+
import ONYXKEYS from '@src/ONYXKEYS';
4+
import type {Report} from '@src/types/onyx';
5+
import type {EmptyObject} from '@src/types/utils/EmptyObject';
6+
7+
let allReports: OnyxCollection<Report>;
8+
Onyx.connect({
9+
key: ONYXKEYS.COLLECTION.REPORT,
10+
waitForCollectionCallback: true,
11+
callback: (value) => (allReports = value),
12+
});
13+
14+
/**
15+
* Get the report given a reportID
16+
*/
17+
function getReport(reportID: string | undefined): OnyxEntry<Report> | EmptyObject {
18+
if (!allReports) {
19+
return {};
20+
}
21+
22+
return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? {};
23+
}
24+
25+
/**
26+
* Get the report policyID given a reportID.
27+
* We need to define this method in a separate file to avoid cyclic dependency.
28+
*/
29+
function getReportPolicyID(reportID?: string): string | undefined {
30+
return getReport(reportID)?.policyID;
31+
}
32+
33+
export default getReportPolicyID;

0 commit comments

Comments
 (0)