Skip to content
Draft
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
13 changes: 11 additions & 2 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,22 @@

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;

Onyx.connect({

Check warning on line 145 in src/libs/ReportNameUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value;
},
});

/**
* Strips accounting-style parentheses from currency amounts in report names.
* The backend formats negative amounts with parentheses (e.g., "($25.00)") instead of
* a minus sign. This function converts them to the standard format (e.g., "$25.00").
*/
function stripAccountingBrackets(reportName: string): string {
return reportName.replaceAll(/\(([^)]*\d[^)]*)\)/g, '$1');
}

function generateArchivedReportName(reportName: string): string {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return `${reportName} (${translateLocal('common.archived')}) `;
Expand Down Expand Up @@ -335,7 +344,7 @@
}

if (report?.reportName && isExpenseReport(report)) {
return report.reportName;
return stripAccountingBrackets(report.reportName);
}

const moneyRequestTotal = getMoneyRequestSpendBreakdown(report).totalDisplaySpend;
Expand Down Expand Up @@ -780,7 +789,7 @@
}

if (report?.reportName && report.type === CONST.REPORT.TYPE.EXPENSE) {
return report?.reportName;
return stripAccountingBrackets(report.reportName);
}

if (isTaskReport(report)) {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1018 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1023,7 +1023,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1026 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1041,7 +1041,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1044 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -1053,7 +1053,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1056 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1062,7 +1062,7 @@
let allPolicies: OnyxCollection<Policy>;
let hasPolicies: boolean;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1065 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1073,7 +1073,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1076 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1081,7 +1081,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1084 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1117,14 +1117,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1120 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1127 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -6727,7 +6727,7 @@
const storedNonReimbursableTotal = nonReimbursableTotal * -1;
const report = chatReportID ? getReportOrDraftReport(chatReportID) : undefined;
const policyName = getPolicyName({report});
const formattedTotal = convertToDisplayString(storedTotal, currency);
const formattedTotal = convertToDisplayString(Math.abs(storedTotal), currency);
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policyReal = getPolicy(policyID);
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/ReportNameUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,25 @@ describe('ReportNameUtils', () => {
expect(reportName).toBe(CONST.REPORT.DEFAULT_EXPENSE_REPORT_NAME);
});

it('should strip accounting-style parentheses from expense report reportName', () => {
// Given an expense report with a reportName containing accounting-style parenthesized amount
const expenseReport: Report = {
...createExpenseReport(202),
reportID: '202',
reportName: 'Workspace owes ($25.00)',
policyID: '202',
type: CONST.REPORT.TYPE.EXPENSE,
total: -2500,
currency: 'USD',
};

// When we get the money request report name
const reportName = getMoneyRequestReportName({report: expenseReport});

// Then it should strip the accounting-style parentheses
expect(reportName).toBe('Workspace owes $25.00');
});

it('should not return empty string for expense report with empty reportName when policy has a normal fieldList', () => {
// Given an expense report with empty reportName
const expenseReport: Report = {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10098,7 +10098,7 @@ describe('ReportUtils', () => {
const total = 100;
const currency = CONST.CURRENCY.USD;
const expenseReport = buildOptimisticExpenseReport({chatReportID, policyID: undefined, payeeAccountID: 1, total, currency, betas: [CONST.BETAS.ALL]});
expect(expenseReport.reportName).toBe(`${fakePolicy.name} owes ${convertToDisplayString(-total, currency)}`);
expect(expenseReport.reportName).toBe(`${fakePolicy.name} owes ${convertToDisplayString(total, currency)}`);
});

it('should set reportName to "New Report" when policy field list is empty', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/libs/getClipboardTextTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Parser from '@libs/Parser';
import getClipboardText from '@libs/Clipboard/getClipboardText';
import Parser from '@libs/Parser';

jest.mock('@libs/Parser', () => ({
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
Loading