From 3e9e9c3490ccd771a0f23d8ac03833e490b1985d Mon Sep 17 00:00:00 2001 From: lorretheboy Date: Thu, 18 Jun 2026 14:23:08 -0500 Subject: [PATCH 1/2] feat: refactor editReportComment --- src/libs/actions/Report/index.ts | 13 +++-- .../ReportActionCompose/useEditMessage.ts | 2 + tests/actions/ReportTest.ts | 47 ++++++++++--------- tests/ui/ReportActionItemMessageEditTest.tsx | 2 +- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index 4f90eb6dcbfa..cef0f448832b 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -3189,13 +3189,19 @@ function removeLinksFromHtml(html: string, links: string[]): string { * @param originalCommentMarkdown original markdown of the comment before editing. * @param videoAttributeCache cache of video attributes ([videoSource]: videoAttributes) */ -function handleUserDeletedLinksInHtml(newCommentText: string, originalCommentMarkdown: string, currentUserLogin: string, videoAttributeCache?: Record): string { +function handleUserDeletedLinksInHtml( + newCommentText: string, + originalCommentMarkdown: string, + currentUserLogin: string, + personalDetails: OnyxEntry, + videoAttributeCache?: Record, +): string { if (newCommentText.length > CONST.MAX_MARKUP_LENGTH) { return newCommentText; } const userEmailDomain = isEmailPublicDomain(currentUserLogin) ? '' : Str.extractEmailDomain(currentUserLogin); - const allPersonalDetailLogins = Object.values(allPersonalDetails ?? {}).map((personalDetail) => personalDetail?.login ?? ''); + const allPersonalDetailLogins = Object.values(personalDetails ?? {}).map((personalDetail) => personalDetail?.login ?? ''); const htmlForNewComment = getParsedMessageWithShortMentions({ text: newCommentText, @@ -3219,6 +3225,7 @@ function editReportComment( isOriginalReportArchived: boolean | undefined, isOriginalParentReportArchived: boolean | undefined, currentUserLogin: string, + personalDetails: OnyxEntry, videoAttributeCache?: Record, visibleReportActionsDataParam?: VisibleReportActionsDerivedValue, ) { @@ -3239,7 +3246,7 @@ function editReportComment( if (originalCommentMarkdown === textForNewComment) { return; } - const htmlForNewComment = handleUserDeletedLinksInHtml(textForNewComment, originalCommentMarkdown, currentUserLogin, videoAttributeCache); + const htmlForNewComment = handleUserDeletedLinksInHtml(textForNewComment, originalCommentMarkdown, currentUserLogin, personalDetails, videoAttributeCache); const reportComment = Parser.htmlToText(htmlForNewComment); diff --git a/src/pages/inbox/report/ReportActionCompose/useEditMessage.ts b/src/pages/inbox/report/ReportActionCompose/useEditMessage.ts index f7aaf29713a8..1213766b8884 100644 --- a/src/pages/inbox/report/ReportActionCompose/useEditMessage.ts +++ b/src/pages/inbox/report/ReportActionCompose/useEditMessage.ts @@ -40,6 +40,7 @@ function useEditMessage({reportID, originalReportID, reportAction, shouldScrollT const actionOwnerReportID = originalReportID ?? reportID; const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${actionOwnerReportID}`); const [visibleReportActionsData] = useOnyx(ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS); + const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const originalParentReportID = getOriginalReportID(actionOwnerReportID, reportAction, reportActions); const [originalReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${actionOwnerReportID}`); const isOriginalReportArchived = useReportIsArchived(actionOwnerReportID); @@ -96,6 +97,7 @@ function useEditMessage({reportID, originalReportID, reportAction, shouldScrollT isOriginalReportArchived, isOriginalParentReportArchived, email ?? '', + personalDetails, Object.fromEntries(draftMessageVideoAttributeCache), visibleReportActionsData, ); diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index d13d8ddf49cd..2276ba3f6f87 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -802,7 +802,7 @@ describe('actions/Report', () => { // We should generate link let originalCommentMarkdown = 'Original Comment'; let afterEditCommentText = 'Original Comment www.google.com'; - let newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + let newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, {}); let expectedOutput = 'Original Comment www.google.com'; expect(newCommentHTML).toBe(expectedOutput); @@ -810,7 +810,7 @@ describe('actions/Report', () => { // We should not generate link originalCommentMarkdown = 'Comment [www.google.com](https://www.google.com)'; afterEditCommentText = 'Comment www.google.com'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, {}); expectedOutput = 'Comment www.google.com'; expect(newCommentHTML).toBe(expectedOutput); @@ -818,7 +818,7 @@ describe('actions/Report', () => { // We should not generate link originalCommentMarkdown = 'Comment [www.google.com](https://www.google.com)'; afterEditCommentText = 'Comment [www.google.com]'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, {}); expectedOutput = 'Comment [www.google.com]'; expect(newCommentHTML).toBe(expectedOutput); @@ -826,7 +826,7 @@ describe('actions/Report', () => { // We should generate both links originalCommentMarkdown = 'Comment'; afterEditCommentText = 'Comment www.google.com www.facebook.com'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, {}); expectedOutput = 'Comment www.google.com ' + 'www.facebook.com'; @@ -836,7 +836,7 @@ describe('actions/Report', () => { // Should not generate link again for the deleted one originalCommentMarkdown = 'Comment [www.google.com](https://www.google.com) [www.facebook.com](https://www.facebook.com)'; afterEditCommentText = 'Comment www.google.com [www.facebook.com](https://www.facebook.com)'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, {}); expectedOutput = 'Comment www.google.com www.facebook.com'; expect(newCommentHTML).toBe(expectedOutput); @@ -844,7 +844,7 @@ describe('actions/Report', () => { // We should generate link originalCommentMarkdown = 'Comment'; afterEditCommentText = 'https://www.facebook.com/hashtag/__main/?__eep__=6'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, {}); expectedOutput = 'https://www.facebook.com/hashtag/__main/?__eep__=6'; expect(newCommentHTML).toBe(expectedOutput); @@ -852,7 +852,7 @@ describe('actions/Report', () => { // We should not generate link originalCommentMarkdown = '[https://www.facebook.com/hashtag/__main/?__eep__=6](https://www.facebook.com/hashtag/__main/?__eep__=6)'; afterEditCommentText = 'https://www.facebook.com/hashtag/__main/?__eep__=6'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, {}); expectedOutput = 'https://www.facebook.com/hashtag/__main/?__eep__=6'; expect(newCommentHTML).toBe(expectedOutput); @@ -860,7 +860,7 @@ describe('actions/Report', () => { // We should generate link originalCommentMarkdown = 'Comment'; afterEditCommentText = 'http://example.com/foo/*/bar/*/test.txt'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, {}); expectedOutput = 'http://example.com/foo/*/bar/*/test.txt'; expect(newCommentHTML).toBe(expectedOutput); @@ -868,7 +868,7 @@ describe('actions/Report', () => { // We should not generate link originalCommentMarkdown = '[http://example.com/foo/*/bar/*/test.txt](http://example.com/foo/*/bar/*/test.txt)'; afterEditCommentText = 'http://example.com/foo/*/bar/*/test.txt'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, {}); expectedOutput = 'http://example.com/foo/*/bar/*/test.txt'; expect(newCommentHTML).toBe(expectedOutput); @@ -884,7 +884,9 @@ describe('actions/Report', () => { }); originalCommentMarkdown = 'Comment'; afterEditCommentText = 'Comment @user'; - newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN); + newCommentHTML = Report.handleUserDeletedLinksInHtml(afterEditCommentText, originalCommentMarkdown, TEST_USER_LOGIN, { + [privateDomainAccount.accountID]: privateDomainAccount, + }); expectedOutput = 'Comment @user@expensify.com'; expect(newCommentHTML).toBe(expectedOutput); }); @@ -1362,7 +1364,7 @@ describe('actions/Report', () => { }; const {result: ancestors, rerender} = renderHook(() => useAncestors(originalReport)); - Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, ''); + Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, '', {}); await waitForBatchedUpdates(); @@ -1444,7 +1446,7 @@ describe('actions/Report', () => { const {result: ancestors, rerender} = renderHook(() => useAncestors(originalReport)); const currentUserEmail = 'test@test.com'; - Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, currentUserEmail); + Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, currentUserEmail, {}); await waitForBatchedUpdates(); const persistedRequests = await getOnyxValue(ONYXKEYS.PERSISTED_REQUESTS); @@ -1504,7 +1506,7 @@ describe('actions/Report', () => { }; const {result: ancestors, rerender} = renderHook(() => useAncestors(originalReport)); - Report.editReportComment(originalReport, reportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, ''); + Report.editReportComment(originalReport, reportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, '', {}); await waitForBatchedUpdates(); @@ -2323,7 +2325,7 @@ describe('actions/Report', () => { const originalReport = { reportID: REPORT_ID, }; - Report.editReportComment(originalReport, reportAction, [], 'Testing an edited comment', undefined, undefined, ''); + Report.editReportComment(originalReport, reportAction, [], 'Testing an edited comment', undefined, undefined, '', {}); await waitForBatchedUpdates(); @@ -2362,9 +2364,9 @@ describe('actions/Report', () => { const {result: ancestors} = renderHook(() => useAncestors(originalReport)); - Report.editReportComment(originalReport, action, ancestors.current, 'value1', undefined, undefined, ''); - Report.editReportComment(originalReport, action, ancestors.current, 'value2', undefined, undefined, ''); - Report.editReportComment(originalReport, action, ancestors.current, 'value3', undefined, undefined, ''); + Report.editReportComment(originalReport, action, ancestors.current, 'value1', undefined, undefined, '', {}); + Report.editReportComment(originalReport, action, ancestors.current, 'value2', undefined, undefined, '', {}); + Report.editReportComment(originalReport, action, ancestors.current, 'value3', undefined, undefined, '', {}); const requests = PersistedRequests?.getAll(); @@ -2426,7 +2428,10 @@ describe('actions/Report', () => { const {result: ancestors} = renderHook(() => useAncestors(originalReport)); // Edit the comment to add a short mention - Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Initial comment with @bob', undefined, undefined, TEST_USER_LOGIN); + Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Initial comment with @bob', undefined, undefined, TEST_USER_LOGIN, { + [TEST_USER_ACCOUNT_ID]: {accountID: TEST_USER_ACCOUNT_ID, login: TEST_USER_LOGIN}, + [MENTIONED_USER_ACCOUNT_ID]: {accountID: MENTIONED_USER_ACCOUNT_ID, login: MENTIONED_USER_LOGIN, displayName: 'Bob'}, + }); await waitForBatchedUpdates(); @@ -2467,9 +2472,9 @@ describe('actions/Report', () => { const {result: ancestors} = renderHook(() => useAncestors(originalReport)); const currentUserEmail = 'user@test.com'; - Report.editReportComment(originalReport, action, ancestors.current, 'value1', undefined, undefined, currentUserEmail); - Report.editReportComment(originalReport, action, ancestors.current, 'value2', undefined, undefined, currentUserEmail); - Report.editReportComment(originalReport, action, ancestors.current, 'value3', undefined, undefined, currentUserEmail); + Report.editReportComment(originalReport, action, ancestors.current, 'value1', undefined, undefined, currentUserEmail, {}); + Report.editReportComment(originalReport, action, ancestors.current, 'value2', undefined, undefined, currentUserEmail, {}); + Report.editReportComment(originalReport, action, ancestors.current, 'value3', undefined, undefined, currentUserEmail, {}); const requests = PersistedRequests?.getAll(); expect(requests.length).toBe(1); diff --git a/tests/ui/ReportActionItemMessageEditTest.tsx b/tests/ui/ReportActionItemMessageEditTest.tsx index 27e4edb72a7c..87d2512135c2 100644 --- a/tests/ui/ReportActionItemMessageEditTest.tsx +++ b/tests/ui/ReportActionItemMessageEditTest.tsx @@ -193,7 +193,7 @@ describe('ReportActionCompose Integration Tests', () => { expect(mockEditReportComment).toHaveBeenCalledTimes(1); const editReportCommentArgs = mockEditReportComment.mock.calls.at(0); - const videoAttributeCache = editReportCommentArgs?.[7]; + const videoAttributeCache = editReportCommentArgs?.[8]; expect(videoAttributeCache).toEqual(expect.any(Object)); expect(videoAttributeCache?.[videoSource]).toEqual(expect.any(String)); From 3bc26f0d6dbe368c523c1d3cb1439fea1574557a Mon Sep 17 00:00:00 2001 From: lorretheboy Date: Thu, 18 Jun 2026 23:12:49 -0500 Subject: [PATCH 2/2] fix: codex --- src/pages/PrivateNotes/PrivateNotesEditPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx index 1a8d31ca53b1..b781c4249919 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx @@ -94,7 +94,7 @@ function PrivateNotesEditPageInternal({route, report, accountID, privateNoteDraf const originalNote = report?.privateNotes?.[Number(route.params.accountID)]?.note ?? ''; let editedNote = ''; if (privateNote.trim() !== originalNote.trim()) { - editedNote = handleUserDeletedLinksInHtml(privateNote.trim(), Parser.htmlToMarkdown(originalNote).trim(), login ?? '', undefined); + editedNote = handleUserDeletedLinksInHtml(privateNote.trim(), Parser.htmlToMarkdown(originalNote).trim(), login ?? '', personalDetailsList); updatePrivateNotes(report.reportID, Number(route.params.accountID), editedNote); }