[MM-56298] Convert ./components/file_attachment/file_thumbnail/file_thumbnail.tsx from Class Component to Function Component (#25761)
* [MM-56298] Convert `./components/file_attachment/file_thumbnail/file_thumbnail.tsx` from Class Component to Function Component * refactor: implement code review changes
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ab6e206a51
Коммит
cac50f593b
@@ -10,7 +10,7 @@ exports[`FileAttachment should match snapshot, after change from file to image 1
|
|||||||
href="#"
|
href="#"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<Connect(FileThumbnail)
|
<Connect(Component)
|
||||||
fileInfo={
|
fileInfo={
|
||||||
Object {
|
Object {
|
||||||
"archived": false,
|
"archived": false,
|
||||||
@@ -99,7 +99,7 @@ exports[`FileAttachment should match snapshot, regular file 1`] = `
|
|||||||
href="#"
|
href="#"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<Connect(FileThumbnail)
|
<Connect(Component)
|
||||||
fileInfo={
|
fileInfo={
|
||||||
Object {
|
Object {
|
||||||
"archived": false,
|
"archived": false,
|
||||||
@@ -332,7 +332,7 @@ exports[`FileAttachment should match snapshot, svg image 1`] = `
|
|||||||
href="#"
|
href="#"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<Connect(FileThumbnail)
|
<Connect(Component)
|
||||||
fileInfo={
|
fileInfo={
|
||||||
Object {
|
Object {
|
||||||
"archived": false,
|
"archived": false,
|
||||||
@@ -532,7 +532,7 @@ exports[`FileAttachment should match snapshot, without compact display and witho
|
|||||||
href="#"
|
href="#"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<Connect(FileThumbnail)
|
<Connect(Component)
|
||||||
fileInfo={
|
fileInfo={
|
||||||
Object {
|
Object {
|
||||||
"archived": false,
|
"archived": false,
|
||||||
|
|||||||
@@ -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 {FileInfo} from '@mattermost/types/files';
|
import type {FileInfo} from '@mattermost/types/files';
|
||||||
|
|
||||||
@@ -19,12 +19,12 @@ type Props = {
|
|||||||
fileInfo: FileInfo;
|
fileInfo: FileInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class FileThumbnail extends React.PureComponent<Props> {
|
const FileThumbnail = ({
|
||||||
render() {
|
fileInfo,
|
||||||
const {fileInfo} = this.props;
|
enableSVGs,
|
||||||
|
}: Props) => {
|
||||||
const type = getFileType(fileInfo.extension);
|
const type = getFileType(fileInfo.extension);
|
||||||
|
|
||||||
let thumbnail;
|
|
||||||
if (type === FileTypes.IMAGE) {
|
if (type === FileTypes.IMAGE) {
|
||||||
let className = 'post-image';
|
let className = 'post-image';
|
||||||
|
|
||||||
@@ -48,18 +48,17 @@ export default class FileThumbnail extends React.PureComponent<Props> {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else if (fileInfo.extension === FileTypes.SVG && this.props.enableSVGs) {
|
} else if (fileInfo.extension === FileTypes.SVG && enableSVGs) {
|
||||||
thumbnail = (
|
return (
|
||||||
<img
|
<img
|
||||||
alt={'file thumbnail image'}
|
alt={'file thumbnail image'}
|
||||||
className='post-image normal'
|
className='post-image normal'
|
||||||
src={getFileUrl(fileInfo.id)}
|
src={getFileUrl(fileInfo.id)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
thumbnail = <div className={'file-icon ' + getIconClassName(type)}/>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return thumbnail;
|
return <div className={'file-icon ' + getIconClassName(type)}/>;
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
export default memo(FileThumbnail);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ exports[`components/file_search_result/FileSearchResultItem should match snapsho
|
|||||||
className="FileSearchResultItem"
|
className="FileSearchResultItem"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<Connect(FileThumbnail)
|
<Connect(Component)
|
||||||
fileInfo={
|
fileInfo={
|
||||||
Object {
|
Object {
|
||||||
"archived": false,
|
"archived": false,
|
||||||
@@ -167,7 +167,7 @@ exports[`components/file_search_result/FileSearchResultItem should match snapsho
|
|||||||
className="FileSearchResultItem"
|
className="FileSearchResultItem"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<Connect(FileThumbnail)
|
<Connect(Component)
|
||||||
fileInfo={
|
fileInfo={
|
||||||
Object {
|
Object {
|
||||||
"archived": false,
|
"archived": false,
|
||||||
@@ -334,7 +334,7 @@ exports[`components/file_search_result/FileSearchResultItem should match snapsho
|
|||||||
className="FileSearchResultItem"
|
className="FileSearchResultItem"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<Connect(FileThumbnail)
|
<Connect(Component)
|
||||||
fileInfo={
|
fileInfo={
|
||||||
Object {
|
Object {
|
||||||
"archived": false,
|
"archived": false,
|
||||||
@@ -501,7 +501,7 @@ exports[`components/file_search_result/FileSearchResultItem should match snapsho
|
|||||||
className="FileSearchResultItem"
|
className="FileSearchResultItem"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<Connect(FileThumbnail)
|
<Connect(Component)
|
||||||
fileInfo={
|
fileInfo={
|
||||||
Object {
|
Object {
|
||||||
"archived": false,
|
"archived": false,
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user