[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>
Этот коммит содержится в:
Syed Ali Abbas Zaidi
2023-12-21 15:12:11 +05:00
коммит произвёл GitHub
родитель dadc752212
Коммит 4fb3d7a349
2 изменённых файлов: 25 добавлений и 30 удалений

Просмотреть файл

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information. // 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 {MessageAttachment as MessageAttachmentType} from '@mattermost/types/message_attachments';
import type {PostImage} from '@mattermost/types/posts'; import type {PostImage} from '@mattermost/types/posts';
@@ -33,32 +33,28 @@ type Props = {
imagesMetadata?: Record<string, PostImage>; imagesMetadata?: Record<string, PostImage>;
} }
export default class MessageAttachmentList extends React.PureComponent<Props> { const EMPTY_METADATA: Record<string, PostImage> = {};
static defaultProps = {
imagesMetadata: {},
};
render() { const MessageAttachmentList = ({
const content = [] as JSX.Element[]; imagesMetadata = EMPTY_METADATA,
this.props.attachments.forEach((attachment, i) => { attachments,
content.push( postId,
<MessageAttachment options,
attachment={attachment} }: Props) => (
postId={this.props.postId}
key={'att_' + i}
options={this.props.options}
imagesMetadata={this.props.imagesMetadata}
/>,
);
});
return (
<div <div
id={`messageAttachmentList_${this.props.postId}`} id={`messageAttachmentList_${postId}`}
className='attachment__list' className='attachment__list'
> >
{content} {attachments.map((attachment, i) => (
<MessageAttachment
attachment={attachment}
postId={postId}
key={'att_' + i}
options={options}
imagesMetadata={imagesMetadata}
/>
))}
</div> </div>
); );
}
} export default memo(MessageAttachmentList);

Просмотреть файл

@@ -60,9 +60,8 @@ exports[`PostBodyAdditionalContent with a message attachment should render corre
<span> <span>
some children some children
</span> </span>
<MessageAttachmentList <Memo(MessageAttachmentList)
attachments={Array []} attachments={Array []}
imagesMetadata={Object {}}
postId="post_id_1" postId="post_id_1"
/> />
</div> </div>