Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

[MM-50467] Change usage of anchor tag in favour of new ExternalLink #12277

Merged
merged 22 commits into from
Mar 9, 2023

Conversation

nickmisasi
Copy link
Contributor

@nickmisasi nickmisasi commented Feb 27, 2023

Summary

We want to be able to enrich link-outs from mattermost to *.mattermost.com with contextual information. This will help us to identify PQL's. This PR implements changes required to satisfy the the new linter rule enforcing usage of this new component mattermost/eslint-plugin-mattermost#6

Ticket Link

https://mattermost.atlassian.net/browse/MM-50467

Related Pull Requests

  • Has server changes (please link here)
  • Has mobile changes (please link here)

Screenshots

Release Note

None

@nickmisasi nickmisasi added the Work in Progress Not yet ready for review label Feb 27, 2023

/* eslint-disable mattermost/use-external-link */

import React from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The component itself

@nickmisasi nickmisasi changed the title [MM-50467] Change usage of anchor tag in favour of new ExternalLink [MM-50467] WIP: Change usage of anchor tag in favour of new ExternalLink Feb 27, 2023
@github-actions
Copy link

github-actions bot commented Feb 27, 2023

Test Results

       1 files     816 suites   14m 54s ⏱️
6 938 tests 6 937 ✔️ 1 💤 0
7 114 runs  7 113 ✔️ 1 💤 0

Results for commit 128db87.

♻️ This comment has been updated with latest results.

package.json Outdated
@@ -39,6 +39,7 @@
"emoji-datasource": "6.1.1",
"emoji-datasource-apple": "6.0.1",
"emoji-regex": "10.2.1",
"eslint-plugin-mattermost": "github:mattermost/eslint-plugin-mattermost#9372e95228f2517c45f83418ea9c4d5b1e390cde",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will need to replace this with the tip of master

@nickmisasi nickmisasi marked this pull request as ready for review March 2, 2023 16:57
@nickmisasi nickmisasi requested a review from a team as a code owner March 2, 2023 16:57
@nickmisasi nickmisasi requested review from hmhealey and removed request for a team March 2, 2023 16:57
@nickmisasi nickmisasi changed the title [MM-50467] WIP: Change usage of anchor tag in favour of new ExternalLink [MM-50467] Change usage of anchor tag in favour of new ExternalLink Mar 2, 2023
@nickmisasi nickmisasi added 1: PM Review Requires review by a product manager 2: Dev Review Requires review by a core commiter and removed Work in Progress Not yet ready for review labels Mar 2, 2023
Copy link
Contributor

@neallred neallred left a comment

Choose a reason for hiding this comment

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

LGTM overall! The only blocking things to me are:

  • There was an extra/double paste of a link
  • I think we need support for if the href prop already contains a query parameter.

Not sure if we want to support utils/markdown/link_only_renderer.tsx or utils/markdown/renderer.tsx ever (might be hard to do in any case), but wanted to raise that its possible we could get markdown linking off to mattermost.com and it wouldn't have the ExternalLink enhancement. I think we're ok with that since dynamic content isn't really part of a campaign per se, and I don't think we'd know what "location" to meaningfully attribute it to.

Found a few places that maybe should be external links:

components/seats_calculator/consequences.tsx , seeHowBillingWorks link

This one is an external link, but formulated in javascript instead of as plain links because of the cloud condition. Not sure how we want to handle it.

components/youtube_video/youtube_video.tsx

when noopener is used, nonempty target names other than _top, _self, and _parent are all treated like _blank in terms of deciding whether to open a new window/tab.

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/noopener

