Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/libs/ReportActionFollowupUtils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import render from 'dom-serializer';
import {DomUtils, parseDocument} from 'htmlparser2';
import {getReportActionMessage, isActionOfType} from '@libs/ReportActionsUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -53,7 +54,7 @@ function parseFollowupsFromHtml(html: string): Followup[] | null {
const followupTextElement = DomUtils.getElementsByTagName('followup-text', followupEl, true).at(0);
const followupResponseElement = DomUtils.getElementsByTagName('followup-response', followupEl, true).at(0);
const text = followupTextElement ? DomUtils.textContent(followupTextElement) : '';
const response = followupResponseElement ? DomUtils.textContent(followupResponseElement) : undefined;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: @marcochavezf the only thing I want to highlight is this will ensure that it'll return HTML for all the strings. I know it's already mentioned in the PR body

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, it's intentional, so now formatted responses from follow-ups (bold, lists, links from the help center) are preserved when displayed

const response = followupResponseElement ? render(followupResponseElement.children) : undefined;
return {text, response};
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Navigation from '@libs/Navigation/Navigation';
import Parser from '@libs/Parser';
import {getCleanedTagName, isPolicyAdmin} from '@libs/PolicyUtils';
import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager';
import stripFollowupListFromHtml from '@libs/ReportActionFollowupUtils/stripFollowupListFromHtml';
import {
getActionableCardFraudAlertMessage,
getActionableMentionWhisperMessage,
Expand Down Expand Up @@ -1073,8 +1074,9 @@ const ContextMenuActions: ContextMenuAction[] = [
);
setClipboardMessage(displayMessage);
} else if (content) {
const contentWithoutFollowups = stripFollowupListFromHtml(content) ?? content;
setClipboardMessage(
content.replaceAll(/(<mention-user>)(.*?)(<\/mention-user>)/gi, (match, openTag: string, innerContent: string, closeTag: string): string => {
contentWithoutFollowups.replaceAll(/(<mention-user>)(.*?)(<\/mention-user>)/gi, (match, openTag: string, innerContent: string, closeTag: string): string => {
const modifiedContent = Str.removeSMSDomain(innerContent) || '';
return openTag + modifiedContent + closeTag || '';
}),
Expand Down
21 changes: 16 additions & 5 deletions tests/unit/ReportActionsFollowupUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,25 @@ describe('ReportActionsFollowupUtils', () => {
expect(parseFollowupsFromHtml(html)).toEqual([]);
});

it('should parse followup with pre-generated response', () => {
it('should parse followup with pre-generated response preserving HTML', () => {
const html = `<followup-list>
<followup>
<followup-text>How do I set up QuickBooks?</followup-text>
<followup-response>To set up QuickBooks, go to Settings > Integrations...</followup-response>
<followup-response>To set up QuickBooks, go to <strong>Settings</strong> &gt; Integrations.</followup-response>
</followup>
</followup-list>`;
expect(parseFollowupsFromHtml(html)).toEqual([{text: 'How do I set up QuickBooks?', response: 'To set up QuickBooks, go to Settings > Integrations...'}]);
expect(parseFollowupsFromHtml(html)).toEqual([{text: 'How do I set up QuickBooks?', response: 'To set up QuickBooks, go to <strong>Settings</strong> > Integrations.'}]);
});

it('should preserve bullet lists in pre-generated responses', () => {
const html = `<followup-list>
<followup>
<followup-text>What are the steps?</followup-text>
<followup-response><ul><li>Step one</li><li>Step two</li></ul></followup-response>
</followup>
</followup-list>`;
const result = parseFollowupsFromHtml(html);
expect(result).toEqual([{text: 'What are the steps?', response: '<ul><li>Step one</li><li>Step two</li></ul>'}]);
});

it('should parse multiple followups with mixed response availability', () => {
Expand All @@ -79,12 +90,12 @@ describe('ReportActionsFollowupUtils', () => {
</followup>
<followup>
<followup-text>Question with response</followup-text>
<followup-response>Here is the cached response</followup-response>
<followup-response>Here is the <strong>cached</strong> response</followup-response>
</followup>
</followup-list>`;
expect(parseFollowupsFromHtml(html)).toEqual([
{text: 'Question without response', response: undefined},
{text: 'Question with response', response: 'Here is the cached response'},
{text: 'Question with response', response: 'Here is the <strong>cached</strong> response'},
]);
});

Expand Down
Loading