From cac50f593b021e025eb7fdd294c3d8c82c421442 Mon Sep 17 00:00:00 2001 From: Syed Ali Abbas Zaidi <88369802+Syed-Ali-Abbas-Zaidi@users.noreply.github.com> Date: Thu, 21 Dec 2023 15:13:08 +0500 Subject: [PATCH] [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 --- .../file_attachment.test.tsx.snap | 8 +- .../file_thumbnail/file_thumbnail.tsx | 77 +++++++++---------- .../file_search_result_item.test.tsx.snap | 8 +- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/webapp/channels/src/components/file_attachment/__snapshots__/file_attachment.test.tsx.snap b/webapp/channels/src/components/file_attachment/__snapshots__/file_attachment.test.tsx.snap index abe7d82192..39301daad6 100644 --- a/webapp/channels/src/components/file_attachment/__snapshots__/file_attachment.test.tsx.snap +++ b/webapp/channels/src/components/file_attachment/__snapshots__/file_attachment.test.tsx.snap @@ -10,7 +10,7 @@ exports[`FileAttachment should match snapshot, after change from file to image 1 href="#" onClick={[Function]} > - - - - { - render() { - const {fileInfo} = this.props; - const type = getFileType(fileInfo.extension); +const FileThumbnail = ({ + fileInfo, + enableSVGs, +}: Props) => { + const type = getFileType(fileInfo.extension); - let thumbnail; - if (type === FileTypes.IMAGE) { - let className = 'post-image'; + if (type === FileTypes.IMAGE) { + let className = 'post-image'; - if (fileInfo.width < Constants.THUMBNAIL_WIDTH && fileInfo.height < Constants.THUMBNAIL_HEIGHT) { - className += ' small'; - } else { - className += ' normal'; - } - - let thumbnailUrl = getFileThumbnailUrl(fileInfo.id); - if (isGIFImage(fileInfo.extension) && !fileInfo.has_preview_image) { - thumbnailUrl = getFileUrl(fileInfo.id); - } - - return ( -
- ); - } else if (fileInfo.extension === FileTypes.SVG && this.props.enableSVGs) { - thumbnail = ( - {'file - ); + if (fileInfo.width < Constants.THUMBNAIL_WIDTH && fileInfo.height < Constants.THUMBNAIL_HEIGHT) { + className += ' small'; } else { - thumbnail =
; + className += ' normal'; } - return thumbnail; + let thumbnailUrl = getFileThumbnailUrl(fileInfo.id); + if (isGIFImage(fileInfo.extension) && !fileInfo.has_preview_image) { + thumbnailUrl = getFileUrl(fileInfo.id); + } + + return ( +
+ ); + } else if (fileInfo.extension === FileTypes.SVG && enableSVGs) { + return ( + {'file + ); } -} + + return
; +}; + +export default memo(FileThumbnail); diff --git a/webapp/channels/src/components/file_search_results/__snapshots__/file_search_result_item.test.tsx.snap b/webapp/channels/src/components/file_search_results/__snapshots__/file_search_result_item.test.tsx.snap index 9691b688d4..de5ba91462 100644 --- a/webapp/channels/src/components/file_search_results/__snapshots__/file_search_result_item.test.tsx.snap +++ b/webapp/channels/src/components/file_search_results/__snapshots__/file_search_result_item.test.tsx.snap @@ -9,7 +9,7 @@ exports[`components/file_search_result/FileSearchResultItem should match snapsho className="FileSearchResultItem" onClick={[Function]} > - - - -