components/admin_console/admin_definition.jsx

                id: 'CustomIntegrationSettings',
                name: t('admin.integrations.integrationManagement.title'),
                name_default: 'Integration Management',
                settings: [
                    {
                        type: Constants.SettingsTypes.TYPE_BOOL,
                        key: 'ServiceSettings.EnableIncomingWebhooks',
                        label: t('admin.service.webhooksTitle'),
                        label_default: 'Enable Incoming Webhooks: ',
                        help_text: t('admin.service.webhooksDescription'),
                        help_text_default: 'When true, incoming webhooks will be allowed. To help combat phishing attacks, all posts from webhooks will be labelled by a BOT tag. See <link>documentation</link> to learn more.',
                        help_text_values: {
                            link: (msg) => (
                                <a
                                    href='https://developers.mattermost.com/integrate/admin-guide/admin-webhooks-incoming/'

components/admin_console/license_settings/trial_banner/trial_banner.tsx

export const EmbargoedEntityTrialError = () => {
    return (
        <FormattedMessage
            id='admin.license.trial-request.embargoed'
            defaultMessage='We were unable to process the request due to limitations for embargoed countries. <link>Learn more in our documentation</link>, or reach out to [email protected] for questions around export limitations.'
            values={{
                link: (text: string) => (
                    <a href={LicenseLinks.EMBARGOED_COUNTRIES}>
                        {text}
                    </a>
                ),
            }}
        />
    );
};

components/external_link/index.tsx Outdated Show resolved Hide resolved
components/external_link/index.tsx Outdated Show resolved Hide resolved
components/external_link/index.tsx Outdated Show resolved Hide resolved
components/external_link/index.tsx Show resolved Hide resolved
components/create_team/components/team_url/team_url.tsx Outdated Show resolved Hide resolved
components/warn_metric_ack_modal/warn_metric_ack_modal.tsx Outdated Show resolved Hide resolved
@hmhealey hmhealey added the Do Not Merge/Awaiting PR Awaiting another pull request before merging (e.g. server changes) label Mar 3, 2023
@nickmisasi nickmisasi removed the Do Not Merge/Awaiting PR Awaiting another pull request before merging (e.g. server changes) label Mar 6, 2023
}

type Props = React.AnchorHTMLAttributes<HTMLAnchorElement> & {
href?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be the minimum required?

let href = props.href;
let queryParams = {};
if (href?.includes('mattermost.com')) {
// encode this stuff so it's not so transparent to the user?
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this comment if we are not taking that direction

utm_source: 'mattermost',
utm_medium: license.Cloud === 'true' ? 'in-product-cloud' : 'in-product',
utm_content: props.location || '',
uid: userId,
Copy link
Member

Choose a reason for hiding this comment

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

Is user id necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kevin mentioned it in lieu of PII. I think it would be useful for the data team since we'd be able to map this value to the user_actual_id from rudder events.

Copy link
Member

@marianunez marianunez left a comment

Choose a reason for hiding this comment

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

Thanks @nickmisasi! Didn't do a review on all the replacements but the components LGTM with some non-blocking comments

Comment on lines 49 to 50
it('should attach parameters if telemetry is enabled', () => {
const state = {
Copy link
Member

Choose a reason for hiding this comment

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

Is this test still applicable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the name of the test, it's applicable now!

Copy link
Member

@hmhealey hmhealey left a comment

Choose a reason for hiding this comment

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

Looks good to me. There's just one thing that I think needs addressing (the dependency vs dev dependency one), but hopefully it's quick

className='GenericModal__button actionButton'
href={presentNoticeInfo.actionParam}
location='product_notices_modal'
href={presentNoticeInfo.actionParam || ''}
Copy link
Member

Choose a reason for hiding this comment

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

This is the first place I've noticed this during my review, but if we end up doing this a lot, we could always consider making this prop optional

package.json Outdated
@@ -39,6 +39,7 @@
"emoji-datasource": "6.1.1",
"emoji-datasource-apple": "6.0.1",
"emoji-regex": "10.2.1",
"eslint-plugin-mattermost": "github:mattermost/eslint-plugin-mattermost#5b0c972eacf19286e4c66221b39113bf8728a99e",
Copy link
Member

Choose a reason for hiding this comment

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

Could you move this back to being a dev dependency? Strictly speaking, it doesn't matter for the web app (it would only really have an effect if we uploaded mattermost-webapp as an NPM package), but I think Security Team had some process around new non-dev dependencies

Copy link
Contributor Author

@nickmisasi nickmisasi Mar 8, 2023

Choose a reason for hiding this comment

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

I'm not sure how this happened tbh. I think maybe the npm link from testing? Fixed

@@ -280,13 +282,12 @@ export default class DatabaseSettings extends AdminSettings {
defaultMessage='Minimum number of characters in a hashtag. This must be greater than or equal to 2. MySQL databases must be configured to support searching strings shorter than three characters, <link>see documentation</link>.'
values={{
link: (msg) => (
<a
<ExternalLink
location='database_settings'
Copy link
Member

Choose a reason for hiding this comment

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

Nothing to change here, but seeing these location things repeated does make me wonder if we'd benefit from wrapping the entire contents of these screens/modals/components in a Context that provides this. That'd be overkill to just save us from having to pass the same location repeatedly for multiple ExternalLinks, but I could see that sort of pattern being useful for other things in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like a "breadcrumb" in a context would be pretty cool for sure. I know there are some patterns around Cloud telemetry that sort of mimics that by appending 'location1 > location2' + 'location3' through props, which is a bit messy imo

@nickmisasi nickmisasi requested a review from hmhealey March 8, 2023 20:55
@hmhealey hmhealey removed the 2: Dev Review Requires review by a core commiter label Mar 9, 2023
@nickmisasi nickmisasi added Setup Cloud Test Server Setup a test server using Mattermost Cloud and removed Setup Cloud Test Server Setup a test server using Mattermost Cloud labels Mar 9, 2023
@mm-cloud-bot mm-cloud-bot removed the Setup Cloud Test Server Setup a test server using Mattermost Cloud label Mar 9, 2023
@nickmisasi nickmisasi added Setup Cloud Test Server Setup a test server using Mattermost Cloud 4: Reviews Complete All reviewers have approved the pull request and removed 1: PM Review Requires review by a product manager labels Mar 9, 2023
@nickmisasi nickmisasi merged commit 780bbe8 into master Mar 9, 2023
@nickmisasi nickmisasi deleted the MM-50467 branch March 9, 2023 16:42
@mattermost-build mattermost-build removed the Setup Cloud Test Server Setup a test server using Mattermost Cloud label Mar 9, 2023
@mm-cloud-bot
Copy link

Test server destroyed

@amyblais amyblais added Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation labels Mar 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4: Reviews Complete All reviewers have approved the pull request Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation release-note-none
Projects
None yet
7 participants