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

Fix resizes on image upload #8928

Merged
merged 11 commits into from
Jun 3, 2022
Merged

Conversation

allroundexperts
Copy link
Contributor

@allroundexperts allroundexperts commented May 10, 2022

Details

Fixed Issues

$ #8590

Tests

  1. In any of the chat room, upload an image via clicking + icon.
  2. The uploaded image in the chat should not resize and remain the same size throughout.
  • Verify that no errors appear in the JS console

PR Review Checklist

Contributor (PR Author) Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there’s a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained “why” the code was doing something instead of only explaining “what” the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named “index.js”. All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose and it is
  • If a new CSS style is added I verified that:
    • A similar style doesn’t already exist
    • The style can’t be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.

PR Reviewer Checklist

  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there’s a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained “why” the code was doing something instead of only explaining “what” the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named “index.js”. All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn’t already exist
    • The style can’t be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.

QA Steps

  1. In any of the chat room, upload an image via clicking + icon.
  2. The uploaded image in the chat should not resize and remain the same size throughout.
  • Verify that no errors appear in the JS console

Screenshots

Web

167023275-f91c0d23-80bb-4415-9023-d07677fe6544.mp4

Mobile Web

simulator-screen-recording-iphone-13-2022-05-12-at-233355_flQfDWOD.mp4

Desktop

screen-recording-2022-05-12-at-113641-pm_c8BPFcNJ.mp4

iOS

simulator-screen-recording-iphone-13-2022-05-12-at-214353_2o7S3HVD.mp4

Android

screen-recording-2022-05-12-at-112758-pm_odUBRRbl.mp4

@github-actions
Copy link
Contributor

github-actions bot commented May 10, 2022

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@allroundexperts allroundexperts marked this pull request as ready for review May 12, 2022 19:10
@allroundexperts allroundexperts requested a review from a team as a code owner May 12, 2022 19:10
@melvin-bot melvin-bot bot requested review from chiragsalian and Santhosh-Sellavel and removed request for a team May 12, 2022 19:10
@allroundexperts
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@allroundexperts allroundexperts changed the title Fix 8590 Fix resizes on image upload May 12, 2022
@Santhosh-Sellavel
Copy link
Collaborator

Sorry, @allroundexperts missed this one.
Can you pull changes from since this is over a week old?
I'll review it tomorrow!
cc: @chiragsalian

@allroundexperts
Copy link
Contributor Author

@Santhosh-Sellavel Updated.

@Santhosh-Sellavel
Copy link
Collaborator

@allroundexperts
I am getting a new issue here, the attachment get's hidden for a couple of secs

Attachment.get.hidden.for.a.second.mov

cc: @chiragsalian

src/components/ThumbnailImage.js Outdated Show resolved Hide resolved
src/components/ThumbnailImage.js Outdated Show resolved Hide resolved
@allroundexperts
Copy link
Contributor Author

@Santhosh-Sellavel Is this issue intermittent? Or does it always happen?

@Santhosh-Sellavel
Copy link
Collaborator

@Santhosh-Sellavel Is this issue intermittent? Or does it always happen?
At that time able to reproduce consistently. The image doesn’t disappear but loading is shown will sending the image.

Screen.Recording.2022-05-21.at.3.43.41.AM.mov

@chiragsalian This is expected behavior right?

@chiragsalian
Copy link
Contributor

Hmm so it looks like once we attach an image,

  1. First the image shows up with its own thumbnail with correct dimensions.
  2. Then once Report_AddComment finishes then the loader gif shows up.
  3. Then the loader hides and the same thumbnail image from step 1 shows up.

@allroundexperts, do we need the loader gif? Is it possible to remove it.
image

The reason i suggest this is because with our offline first design changes if the user is offline we'll still show the attachment thumbail as per step 1 and have a different language to show a comment hasn't been saved in the server. So i think showing the loader in the middle doesn't have much value here. Thoughts?

@allroundexperts
Copy link
Contributor Author

allroundexperts commented May 23, 2022 via email

@chiragsalian
Copy link
Contributor

Can we not keep it as the attachment thumbnail before the api request was completed? From my comment above the image thumbnail from step 1 and 3 looks identical so i was wondering if we could just not show the loader gif?
If it helps this is what i see,

  • step 1, i just uploaded the image,
    image

  • step 2, image uploaded complete,
    image

  • step 3, loader hides. It looks like the same thumbnail from step 1 is shown,
    image

I was wondering If we could update the code so that the loader from step 2 would not be shown so that the attachment upload looks smoother. I haven't looked at the code closely but i imagine if the response dimensions and image is the same as what we already had then don't show the loader. Thoughts?

@allroundexperts
Copy link
Contributor Author

Can we not keep it as the attachment thumbnail before the api request was completed? From my comment above the image thumbnail from step 1 and 3 looks identical so i was wondering if we could just not show the loader gif? If it helps this is what i see,

  • step 1, i just uploaded the image,
    image
  • step 2, image uploaded complete,
    image
  • step 3, loader hides. It looks like the same thumbnail from step 1 is shown,
    image

