Skip to content

Commit

Permalink
Fix #9892 thumb max size filter restored (#9893)
Browse files Browse the repository at this point in the history
* Fix #9892 thumb max size filter restored
  • Loading branch information
MV88 authored Jan 18, 2024
1 parent a666db2 commit 7eb4d3d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions web/client/components/background/BackgroundDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export default class BackgroundDialog extends React.Component {
{<Form style={{width: '100%'}}>
{this.renderThumbnailErrors()}
<Thumbnail
checkOriginalFileSize
onUpdate={(data, url) => this.setState({thumbnail: {data, url}})}
onError={(errors) => this.setState({thumbnailErrors: errors})}
message={<Message msgId="backgroundDialog.thumbnailMessage"/>}
Expand Down
4 changes: 3 additions & 1 deletion web/client/components/maps/forms/Thumbnail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class MapThumbnail extends React.Component {
onRemoveThumbnail: PropTypes.func,
// I18N
message: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
suggestion: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
suggestion: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
checkOriginalFileSize: PropTypes.bool
};

static contextTypes = {
Expand Down Expand Up @@ -113,6 +114,7 @@ class MapThumbnail extends React.Component {
ref="imgThumbnail"
thumbnail={this.getThumbnailUrl()}
className={null}
checkOriginalFileSize={this.props.checkOriginalFileSize}
dropZoneProps={{
className: 'dropzone alert alert-info',
rejectClassName: 'alert-danger'
Expand Down
9 changes: 8 additions & 1 deletion web/client/components/misc/Thumbnail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const getThumbnail = (files, options) => {
* @prop {node} message display node message inside thumbnail
* @prop {string} thumbnail source of thumbnail
* @prop {number} maxFileSize max size of file
* @prop {boolean} checkOriginalFileSize if true it checks maxFileSize compared to source image
* @prop {array} supportedImageTypes array of images supported mime types
* @prop {options} thumbnailOptions options to scale the thumbnail to fit a specific size
* @prop {object} dropZoneProps props for dropzone component
Expand All @@ -64,6 +65,7 @@ const Thumbnail = forwardRef(({
removeTooltipId = 'removeThumbnail',
style = {},
maxFileSize = 500000,
checkOriginalFileSize = false,
supportedImageTypes = ['image/png', 'image/jpeg', 'image/jpg'],
thumbnailOptions,
dropZoneProps = {
Expand All @@ -89,9 +91,13 @@ const Thumbnail = forwardRef(({

const handleDrop = (files) => {
const imageType = files?.[0]?.type;
const imageSize = files?.[0]?.size;
const isASupportedImage = supportedImageTypes.indexOf(imageType) !== -1;
if (checkOriginalFileSize && imageSize >= maxFileSize) {
return onError(['SIZE'], files);
}
setPending(true);
getThumbnail(files, thumbnailOptions)
return getThumbnail(files, thumbnailOptions)
.then(({ data, size }) => {
if (!mounted.current) {
return null;
Expand All @@ -112,6 +118,7 @@ const Thumbnail = forwardRef(({
setPending(false);
return onError(e);
});

};

const handleRemove = (event) => {
Expand Down

0 comments on commit 7eb4d3d

Please sign in to comment.