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

Remove fetch after upload #1848

Merged
merged 7 commits into from
Jun 10, 2020
Merged

Remove fetch after upload #1848

merged 7 commits into from
Jun 10, 2020

Conversation

cvolzke4
Copy link
Contributor

@cvolzke4 cvolzke4 commented May 19, 2020

Summary

Remove fetch after upload. Instead, retrieve the updated resource info from the response of the upload api call.

This solves two problems:

  • As a part of the larger epic to avoid re-renders, prevent the 'uploadMedia' function reference from being re-created when pagingNum changes.
  • fetch after upload uses the current 'pagingNum', which doesn't update the latest media if the gallery is scrolled down the page.

@codecov
Copy link

codecov bot commented May 19, 2020

Codecov Report

Merging #1848 into master will increase coverage by 0.09%.
The diff coverage is 88.88%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1848      +/-   ##
============================================
+ Coverage     66.13%   66.22%   +0.09%     
  Complexity      314      314              
============================================
  Files           651      651              
  Lines         10768    10772       +4     
============================================
+ Hits           7121     7134      +13     
+ Misses         3647     3638       -9     
Impacted Files Coverage Δ Complexity Δ
assets/src/edit-story/app/media/mediaProvider.js 73.17% <ø> (ø) 0.00 <0.00> (ø)
...t-story/app/media/useUploadMedia/useUploadMedia.js 63.26% <88.88%> (+23.26%) 0.00 <0.00> (ø)

@github-actions
Copy link
Contributor

github-actions bot commented May 19, 2020

Size Change: +9 B (0%)

Total Size: 830 kB

Filename Size Change
assets/js/edit-story.js 372 kB +9 B (0%)
ℹ️ View Unchanged
Filename Size Change
assets/css/edit-story.css 269 B 0 B
assets/css/stories-dashboard.css 305 B 0 B
assets/css/web-stories-embed-block.css 501 B 0 B
assets/js/stories-dashboard.js 442 kB 0 B
assets/js/web-stories-embed-block.js 15.7 kB 0 B

compressed-size-action

@spacedmonkey
Copy link
Contributor

The fetch after upload was added for two reasons.

  • Why video poster is generated and uploaded, we needed up force the media library to reload. But I believe this has since been fixed.
  • If images have been uploaded in the WP media dialog, we need to force this to reload.

@cvolzke4 you need to take into account this case in this PR, I believe.

@cvolzke4 cvolzke4 changed the title Remove fetch after upload. Remove fetch after upload May 21, 2020
@cvolzke4 cvolzke4 force-pushed the fix/remove-fetch-after-upload branch from 549e054 to 714f10c Compare May 21, 2020 06:15
@cvolzke4
Copy link
Contributor Author

cvolzke4 commented May 21, 2020

The fetch after upload was added for two reasons.

  • Why video poster is generated and uploaded, we needed up force the media library to reload. But I believe this has since been fixed.
  • If images have been uploaded in the WP media dialog, we need to force this to reload.

@cvolzke4 you need to take into account this case in this PR, I believe.

In these changes, the return value from 'await uploadFile(localFile.file)' is used to update the media directly. I tested this by drag/drop of an image into the media pane, and checked that the attributes are consistent with a server reload.

When using the 'Upload' button to upload into WP, the media pane is reloaded elsewhere, but it's still reloaded as expected.

@cvolzke4 cvolzke4 marked this pull request as ready for review May 21, 2020 06:44
@spacedmonkey
Copy link
Contributor

Screenshot 2020-05-21 at 15 41 22
Whenever I try and upload an image via drag and drop or pasting, I get this error.

Copy link
Contributor

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

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

Even with the new Map fix, this PR didnt work for me. The progress bar on the upload remained forever and was never replaced with uploaded version.

@cvolzke4 cvolzke4 force-pushed the fix/remove-fetch-after-upload branch from 714f10c to af63983 Compare May 21, 2020 14:59
@cvolzke4
Copy link
Contributor Author

cvolzke4 commented May 21, 2020

Screenshot 2020-05-21 at 15 41 22
Whenever I try and upload an image via drag and drop or pasting, I get this error.

My bad, I thought I was working in dart again :)
Fixed.

@spacedmonkey
Copy link
Contributor

How does this PR work when a filter is active?
Case.

  1. User search for cats
  2. User filter media library by video.
  3. User uploads a image called. dog.jpg.

Currently this just add the image to the top of the list, is that correct? I am not sure how we work around this, unless if does the refetch if a filter or search is set overwise, just adds to the top?

@spacedmonkey
Copy link
Contributor

Screenshot 2020-05-21 at 15 52 52
Still seeing the progress bar forever more.

@cvolzke4 cvolzke4 force-pushed the fix/remove-fetch-after-upload branch from af63983 to 0c63ac0 Compare May 21, 2020 15:21
@cvolzke4
Copy link
Contributor Author

Even with the new Map fix, this PR didnt work for me. The progress bar on the upload remained forever and was never replaced with uploaded version.

I was too fast to reply. This has been fixed, please try again.

@spacedmonkey
Copy link
Contributor

Also worthing noting that seems like force pushing here to rewrite commits. Please avoid doing this, as making pulling your change hard as I have to delete the branch and fetch it again.

@cvolzke4
Copy link
Contributor Author

cvolzke4 commented May 21, 2020

How does this PR work when a filter is active?
Case.

  1. User search for cats
  2. User filter media library by video.
  3. User uploads a image called. dog.jpg.

Currently this just add the image to the top of the list, is that correct? I am not sure how we work around this, unless if does the refetch if a filter or search is set overwise, just adds to the top?