I was wondering If we could update the code so that the loader from step 2 would not be shown so that the attachment upload looks smoother. I haven't looked at the code closely but i imagine if the response dimensions and image is the same as what we already had then don't show the loader. Thoughts?

So it's not working like that. As explained in the issue description as well, here's what is happening:

  1. User uploads the image and we have a blob (image stored on users local machine). We display that blob. We also upload that blob to the API. The API call succeeds and we get a response containing the image link on the server with its dimensions.

  2. Next, we download the image from the link (this is where the loader is shown). The placeholder (loading image) is the same size as the thumbnail in step 1 because we have the image dimensions as an API response from the server.

  3. Once the image is downloaded, it is now shown to the user.

The loader is shown while the image is downloaded. It's NOT shown while the API call is being processed.

@chiragsalian
Copy link
Contributor

chiragsalian commented May 23, 2022

Okay, so let's take your step you mentioned in the earlier comment. Is it possible to to not show the loader while downloading the image when we already have a thumbnail with the proper dimensions? I'm pretty much asking if we can come up with a plan to not show the loader in the middle since it feels unnecessary and weird when the user is sees a proper thumbnail, then sees a loader gif to again see the proper thumbnail from earlier.

Or do you feel there is a time when the user attaches an image that the loader is necessary? If so can you explain why?

I do think when there is no thumbnail the loader should still be shown, like when we switch to a chat and you are downloading messages and images then i think it makes sense to have.

Also if its difficult to change i don't mind keeping it too. Was just wondering if this would be a nice user experience improvement to remove the loader gif when image thumbnail and dimensions are already known.

@allroundexperts
Copy link
Contributor Author

@chiragsalian If you look at the code, you'll see that when the user uploads the image from his local machine, at that point, we create a offline db record and save it in the local storage. That db record contains all the fields as a remote db record would except the image url will be the one that points to the local blob url. As soon as the API request is made, the record that was saved locally on users storage gets replaced with the remote record that has the image url pointing to your storage server.

The approach that you're suggesting would require:
a. Store a duplicate record on local storage which doesn't get over-ridden by the server response.
b. Make the report screen smart enough to choose between the duplicate record and the over-ridden record.

This all won't still work for the other users in the chat room. We'll still need to show them the loader because they only have a single source to get the image from ie your server.

Doing this change for just a single user (other users would still see loader) is not worth the time in my opinion.

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

Looks Good & Tests well!

cc: @chiragsalian

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented May 27, 2022

PR Reviewer Checklist

  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there’s a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained “why” the code was doing something instead of only explaining “what” the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named “index.js”. All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn’t already exist
    • The style can’t be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.

Copy link
Contributor

@chiragsalian chiragsalian left a comment

Choose a reason for hiding this comment

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

Suggested some minor changes but the rest LGTM and works well.

src/components/ThumbnailImage.js Outdated Show resolved Hide resolved
src/components/ThumbnailImage.js Outdated Show resolved Hide resolved
src/components/ThumbnailImage.js Show resolved Hide resolved
@chiragsalian
Copy link
Contributor

Friendly bump @allroundexperts to update the PR based on my review comments.

@allroundexperts
Copy link
Contributor Author

Friendly bump @allroundexperts to update the PR based on my review comments.

Handled.

src/components/ThumbnailImage.js Outdated Show resolved Hide resolved
Copy link
Contributor

@chiragsalian chiragsalian left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for the changes.

PR Reviewer Checklist

  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there’s a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained “why” the code was doing something instead of only explaining “what” the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named “index.js”. All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn’t already exist
    • The style can’t be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.

@chiragsalian
Copy link
Contributor

Merging since santhosh approved earlier.

@chiragsalian chiragsalian merged commit 50da22f into Expensify:main Jun 3, 2022
@OSBotify
Copy link
Contributor

OSBotify commented Jun 3, 2022

✋ 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

OSBotify commented Jun 6, 2022

🚀 Deployed to staging by @chiragsalian in version: 1.1.72-0 🚀

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

@joelbettner
Copy link
Contributor

joelbettner commented Jun 7, 2022

@allroundexperts FYI, this got reverted to fix this deploy blocker: #9334

Without taking additional time on a time sensitive issue, we could not narrow down which part of this PR actually caused the bug. It is probably a good idea to "retry" this PR, but make sure we test for the bug from the deploy blocker as the changes are being made so we can pinpoint the issue and fix it.

@OSBotify
Copy link
Contributor

OSBotify commented Jun 8, 2022

🚀 Deployed to production by @yuwenmemon in version: 1.1.73-2 🚀

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

Comment on lines +47 to +48
const imageWidth = htmlAttribs['data-expensify-width'] ? parseInt(htmlAttribs['data-expensify-width'], 10) : undefined;
const imageHeight = htmlAttribs['data-expensify-height'] ? parseInt(htmlAttribs['data-expensify-height'], 10) : undefined;
Copy link
Member

Choose a reason for hiding this comment

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

if data-expensify-width is set to "0", it breaks PDF rendering. #33626

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

6 participants