mattermost / mattermost-developer-documentation

Mattermost developer documentation.
https://developers.mattermost.com
BSD 3-Clause "New" or "Revised" License
79 stars 383 forks source link

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

Closed kaakaa closed 2 months ago

kaakaa commented 2 months ago

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
```js 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 (

msg1

{msg1}

msg2

{msg2}

msg3

{msg3}
); } 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 commented 2 months ago

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.

github-actions[bot] commented 2 months ago

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

github-actions[bot] commented 2 months ago

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