forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate view_image.jsx to be follow the guidline (mattermost#204)
* Move any PropTypes from the bottom of the file to be defined at the top of the component * Make sure to add documentation for each prop * Switch the component to extend React.PureComponent instead of React.Component * Remove the jQuery use * Clean up import paths * Make startIndex to be a required prop * Add test and snapshot for the ViewImageModal component * Remove function binding above and then change corresponding function to arrow style * Separate image preview and add test and initial snanshot * Migrate ImageView to functional style * Separate LoadingImagePreview and add test and initial snanshot * Update snapshot of ViewImageModal * fix component tests
- Loading branch information
Showing
9 changed files
with
1,783 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import {getFilePreviewUrl, getFileUrl} from 'mattermost-redux/utils/file_utils'; | ||
|
||
import {canDownloadFiles} from 'utils/file_utils'; | ||
|
||
export default function ImagePreview({fileInfo}) { | ||
const {has_preview_image: hasPreviewImage, id} = fileInfo; | ||
const fileUrl = getFileUrl(id); | ||
const previewUrl = hasPreviewImage ? getFilePreviewUrl(id) : fileUrl; | ||
|
||
if (!canDownloadFiles()) { | ||
return <img src={previewUrl}/>; | ||
} | ||
|
||
return ( | ||
<a | ||
href={fileUrl} | ||
target='_blank' | ||
rel='noopener noreferrer' | ||
download={true} | ||
> | ||
<img src={previewUrl}/> | ||
</a> | ||
); | ||
} | ||
|
||
ImagePreview.propTypes = { | ||
|
||
/** | ||
* The file info object | ||
*/ | ||
fileInfo: PropTypes.object.isRequired | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import loadingGif from 'images/load.gif'; | ||
|
||
export default function LoadingImagePreview({loading, progress}) { | ||
let progressView = null; | ||
if (progress) { | ||
progressView = ( | ||
<span className='loader-percent'> | ||
{`${loading} ${progress}%`} | ||
</span> | ||
); | ||
} | ||
|
||
return ( | ||
<div className='view-image__loading'> | ||
<img | ||
className='loader-image' | ||
src={loadingGif} | ||
/> | ||
{progressView} | ||
</div> | ||
); | ||
} | ||
|
||
LoadingImagePreview.propTypes = { | ||
|
||
/** | ||
* The percent number of the progress | ||
*/ | ||
progress: PropTypes.number, | ||
|
||
/** | ||
* The loading message to display | ||
*/ | ||
loading: PropTypes.string | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/components/__snapshots__/image_preview.test.jsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`components/ImagePreview should match snapshot, with and without preview 1`] = ` | ||
<a | ||
download={true} | ||
href="/api/v4/files/file_id" | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
<img | ||
src="/api/v4/files/file_id" | ||
/> | ||
</a> | ||
`; | ||
|
||
exports[`components/ImagePreview should match snapshot, with and without preview 2`] = ` | ||
<a | ||
download={true} | ||
href="/api/v4/files/file_id_1" | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
<img | ||
src="/api/v4/files/file_id_1/preview" | ||
/> | ||
</a> | ||
`; |
Oops, something went wrong.