mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-56295] Convert ./components/post_view/message_attachments/message_attachment_list.tsx from Class Component to Function Component (#25767)
* [MM-56295] Convert `./components/post_view/message_attachments/message_attachment_list.tsx` from Class Component to Function Component * refactor: update default prop * refactor: update snapshot --------- Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
committed by
GitHub
parent
dadc752212
commit
4fb3d7a349
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import React from 'react';
|
||||
import React, {memo} from 'react';
|
||||
|
||||
import type {MessageAttachment as MessageAttachmentType} from '@mattermost/types/message_attachments';
|
||||
import type {PostImage} from '@mattermost/types/posts';
|
||||
@@ -33,32 +33,28 @@ type Props = {
|
||||
imagesMetadata?: Record<string, PostImage>;
|
||||
}
|
||||
|
||||
export default class MessageAttachmentList extends React.PureComponent<Props> {
|
||||
static defaultProps = {
|
||||
imagesMetadata: {},
|
||||
};
|
||||
const EMPTY_METADATA: Record<string, PostImage> = {};
|
||||
|
||||
render() {
|
||||
const content = [] as JSX.Element[];
|
||||
this.props.attachments.forEach((attachment, i) => {
|
||||
content.push(
|
||||
<MessageAttachment
|
||||
attachment={attachment}
|
||||
postId={this.props.postId}
|
||||
key={'att_' + i}
|
||||
options={this.props.options}
|
||||
imagesMetadata={this.props.imagesMetadata}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
const MessageAttachmentList = ({
|
||||
imagesMetadata = EMPTY_METADATA,
|
||||
attachments,
|
||||
postId,
|
||||
options,
|
||||
}: Props) => (
|
||||
<div
|
||||
id={`messageAttachmentList_${postId}`}
|
||||
className='attachment__list'
|
||||
>
|
||||
{attachments.map((attachment, i) => (
|
||||
<MessageAttachment
|
||||
attachment={attachment}
|
||||
postId={postId}
|
||||
key={'att_' + i}
|
||||
options={options}
|
||||
imagesMetadata={imagesMetadata}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
id={`messageAttachmentList_${this.props.postId}`}
|
||||
className='attachment__list'
|
||||
>
|
||||
{content}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
export default memo(MessageAttachmentList);
|
||||
|
||||
@@ -60,9 +60,8 @@ exports[`PostBodyAdditionalContent with a message attachment should render corre
|
||||
<span>
|
||||
some children
|
||||
</span>
|
||||
<MessageAttachmentList
|
||||
<Memo(MessageAttachmentList)
|
||||
attachments={Array []}
|
||||
imagesMetadata={Object {}}
|
||||
postId="post_id_1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user