-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avatar Image Upload Limit #5900
Avatar Image Upload Limit #5900
Conversation
@@ -65,7 +66,7 @@ function getDataForUpload(fileData) { | |||
name: fileData.fileName || fileData.name || 'chat_attachment', | |||
type: fileData.type, | |||
uri: fileData.uri, | |||
size: fileData.size, | |||
size: lodashGet(fileData, 'fileSize', lodashGet(fileData, 'size')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need lodashGet here? will FileData
ever be undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh I did answer this yesterday, can't find the comment.
Earlier we had fileData.size
but it gives size is undefined
. I checked it returns fileData.fileSize
. So I've used both to keep it backward compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I think it is better like this.
Filedata.filesize || filedata.size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. I thought generally we use lodash.get
for optional checks.
@@ -52,6 +54,9 @@ const propTypes = { | |||
/** Size of Indicator */ | |||
size: PropTypes.string, | |||
|
|||
/** Max image size */ | |||
maxUploadSizeInMB: PropTypes.number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this prop? I don't think we want to customize this ever.
@@ -52,6 +54,9 @@ const propTypes = { | |||
/** Size of Indicator */ | |||
size: PropTypes.string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add the correct type here?
size: PropTypes.string, | |
size: size: PropTypes.oneOf([CONST.AVATAR_SIZE.LARGE, CONST.AVATAR_SIZE.DEFAULT]), |
@@ -93,6 +102,23 @@ class AvatarWithImagePicker extends React.Component { | |||
this.animation.stop(); | |||
} | |||
|
|||
/** | |||
* Toggle max upload limit mModal visibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Toggle max upload limit mModal visibility | |
* Toggle max upload limit modal's visibility |
src/CONST.js
Outdated
@@ -4,6 +4,7 @@ const NEW_EXPENSIFY_URL = 'https://new.expensify.com'; | |||
const CONST = { | |||
// 50 megabytes in bytes | |||
API_MAX_ATTACHMENT_SIZE: 52428800, | |||
AVATAR_MAX_ATTACHMENT_SIZE_MB: 3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change it to Bytes? Most of the time arithmetic operations will be in bytes.
* @returns {Boolean} | ||
*/ | ||
isValidSize(image) { | ||
return !image || !this.props.maxUploadSizeInMB || lodashGet(image, 'size', 0) < (this.props.maxUploadSizeInMB * 1024 * 1024); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the image is null, it returns true
.
onConfirm={() => this.setUploadLimitModalVisibility(false)} | ||
onCancel={() => this.setUploadLimitModalVisibility(false)} | ||
isVisible={this.state.isMaxUploadSizeModalOpen} | ||
prompt={this.props.translate('avatarWithImagePicker.sizeExceeded', {maxUploadSizeInMB: this.props.maxUploadSizeInMB})} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use x * 1024 * 1024
here instead.
src/languages/es.js
Outdated
@@ -216,6 +216,8 @@ export default { | |||
uploadPhoto: 'Subir foto', | |||
removePhoto: 'Eliminar foto', | |||
editImage: 'Editar foto', | |||
imageUploadFailed: 'Error al cargar la imagen', | |||
sizeExceeded: ({maxUploadSizeInMB}) => `La imagen supera el tamaño máximo de ${maxUploadSizeInMB} MB.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sizeExceeded: ({maxUploadSizeInMB}) => `La imagen supera el tamaño máximo de ${maxUploadSizeInMB} MB.`, | |
sizeExceeded: ({maxUploadSizeInMB}) => `La imagen supera el tamaño máximo de ${maxUploadSizeInMB}MB.`, |
@@ -211,6 +211,7 @@ class ProfilePage extends Component { | |||
isUsingDefaultAvatar={this.props.myPersonalDetails.avatar.includes('/images/avatars/avatar')} | |||
anchorPosition={styles.createMenuPositionProfile} | |||
size={CONST.AVATAR_SIZE.LARGE} | |||
maxUploadSizeInMB={CONST.AVATAR_MAX_ATTACHMENT_SIZE_MB} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed based on my comment above.
@@ -158,6 +158,7 @@ class WorkspaceSettingsPage extends React.Component { | |||
isUsingDefaultAvatar={!this.state.previewAvatarURL} | |||
onImageSelected={this.uploadAvatar} | |||
onImageRemoved={this.removeAvatar} | |||
maxUploadSizeInMB={CONST.AVATAR_MAX_ATTACHMENT_SIZE_MB} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
@parasharrajat PR Updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few changes.
src/CONST.js
Outdated
@@ -4,6 +4,7 @@ const NEW_EXPENSIFY_URL = 'https://new.expensify.com'; | |||
const CONST = { | |||
// 50 megabytes in bytes | |||
API_MAX_ATTACHMENT_SIZE: 52428800, | |||
AVATAR_MAX_ATTACHMENT_SIZE_MB: 3145728, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hoped you would change the name AVATAR_MAX_ATTACHMENT_SIZE _MB. Don't forget to update the references.
@@ -65,7 +66,7 @@ function getDataForUpload(fileData) { | |||
name: fileData.fileName || fileData.name || 'chat_attachment', | |||
type: fileData.type, | |||
uri: fileData.uri, | |||
size: fileData.size, | |||
size: lodashGet(fileData, 'fileSize', lodashGet(fileData, 'size')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a question?
Sorry about the var name, will update |
@parasharrajat PR updated. Any other changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. tests well.
Ready for final review and possibly for merge after N6.cc: @pecanoro
Thanks, @parasharrajat for the detailed review. Appreciate it. |
* @returns {Boolean} | ||
*/ | ||
isValidSize(image) { | ||
return image && lodashGet(image, 'size', 0) < CONST.AVATAR_MAX_ATTACHMENT_SIZE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we passing the size as a prop but then using the constant directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pecanoro size
is for the size of the Avatar image - Large or default. Wasn't added in this PR. I just updated proptypes.
and for upload size limit I had added props but based on the feedback removed, so using CONST directly.
@akshayasalvi Could you please merge main into your PR? I want to make sure there are no issues as a lot has been changed in N6. Thanks for your patience. |
On it for all PRs |
Merged main and retested @parasharrajat @pecanoro |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to production by @roryabraham in version: 1.1.10-2 🚀
|
Details
Fixed Issues
$ #5778
Tests
QA Steps
Tested On
Screenshots
Web
web-upload-limit-compressed.mp4
Mobile Web
Desktop
iOS
Android