From e5a4710696b414716fb8a44e0e84d9a7ddd48b41 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 14 Mar 2024 08:19:15 +0700 Subject: [PATCH 1/6] fix incorrect title thread --- src/libs/ModifiedExpenseMessage.ts | 2 +- src/libs/ReportActionsUtils.ts | 2 +- src/libs/ReportUtils.ts | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index f501244a725d..26a1a8d890ff 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -97,7 +97,7 @@ 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): string { +function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry | ReportAction | Record): string { if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE) { return ''; } diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index c158a0c2972c..b31d60242dc1 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -131,7 +131,7 @@ function isReportPreviewAction(reportAction: OnyxEntry): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; } -function isModifiedExpenseAction(reportAction: OnyxEntry): boolean { +function isModifiedExpenseAction(reportAction: OnyxEntry | ReportAction | Record): boolean { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8dc1c9967f13..c991d8771a15 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -61,6 +61,7 @@ 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'; @@ -2642,6 +2643,9 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu if (parentReportActionMessage && isArchivedRoom(report)) { return `${parentReportActionMessage} (${Localize.translateLocal('common.archived')})`; } + if (ReportActionsUtils.isModifiedExpenseAction(parentReportAction)) { + return ModifiedExpenseMessage.getForReportAction(report?.reportID, parentReportAction); + } return parentReportActionMessage; } From c3210dde8c2d89457a395e68bf29bd4a2b0b2648 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 14 Mar 2024 09:11:05 +0700 Subject: [PATCH 2/6] fix lint --- src/libs/ReportUtils.ts | 4 ++-- src/libs/getForReportAction.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/libs/getForReportAction.ts diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c991d8771a15..8c6d4e417304 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -56,12 +56,12 @@ import * as store from './actions/ReimbursementAccount/store'; import * as CollectionUtils from './CollectionUtils'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; +import getForReportAction from './getForReportAction'; 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'; @@ -2644,7 +2644,7 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu return `${parentReportActionMessage} (${Localize.translateLocal('common.archived')})`; } if (ReportActionsUtils.isModifiedExpenseAction(parentReportAction)) { - return ModifiedExpenseMessage.getForReportAction(report?.reportID, parentReportAction); + return getForReportAction(report?.reportID, parentReportAction); } return parentReportActionMessage; } diff --git a/src/libs/getForReportAction.ts b/src/libs/getForReportAction.ts new file mode 100644 index 000000000000..35ef40f9de1a --- /dev/null +++ b/src/libs/getForReportAction.ts @@ -0,0 +1,15 @@ +import type {OnyxEntry} from 'react-native-onyx'; +import type {ReportAction} from '@src/types/onyx'; +import originalModifiedExpenseMessage from './ModifiedExpenseMessage'; + +/** + * Get the report action message when expense has been modified. + * + * 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 | Record): string { + return originalModifiedExpenseMessage.getForReportAction(reportID, reportAction); +} + +export default getForReportAction; From 8ca37786df5114ad0559dcdb72af08479daea94e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 14 Mar 2024 09:18:58 +0700 Subject: [PATCH 3/6] fix revert lint fix --- src/libs/ReportUtils.ts | 4 ++-- src/libs/getForReportAction.ts | 15 --------------- 2 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 src/libs/getForReportAction.ts diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8c6d4e417304..c991d8771a15 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -56,12 +56,12 @@ import * as store from './actions/ReimbursementAccount/store'; import * as CollectionUtils from './CollectionUtils'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; -import getForReportAction from './getForReportAction'; 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'; @@ -2644,7 +2644,7 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu return `${parentReportActionMessage} (${Localize.translateLocal('common.archived')})`; } if (ReportActionsUtils.isModifiedExpenseAction(parentReportAction)) { - return getForReportAction(report?.reportID, parentReportAction); + return ModifiedExpenseMessage.getForReportAction(report?.reportID, parentReportAction); } return parentReportActionMessage; } diff --git a/src/libs/getForReportAction.ts b/src/libs/getForReportAction.ts deleted file mode 100644 index 35ef40f9de1a..000000000000 --- a/src/libs/getForReportAction.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type {OnyxEntry} from 'react-native-onyx'; -import type {ReportAction} from '@src/types/onyx'; -import originalModifiedExpenseMessage from './ModifiedExpenseMessage'; - -/** - * Get the report action message when expense has been modified. - * - * 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 | Record): string { - return originalModifiedExpenseMessage.getForReportAction(reportID, reportAction); -} - -export default getForReportAction; From f92c8338aba0e57d2e0fcbf2935824cbe99d13fd Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 14 Mar 2024 10:40:44 +0700 Subject: [PATCH 4/6] fix lint deps cycle --- src/libs/ModifiedExpenseMessage.ts | 4 ++-- src/libs/ReportUtils.ts | 3 ++- src/libs/getReportPolicyID.ts | 32 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/libs/getReportPolicyID.ts diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 26a1a8d890ff..81170a830060 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -7,9 +7,9 @@ import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; 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'; +import getReportPolicyID from './getReportPolicyID'; let allPolicyTags: OnyxCollection = {}; Onyx.connect({ @@ -102,7 +102,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr return ''; } const reportActionOriginalMessage = reportAction?.originalMessage as ExpenseOriginalMessage | undefined; - const policyID = ReportUtils.getReportPolicyID(reportID) ?? ''; + const policyID = getReportPolicyID(reportID) ?? ''; const removalFragments: string[] = []; const setFragments: string[] = []; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c991d8771a15..003cd45b5439 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -56,6 +56,7 @@ 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'; @@ -4444,7 +4445,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); } /** diff --git a/src/libs/getReportPolicyID.ts b/src/libs/getReportPolicyID.ts new file mode 100644 index 000000000000..a5ed639ecae2 --- /dev/null +++ b/src/libs/getReportPolicyID.ts @@ -0,0 +1,32 @@ +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; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (value) => (allReports = value), +}); + +/** + * Get the report given a reportID + */ +function getReport(reportID: string | undefined): OnyxEntry | EmptyObject { + if (!allReports) { + return {}; + } + + return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] ?? {}; +} + +/** + * Get the report policyID given a reportID + */ +function getReportPolicyID(reportID?: string): string | undefined { + return getReport(reportID)?.policyID; +} + +export default getReportPolicyID; From 475f300b0cd6fdb6dcca8dedfc750dbc8afd0e86 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 14 Mar 2024 10:48:08 +0700 Subject: [PATCH 5/6] fix pretier --- src/libs/ModifiedExpenseMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 81170a830060..3b3e24867a4f 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -5,11 +5,11 @@ 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 type {ExpenseOriginalMessage} from './ReportUtils'; import * as TransactionUtils from './TransactionUtils'; -import getReportPolicyID from './getReportPolicyID'; let allPolicyTags: OnyxCollection = {}; Onyx.connect({ From 7089e8295d7fdc2c294136b469a18e423da26135 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 20 Mar 2024 19:16:29 +0700 Subject: [PATCH 6/6] fix add comment to a new file --- src/libs/getReportPolicyID.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/getReportPolicyID.ts b/src/libs/getReportPolicyID.ts index a5ed639ecae2..12124f24fbe7 100644 --- a/src/libs/getReportPolicyID.ts +++ b/src/libs/getReportPolicyID.ts @@ -23,7 +23,8 @@ function getReport(reportID: string | undefined): OnyxEntry | EmptyObjec } /** - * Get the report policyID given a 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;