Skip to content
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

Merged
merged 14 commits into from
Oct 19, 2021

Conversation

akshayasalvi
Copy link
Contributor

@akshayasalvi akshayasalvi commented Oct 15, 2021

Details

  • Added upload limit to AvatarImage in Workspace
  • Added the same for Profile Image as well

Fixed Issues

$ #5778

Tests

  1. Tested by uploading images of different sizes in all platforms.
  2. Tested modal with language changes.

QA Steps

  1. Go to any workspace via Sidebar
  2. Click on the Workspace Title to edit it.
  3. Try uploading an image of size > 3MB, it should throw an error
  4. Upload an image within the limit, it should successfully allow uploading

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

web-upload-limit-compressed.mp4

web-es-upload-limit

Mobile Web

mweb-upload-limit

Desktop

desktop-upload-limit

iOS

ios-upload-limit

Android

android-upload-limit

@akshayasalvi akshayasalvi requested a review from a team as a code owner October 15, 2021 19:40
@MelvinBot MelvinBot requested review from pecanoro and removed request for a team October 15, 2021 19:40
@@ -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')),
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a question?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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,
Copy link
Member

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,
Copy link
Member

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?

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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,
Copy link
Member

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);
Copy link
Member

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})}
Copy link
Member

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.

@@ -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.`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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}
Copy link
Member

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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@akshayasalvi
Copy link
Contributor Author

@parasharrajat PR Updated

Copy link
Member

@parasharrajat parasharrajat left a 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,
Copy link
Member

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')),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a question?

@akshayasalvi
Copy link
Contributor Author

Sorry about the var name, will update

@akshayasalvi
Copy link
Contributor Author

@parasharrajat PR updated. Any other changes?

Copy link
Member

@parasharrajat parasharrajat left a 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

@akshayasalvi
Copy link
Contributor Author

Thanks, @parasharrajat for the detailed review. Appreciate it.

* @returns {Boolean}
*/
isValidSize(image) {
return image && lodashGet(image, 'size', 0) < CONST.AVATAR_MAX_ATTACHMENT_SIZE;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@parasharrajat
Copy link
Member

@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.

@akshayasalvi
Copy link
Contributor Author

@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

@akshayasalvi
Copy link
Contributor Author

akshayasalvi commented Oct 19, 2021

Merged main and retested @parasharrajat @pecanoro

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@pecanoro pecanoro merged commit 73b7551 into Expensify:main Oct 19, 2021
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @pecanoro in version: 1.1.8-10 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @roryabraham in version: 1.1.10-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants