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/37448: Incorrect title thread #38267

Merged
Show file tree
Hide file tree
Changes from 5 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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like updating type of reportAction here.
If this causes TS error in other place, fix it to match OnyxEntry<ReportAction> instead of fixing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Do you have any idea to do like you mentioned?
  • Additionally, I just tested the current implementation and there is no TS error in other place

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I am fine with this as already existing pattern in other place

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 @@ -131,7 +131,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 @@ -56,11 +56,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 @@ -2642,6 +2644,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);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have used formatReportLastMessageText here similar to other cases above. More context here: #49518

}
return parentReportActionMessage;
}

Expand Down Expand Up @@ -4440,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);
}

/**
Expand Down
32 changes: 32 additions & 0 deletions src/libs/getReportPolicyID.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that this is to avoid cycle dependency.
Please add comment why this separate file is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comment

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
*/
function getReportPolicyID(reportID?: string): string | undefined {
return getReport(reportID)?.policyID;
}

export default getReportPolicyID;
Loading