[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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
dadc752212
Коммит
4fb3d7a349
@@ -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}
|
<div
|
||||||
key={'att_' + i}
|
id={`messageAttachmentList_${postId}`}
|
||||||
options={this.props.options}
|
className='attachment__list'
|
||||||
imagesMetadata={this.props.imagesMetadata}
|
>
|
||||||
/>,
|
{attachments.map((attachment, i) => (
|
||||||
);
|
<MessageAttachment
|
||||||
});
|
attachment={attachment}
|
||||||
|
postId={postId}
|
||||||
|
key={'att_' + i}
|
||||||
|
options={options}
|
||||||
|
imagesMetadata={imagesMetadata}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
export default memo(MessageAttachmentList);
|
||||||
<div
|
|
||||||
id={`messageAttachmentList_${this.props.postId}`}
|
|
||||||
className='attachment__list'
|
|
||||||
>
|
|
||||||
{content}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user