Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a missing note about plugin webapp utility function (PostUtils.formatText) #1364

Merged
merged 2 commits into from
May 16, 2024

Conversation

kaakaa
Copy link
Contributor

@kaakaa kaakaa commented May 9, 2024

Summary

When replacing ~channel mention with a link by PostUtils.formatText, just specifying channelNamesMap as args didn't get a correct result, and it was required to specify team arg at the same time. The document doesn't mention this, so it should be added.

Ticket Link

N/A

Additional Context

...
    // msg1: no options
    const msg1 = messageHtmlToComponent(
        formatText(`link: ~off-topic`, {}
    ), true, {});
    // msg2: just `channelNamesMap`
    const msg2 = messageHtmlToComponent(
        formatText(`link: ~off-topic`, {channelNamesMap}
    ), true, {});
    // msg3: `channelNamesMap` and `team`
    const msg3 = messageHtmlToComponent(
        formatText(`link: ~off-topic`, {channelNamesMap, team}
    ), true, {});
...

Screenshot from 2024-05-09 21-41-11

Entire code
import React from 'react';

import {getChannelsNameMapInCurrentTeam} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import { useSelector } from 'react-redux';

const {formatText, messageHtmlToComponent} = window.PostUtils;

const Sub = () => {
    const channelNamesMap = useSelector((state) => getChannelsNameMapInCurrentTeam(state));
    const team = useSelector((state) => getCurrentTeam(state));

    // msg1: no options
    const msg1 = messageHtmlToComponent(
        formatText(`link: ~off-topic`, {}
    ), true, {});
    // msg2: just `channelNamesMap`
    const msg2 = messageHtmlToComponent(
        formatText(`link: ~off-topic`, {channelNamesMap}
    ), true, {});
    // msg3: `channelNamesMap` and `team`
    const msg3 = messageHtmlToComponent(
        formatText(`link: ~off-topic`, {channelNamesMap, team}
    ), true, {});

    return (
        <div>
            <h3>msg1</h3>
            <div>{msg1}</div>
            <h3>msg2</h3>
            <div>{msg2}</div>
            <h3>msg3</h3>
            <div>{msg3}</div>
        </div>
    );
}

export default Sub;

Without team, replacing token isn't seemed to be fired.
https://github.com/mattermost/mattermost/blob/f111db5fe85e8320fbc4b88b75cd423e181a7600/webapp/channels/src/utils/text_formatting.tsx#L546

@mattermost-build
Copy link
Contributor

Hello @kaakaa,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

@cwarnermm cwarnermm added the preview-environment Allow the preview environment to be generated for Pull Requests coming from fork repositories label May 14, 2024
@cwarnermm cwarnermm self-requested a review May 15, 2024 17:12
@cwarnermm cwarnermm added the 2: Editor Review Requires review by an editor label May 15, 2024
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.

Thanks for the PR! That's a great catch. From what I can tell, team has been required for channel short links for a while now, so it's good to have that fixed

Copy link
Member

@cwarnermm cwarnermm left a comment

Choose a reason for hiding this comment

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

Thank you for this great developer documentation PR, @kaakaa!

@cwarnermm cwarnermm added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Editor Review Requires review by an editor preview-environment Allow the preview environment to be generated for Pull Requests coming from fork repositories labels May 16, 2024
Copy link

Newest code from cwarnermm has been published to preview environment for Git SHA 56458ab

@cwarnermm cwarnermm merged commit dd637ab into mattermost:master May 16, 2024
5 checks passed
Copy link

Newest code from cwarnermm has been published to preview environment for Git SHA b8dcfd6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request Contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants