Skip to content

Commit 1cc32ab

Browse files
Refactor: simplified getReportActionMessageFragments to remove dependency from ONYXKEYS.COLLECTION.REPORT Onyx data
1 parent 1dd01da commit 1cc32ab

3 files changed

Lines changed: 2 additions & 65 deletions

File tree

src/libs/ReportActionsUtils.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,13 +2407,6 @@ function getUpdateRoomDescriptionFragment(translate: LocalizedTranslate, reportA
24072407
}
24082408

24092409
function getReportActionMessageFragments(translate: LocalizedTranslate, action: ReportAction): Message[] {
2410-
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REIMBURSED)) {
2411-
const reportID = action.reportID;
2412-
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
2413-
const message = getReimbursedMessage(translate, action, report, deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID);
2414-
return [{text: message, html: `<muted-text>${message}</muted-text>`, type: 'COMMENT'}];
2415-
}
2416-
24172410
if (isOldDotReportAction(action)) {
24182411
const oldDotMessage = getMessageOfOldDotReportAction(translate, action);
24192412
const html = isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SELECTED_FOR_RANDOM_AUDIT) ? Parser.replace(oldDotMessage) : oldDotMessage;

src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ import {
7373
getPolicyChangeLogMaxExpenseAmountMessage,
7474
getPolicyChangeLogMaxExpenseAmountNoReceiptMessage,
7575
getPolicyChangeLogUpdateEmployee,
76+
getReimbursedMessage,
7677
getReimburserUpdateMessage,
7778
getRemovedCardFeedMessage,
7879
getRemovedConnectionMessage,
7980
getRenamedAction,
8081
getRenamedCardFeedMessage,
8182
getReportAction,
82-
getReportActionMessageFragments,
8383
getReportActionMessageText,
8484
getRoomAvatarUpdatedMessage,
8585
getSetAutoJoinMessage,
@@ -991,7 +991,7 @@ const ContextMenuActions: ContextMenuAction[] = [
991991
} else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED)) {
992992
Clipboard.setString(getMarkedReimbursedMessage(translate, reportAction));
993993
} else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.REIMBURSED)) {
994-
Clipboard.setString(getReportActionMessageFragments(translate, reportAction).at(0)?.text ?? '');
994+
Clipboard.setString(getReimbursedMessage(translate, reportAction, report, currentUserPersonalDetails.accountID));
995995
} else if (isReimbursementQueuedAction(reportAction)) {
996996
Clipboard.setString(
997997
getReimbursementQueuedActionMessage({reportAction, translate, formatPhoneNumber: formatPhoneNumberPhoneUtils, report, shouldUseShortDisplayName: false}),

tests/unit/ReportActionsUtilsTest.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,62 +1284,6 @@ describe('ReportActionsUtils', () => {
12841284
});
12851285

12861286
describe('getReportActionMessageFragments', () => {
1287-
it('should return the correct fragment for the REIMBURSED action', () => {
1288-
const action = {
1289-
actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED,
1290-
reportActionID: '1',
1291-
created: '1',
1292-
message: [
1293-
{
1294-
type: 'TEXT',
1295-
style: 'strong',
1296-
text: 'Concierge',
1297-
},
1298-
{
1299-
type: 'TEXT',
1300-
style: 'normal',
1301-
text: ' reimbursed this report',
1302-
},
1303-
{
1304-
type: 'TEXT',
1305-
style: 'normal',
1306-
text: ' on behalf of you',
1307-
},
1308-
{
1309-
type: 'TEXT',
1310-
style: 'normal',
1311-
text: ' from the bank account ending in 1111',
1312-
},
1313-
{
1314-
type: 'TEXT',
1315-
style: 'normal',
1316-
text: '. Money is on its way to your bank account ending in 0000. Reimbursement estimated to complete on Dec 16.',
1317-
},
1318-
],
1319-
};
1320-
const expectedMessage = ReportActionsUtils.getReimbursedMessage(translateLocal, action, undefined, 0);
1321-
const expectedFragments = ReportActionsUtils.getReportActionMessageFragments(translateLocal, action);
1322-
expect(expectedFragments).toEqual([{text: expectedMessage, html: `<muted-text>${expectedMessage}</muted-text>`, type: 'COMMENT'}]);
1323-
});
1324-
1325-
it('should translate the REIMBURSED action using originalMessage.method when paymentMethod is absent (Pusher path)', () => {
1326-
// Given a REIMBURSED action that arrived via Pusher with only `method` set (as Auth stores it)
1327-
const action: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSED> = {
1328-
actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED,
1329-
reportActionID: '2',
1330-
created: '2024-01-01',
1331-
originalMessage: {
1332-
method: 'Check',
1333-
},
1334-
};
1335-
// When we get the message fragments
1336-
const fragments = ReportActionsUtils.getReportActionMessageFragments(translateLocal, action);
1337-
// Then the translated message is used (not raw backend text)
1338-
const expectedMessage = ReportActionsUtils.getReimbursedMessage(translateLocal, action, undefined, 0);
1339-
expect(fragments).toEqual([{text: expectedMessage, html: `<muted-text>${expectedMessage}</muted-text>`, type: 'COMMENT'}]);
1340-
expect(expectedMessage).toContain('check');
1341-
});
1342-
13431287
it('should return the correct fragment for the DYNAMIC_EXTERNAL_WORKFLOW_ROUTED action', () => {
13441288
// Given a DYNAMIC_EXTERNAL_WORKFLOW_ROUTED action
13451289
const action: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.DYNAMIC_EXTERNAL_WORKFLOW_ROUTED> = {

0 commit comments

Comments
 (0)