It's a good question, this may be a case for re-fetching (or re-apply the search in memory, if that's easy to do). Another way to look at it is as a 'feature', so that the user can see what they just uploaded. It may appear to be a glitch if an upload finishes, and then the image (or images) suddenly disappear.

When a search is active inside the WP uploader, the image isn't displayed, but image details appear on a pane to the right of the list (the last uploaded image if multiple were dropped).

It may not matter very much, as the user can re-enter the search term to re-apply the filter if needed.

This sounds like a question for UX, WDYT?

@cvolzke4
Copy link
Contributor Author

Also worthing noting that seems like force pushing here to rewrite commits. Please avoid doing this, as making pulling your change hard as I have to delete the branch and fetch it again.

Thanks for letting me know. I was under the impression that this only affects a pull if another contributor is making changes to the same branch.

@cvolzke4
Copy link
Contributor Author

cvolzke4 commented May 21, 2020

Still seeing the progress bar forever more

I don't think this is the updated version, try refreshing the browser.

@spacedmonkey
Copy link
Contributor

Changes like this really need a ticket first and a the solution to be discussed before any code is written. If that was the case I would have pointed out the pitfalls and why we had to be the refetch in the first place.

  1. Can we create a ticket so this work can be tracked.
  2. Confirm UX after upload with Sam.
  3. Write a set of tests, that proves this doesn't break anything. A change this wide reaching will likely have breakages.

We need to validate that this doesn't break the 5 kinds of upload

  • Upload via drag into media library.
  • Upload via drag into canvas.
  • Upload via paste ( only works on Mac OS )
  • Upload via WP media modal.
  • Upload via poster generation.

@cvolzke4
Copy link
Contributor Author

cvolzke4 commented May 21, 2020

Changes like this really need a ticket first and a the solution to be discussed before any code is written. If that was the case I would have pointed out the pitfalls and why we had to be the refetch in the first place.

  1. Can we create a ticket so this work can be tracked.
  2. Confirm UX after upload with Sam.
  3. Write a set of tests, that proves this doesn't break anything. A change this wide reaching will likely have breakages.

We need to validate that this doesn't break the 5 kinds of upload

  • Upload via drag into media library.
  • Upload via drag into canvas.
  • Upload via paste ( only works on Mac OS )
  • Upload via WP media modal.
  • Upload via poster generation.

Thanks Jonny.

This change relates to the performance ticket (which I've linked now, I should have done this earlier). I'll raise another ticket Monday to address the specific change. I had started this PR as a way to communicate this in a comment elsewhere, and then finished the implementation since it wasn't very much work and I could receive feedback on the approach, which you have given (thank you). I'll write some new tests once the behavior has been confirmed with Sam.

Please bear with me while we find our feet working with github, linking issues, getting feedback etc, as you can understand it's a very different environment to what we are used to.

I've just tested the upload types that you mentioned, including upload of multiple files.

There's a few other issues that I noticed while testing:

  • fetchMedia depends on pagingNum, which causes re-renders during scrolling (the issue I'm trying to fix).
  • Uploading a video doesn't focus the 'Video' tab, but it probably should.
  • fetchMedia uses pagingNum to load the last page of results, and prepends them to the list of media. This change would also fix that.
  • Pasting an mp4 video into the canvas pastes the filename, but not the content.
  • Uploading a video into the canvas froze chrome (appears to be a once off, I can no longer reproduce it).

fileUploaded,
])
);
setMedia({
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like reshuffling the whole array of media elements is a lot. I think we already have updateMediaElement. Can we use it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As it is today, the reducer for updateMediaElement is also O(n) for each media element. But we should be able to refactor it to take more than one media element at a time.

Here is an issue to address this: #2072

...media,
],
});
updatedMedia = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to have instead a targeted method prependMedia and resolve array logic and stuff on the reducer level?

Copy link
Contributor Author

@cvolzke4 cvolzke4 May 28, 2020

Choose a reason for hiding this comment

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

That would be a better way, this is an existing issue that can be addressed in a separate PR. I've raised an issue: #2072

@spacedmonkey
Copy link
Contributor

Honestly, there are still a lot of question regarding the UX of the media library about expected behavior. Like

What you are scrolled down say 200th item in the media list, does the preview appear at the top of the list?
Should a preview should for a video when image has been filtered.
What the preview upload appear at all if a search is active?
Are the any cases that where the filters and search need to be reset?

I don't think that we can work with the idea that current UX is correct as most of it was written before any of the current designs were implemented.

Until UX is confirmed, is hard to know if this PR is doing that correct behavior.

@cvolzke4 cvolzke4 requested a review from swissspidy as a code owner June 1, 2020 07:13
@cvolzke4 cvolzke4 requested a review from dvoytenko June 2, 2020 01:42
@dvoytenko
Copy link
Contributor

@cvolzke4 trying to catch up on this. is this ready to be rereviewed? I'm generally LG with changes, but there's a longish threads with other reviewers...

@cvolzke4
Copy link
Contributor Author

cvolzke4 commented Jun 3, 2020

@cvolzke4 trying to catch up on this. is this ready to be rereviewed? I'm generally LG with changes, but there's a longish threads with other reviewers...

Thanks Dima, I was going to ping you about this today :)
UX has approved this approach (see #1971), so this PR is ready for review.

@swissspidy swissspidy added Group: Media Type: Enhancement New feature or improvement of an existing feature labels Jun 5, 2020
Copy link
Contributor

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

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

LGTM

@cvolzke4 cvolzke4 merged commit 62f9c8d into master Jun 10, 2020
@cvolzke4 cvolzke4 deleted the fix/remove-fetch-after-upload branch June 10, 2020 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Group: Media Type: Enhancement New feature or improvement of an existing feature
Projects
None yet
5 participants