Skip to content

Conversation

bhabalan
Copy link
Contributor

@bhabalan bhabalan commented Sep 2, 2024

Problem:
When the space widget is loaded inside of an iframe, the links in the messages when clicked are restricted from being loaded.

Solution:
Add target="_blank" attribute to open these links in a new tab

JIRA: SPARK-556112

@bhabalan bhabalan self-assigned this Sep 2, 2024
// eslint-disable-reason content is generated from elsewhere in the app
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{__html: content}}
dangerouslySetInnerHTML={{__html: content.replace(/<a(?![^>]*target="_blank"|\s*href\s*=\s*["'](?:mailto:|tel:))([^>]*)>/gi, '<a target="_blank"$1>')}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This component is used when there is an @mention present in the message

Copy link
Contributor

Choose a reason for hiding this comment

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

Where does @mentioned links take to today in the widgets? Should we have a test case for that one as well?

Copy link
Contributor Author

@bhabalan bhabalan Sep 3, 2024

Choose a reason for hiding this comment

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

The @mentioned links aren't clickable. They add a new tag called <spark-mention /> and wrap the person data around it. Whenever a mention is present in a message, this component gets used instead of react-component-activity-text. So I had to add the replacement logic here as well.
eg:
<spark-mention data-object-type="person" data-object-id="801bb984-343b-4f6b-97ae-d13c91d4b877">John Doe</spark-mention>

Comment on lines +24 to +28
it('renders clean links properly', () => {
const component = renderer.create(<ActivityText content={cleanLink} />);

expect(component).toMatchSnapshot();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also have tests for cases where there is already _blank or mailto: or tel: in the anchor tag?

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 tests

// eslint-disable-reason content is generated from elsewhere in the app
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{__html: content}}
dangerouslySetInnerHTML={{__html: content.replace(/<a(?![^>]*target="_blank"|\s*href\s*=\s*["'](?:mailto:|tel:))([^>]*)>/gi, '<a target="_blank"$1>')}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does @mentioned links take to today in the widgets? Should we have a test case for that one as well?

Copy link
Contributor

@mkesavan13 mkesavan13 left a comment

Choose a reason for hiding this comment

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

Not sure if tests are there already and are required for the @mentions case. Please add if required. Approving

@bhabalan bhabalan merged commit 3658eb0 into webex:master Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants