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

Site Settings: Show error notice when icon fails to upload #11043

Merged
merged 4 commits into from
Feb 1, 2017

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Jan 30, 2017

This pull request seeks to improve the handling of a failed media upload in the site icon flow. Currently if a media fails to upload, we still try to receive it into Redux state and use it as the site icon, resulting in the icon resetting to the initial value with no indication aside from a console error. The changes here make it such that if the icon upload fails, a global error notice is shown to indicate the failure, and no attempt is made to use the media as the icon.

Testing instructions:

This was discovered in testing site icon usage in the desktop application. It may also be possible to test by toggling "Offline" in Chrome Network tab at point of clicking "Done" in Site Icon flow. If desktop app is available for testing, simply change into calypso directory and checkout this branch before starting desktop app with make run.

  1. Navigate to site settings
  2. Select a site
  3. Click Change below Site Icon field
  4. Select an image and click Continue
  5. Crop image such that it is changed from the original image
  6. Click Done
  7. Note that if media fails to upload, an error notice is shown

@aduth aduth added [Feature] Site Settings All other general site settings. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 30, 2017
@aduth aduth added this to the Site Icon milestone Jan 30, 2017
@aduth aduth requested a review from youknowriad January 30, 2017 15:00
@matticbot
Copy link
Contributor

if ( media ) {
this.saveSiteIconSetting( siteId, media );
} else {
this.props.errorNotice( translate( 'An error occurred while uploading the file' ) );
Copy link

Choose a reason for hiding this comment

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

Hi! I've found a possible matching string that has already been translated 23 times:
translate( 'An error occurred while uploading the file.' ) ES Score: 9.38

Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented).

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

It is working as expected but maybe we could avoid calling receiveMedia on falsy media.

@@ -105,7 +106,13 @@ class SiteIconSetting extends Component {
}

MediaStore.off( 'change', checkUploadComplete );
this.saveSiteIconSetting( siteId, media );
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we avoid calling this.props.receiveMedia( siteId, media ) above if we have no media?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we avoid calling this.props.receiveMedia( siteId, media ) above if we have no media?

Good question. I recall I'd recently moved that line to before the isItemBeingUploaded probably to allow optimistic display of the image while it's uploading. Let me check what the impact here is and what alternatives we have...

@aduth
Copy link
Contributor Author

aduth commented Jan 31, 2017

Thanks for the review @youknowriad . In the last few commits, I revised the change handler to check whether the media is falsey and, if so, avoid receiving it and instead ensure that it's removed from Redux state (assuming that it's a failed upload).

Aside: I found easiest way to test is to toggle "Offline" in Chrome's network tab right before clicking "Done" of cropping screen in the media modal.

@youknowriad
Copy link
Contributor

I don't know if you consider this blocking or not, but when I have a failed upload, the site icon is empty after that (I see the default icon), Should we keep the old site icon or something?

@aduth
Copy link
Contributor Author

aduth commented Jan 31, 2017

@youknowriad Another good point. It's starting to get a little messy, but daca87f should account for this. There's an awkward dance we need to do to try to get the previous icon's media data into Redux. I think I'd like to improve this by having the <SiteIcon /> component query for the media itself if an ID is known but the media object is not yet available. This would likely need to expand on #10392 to enhance the query component and action creators to be able to request a single media by ID. Currently the icon will visually revert back to its previous value only if the legacy media store is tracking it (which may not be the case if there is a large number of media on the site).

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

@aduth The QueryMedia by id is also the exact same thing I need in stats ;) I'll draft a PR with this.

btw this is working well 🚢

And unrelated to this PR, sometimes I notice that the siteicon displayed is reverted to the previous site icon even on successful updates. But I can't not reproduce consistently and it's not specific to this PR only

@youknowriad youknowriad added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 1, 2017
@aduth
Copy link
Contributor Author

aduth commented Feb 1, 2017

And unrelated to this PR, sometimes I notice that the siteicon displayed is reverted to the previous site icon even on successful updates. But I can't not reproduce consistently and it's not specific to this PR only

The most common cause I've seen is when the icon is updated while a /me/sites polling request is already in-flight. Once the request completes, it will have the old site information.

I'm not sure there's a whole lot we can do about this, aside from building some complex mechanism where we decide which attributes have changed since the sites request started and preserve them. This is complicated more by the fact that the polling still lives outside Redux.

Since usually Automatticians are most affected by long /me/sites requests (belonging to hundreds of sites), I don't think it will be a widespread issue, and certainly isn't exclusive to site icon.

@aduth aduth force-pushed the update/site-icon-failed-upload-notice branch from daca87f to a13c177 Compare February 1, 2017 13:32
@aduth aduth merged commit d0f4017 into master Feb 1, 2017
@aduth aduth deleted the update/site-icon-failed-upload-notice branch February 1, 2017 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Settings All other general site settings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants