MM-53926 fix commented on display name (#24322)

* Sync giphy package versions in package-lock.json file

The versions were added automatically after starting the server, so seems like lock file is not synced

* Use main user_profile component in commented_on to fix displayName

* Refactor commented_on component from class to dumb/function component

* Resolved comments and make eslint happy

* Remove display name prop being passed to UserProfile component

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Tasawar Hussain 2023-08-28 18:25:12 +05:00 committed by GitHub
parent 4790a60369
commit 77b19a0d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 86 deletions

View File

@ -14,14 +14,9 @@ exports[`components/post_view/CommentedOn should match snapshot 1`] = `
"name": <a
className="theme user_name"
>
<UserProfile
colorize={false}
<Memo(Connect(UserProfile))
disablePopover={false}
displayUsername={false}
hasMention={true}
hideStatus={false}
isRHS={false}
overwriteName=""
userId=""
/>
</a>,
@ -52,14 +47,9 @@ exports[`components/post_view/CommentedOn should match snapshot 2`] = `
"name": <a
className="theme user_name"
>
<UserProfile
colorize={false}
<Memo(Connect(UserProfile))
disablePopover={false}
displayUsername={false}
hasMention={true}
hideStatus={false}
isRHS={false}
overwriteName=""
userId=""
/>
</a>,
@ -90,14 +80,9 @@ exports[`components/post_view/CommentedOn should match snapshot 3`] = `
"name": <a
className="theme user_name"
>
<UserProfile
colorize={false}
<Memo(Connect(UserProfile))
disablePopover={false}
displayUsername={false}
hasMention={true}
hideStatus={false}
isRHS={false}
overwriteName=""
userId=""
/>
</a>,
@ -130,14 +115,9 @@ exports[`components/post_view/CommentedOn should match snapshots for post with p
"name": <a
className="theme user_name"
>
<UserProfile
colorize={false}
<Memo(Connect(UserProfile))
disablePopover={false}
displayUsername={false}
hasMention={true}
hideStatus={false}
isRHS={false}
overwriteName=""
userId=""
/>
</a>,
@ -168,14 +148,9 @@ exports[`components/post_view/CommentedOn should match snapshots for post with p
"name": <a
className="theme user_name"
>
<UserProfile
colorize={false}
<Memo(Connect(UserProfile))
disablePopover={false}
displayUsername={false}
hasMention={true}
hideStatus={false}
isRHS={false}
overwriteName=""
userId=""
/>
</a>,
@ -206,14 +181,9 @@ exports[`components/post_view/CommentedOn should match snapshots for post with p
"name": <a
className="theme user_name"
>
<UserProfile
colorize={false}
<Memo(Connect(UserProfile))
disablePopover={false}
displayUsername={false}
hasMention={true}
hideStatus={false}
isRHS={false}
overwriteName=""
userId=""
/>
</a>,
@ -244,14 +214,9 @@ exports[`components/post_view/CommentedOn should match snapshots for post with p
"name": <a
className="theme user_name"
>
<UserProfile
colorize={false}
<Memo(Connect(UserProfile))
disablePopover={false}
displayUsername={false}
hasMention={true}
hideStatus={false}
isRHS={false}
overwriteName=""
userId=""
/>
</a>,

View File

@ -1,29 +1,27 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import React, {memo} from 'react';
import {FormattedMessage} from 'react-intl';
import {UserProfile as UserProfileType} from '@mattermost/types/users';
import {Post} from '@mattermost/types/posts';
import * as Utils from 'utils/utils';
import {stripMarkdown} from 'utils/markdown';
import CommentedOnFilesMessage from 'components/post_view/commented_on_files_message';
import UserProfile from '../../user_profile/user_profile';
import UserProfile from 'components/user_profile';
type Props = {
enablePostUsernameOverride?: boolean;
parentPostUser?: UserProfileType;
onCommentClick?: React.EventHandler<React.MouseEvent>;
post: Post;
}
};
export default class CommentedOn extends PureComponent<Props> {
makeCommentedOnMessage = () => {
const {post} = this.props;
function CommentedOn({post, parentPostUser, onCommentClick}: Props) {
const makeCommentedOnMessage = () => {
let message: React.ReactNode = '';
if (post.message) {
message = Utils.replaceHtmlEntities(post.message);
@ -31,7 +29,7 @@ export default class CommentedOn extends PureComponent<Props> {
message = (
<CommentedOnFilesMessage parentPostId={post.id}/>
);
} else if (post.props && post.props.attachments && post.props.attachments.length > 0) {
} else if (post.props?.attachments?.length > 0) {
const attachment = post.props.attachments[0];
const webhookMessage = attachment.pretext || attachment.title || attachment.text || attachment.fallback || '';
message = Utils.replaceHtmlEntities(webhookMessage);
@ -40,42 +38,40 @@ export default class CommentedOn extends PureComponent<Props> {
return message;
};
render() {
const message = this.makeCommentedOnMessage();
const parentPostUser = this.props.parentPostUser;
const parentPostUserId = (parentPostUser && parentPostUser.id) || '';
const message = makeCommentedOnMessage();
const parentPostUserId = parentPostUser?.id || '';
const parentUserProfile = (
<UserProfile
user={parentPostUser}
userId={parentPostUserId}
displayName={parentPostUser?.username}
hasMention={true}
disablePopover={false}
/>
);
const parentUserProfile = (
<UserProfile
user={parentPostUser}
userId={parentPostUserId}
hasMention={true}
disablePopover={false}
/>
);
return (
<div
data-testid='post-link'
className='post__link'
>
<span>
<FormattedMessage
id='post_body.commentedOn'
defaultMessage="Commented on {name}'s message: "
values={{
name: <a className='theme user_name'>{parentUserProfile}</a>,
}}
/>
<a
className='theme'
onClick={this.props.onCommentClick}
>
{typeof message === 'string' ? stripMarkdown(message) : message}
</a>
</span>
</div>
);
}
return (
<div
data-testid='post-link'
className='post__link'
>
<span>
<FormattedMessage
id='post_body.commentedOn'
defaultMessage="Commented on {name}'s message: "
values={{
name: <a className='theme user_name'>{parentUserProfile}</a>,
}}
/>
<a
className='theme'
onClick={onCommentClick}
>
{typeof message === 'string' ? stripMarkdown(message) : message}
</a>
</span>
</div>
);
}
export default memo(CommentedOn);