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

[enhancement] upload progress fixes #17

Merged
merged 11 commits into from
Mar 30, 2020
Merged

[enhancement] upload progress fixes #17

merged 11 commits into from
Mar 30, 2020

Conversation

BryonLewis
Copy link
Collaborator

Changes

  • Added default FPS to 10 when uploading files
  • Added in default upload Folder name, based on the first file in the list and removing the extension
  • Changed 'Upload' to 'Start Upload', multiple times I got confused and clicked 'Upload' thinking it would allow me to add more files
  • Implemented the fileUploader mixin from Girder Web Components
  • Image counter now decreases as the images are uploading. That was the original intention of how this component was designed, it didn't work properly because of the batch uploading (instantly tried uploading 500 items).
  • If the upload is a single file, it will display the file size
  • If the upload is a list of videos it will display the number, then when it starts uploading it will display the current amount of data uploaded and the total aggregate size of the videos
  • Restructured the uploading process to allow adding additional items while uploading. (Let me know if we want something better than a while->await loop for this)
  • Added in some error message handling based on GWC. Standard mixing error handling plus handling response errors when creating the folder to uploading items to.
  • image
  • image

@subdavis subdavis added the Type: Feature Request New feature or request label Mar 26, 2020
@subdavis subdavis changed the title Upload progress Fixes [enhancement] upload progress fixes Mar 26, 2020
Copy link
Contributor

@subdavis subdavis left a comment

Choose a reason for hiding this comment

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

Minor nits.

item => item.status !== "done" && item.status !== "error"
).length;
},
// Takes the pending upload and returns the # of images or size of the file
Copy link
Contributor

Choose a reason for hiding this comment

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

For comments like this, it may make sense to just write a full jsdoc comment. You've gone to the trouble of documenting this functions's signature in English, so I might as well get some type hints out of it.

},
// Takes the pending upload and returns the # of images or size of the file
computeUploadProgress(pendingUpload) {
// formatSize, totalProgress and totalSize are located in the fileUploader and sizeFormatter mixin
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// formatSize, totalProgress and totalSize are located in the fileUploader and sizeFormatter mixin
const { formatSize, totalProgress, totalSize } = this; // use methods and properties from mixins

IMO this line is better because the code tells me what is being used, and the comment only needs to tell me where it came from. I'm not going to remember to update this comment if the method changes.

this.$emit("update:uploading", false);
console.log(uploaded);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove console log.

// Upload Mixin function to start uploading
await this.start({
dest: folder,
postUpload: postUpload
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
postUpload: postUpload
postUpload,

{{ pendingUpload.files.length }} images
<v-list-item-subtitle>
{{ computeUploadProgress(pendingUpload) }}
<!-- errorMessage is provided by the fileUploader mixin -->
Copy link
Contributor

Choose a reason for hiding this comment

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

While I appreciate this, I think it's a lots cause. I've never seen anyone comment every time they use a mixin feature. Is this considered a best practice, or just something you like to do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's something I do just for ease of use and readability if I ever have to look at it again. Is there an extension for VS code or some setup that will goTo a function that is imported as a mixin from a node_module. If I came at this with standard VS code setup and ctrl+shft+F for the function name I wouldn't be able to find it without turning on searching inside of node_modules. Then if I do something like 'errorMessage' is found 400+ times. This is the part where I really wish there was some namespacing for mixins, or even a naming standard mixinErrorMessage. I can obviously take some of them out.

this.$emit("update:uploading", false);
this.$emit("uploaded", uploaded);
},
async uploadPending(pendingUpload, uploaded) {
var { name, files, fps } = pendingUpload;
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
var { name, files, fps } = pendingUpload;
let { name, files, fps } = pendingUpload;

var { name, files, fps } = pendingUpload;
fps = parseInt(fps);
pendingUpload.uploading = true;
var { data: folder } = await this.girderRest
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
var { data: folder } = await this.girderRest
let { data: folder } = await this.girderRest

const postUpload = data => {
uploaded.push({
folder,
results: data.results,
Copy link
Member

Choose a reason for hiding this comment

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

Should there be a check here? When running locally, everytime I try to upload, it hands with an error saying:

TypeError: Cannot read property 'results' of undefined

Does this happen for anyone else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not getting that error, but there should be a check there anyways. Was your girder web components updated in the process?

Copy link
Member

Choose a reason for hiding this comment

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

I did not upgrade GWC. I'll upgrade and report back with the results.

Comment on lines 133 to 146
.catch(error => {
if (
error.response &&
error.response.data &&
error.response.data.message
) {
this.errorMessage = error.response.data.message;
} else {
this.errorMessage = error;
}
pendingUpload.uploading = false;
// Return empty object for the folder destructuring
return { data: null };
});
Copy link
Member

Choose a reason for hiding this comment

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

Since you're already awaitng the girderRest call, can't this can be handled with a try-catch around the await? This would make it easier to read as well as more standard for using await.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can do that, but I think it prevents the assignment destructuring of the returned value from the await.
let { data: folder } = await this.girderRest.post(......
The options I can think of are either to wrap the entire data and where it used inside the try statement (including other awaits), hoist the variable declaration with a 'var' (don't want to do) or declare the variable outside of the try block and then grab the data afterwards using assignment without declaration syntax (essentially wrapping the entire await in ())
let folder; try { ({ data: folder } = await this.girderRest.post(.......)
let me know if you have another method that I might not be thinking of.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not messing with the code formatted for github, here is what I'm talking about
image

Copy link
Member

Choose a reason for hiding this comment

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

In response to that code snippet, I think that'd be fine, or at least better than the alternative. If you didn't want to use the weird destructuring assignment syntax, you could also do this:

let folder;
try {
  const { data } = await this.girderRest.post(
  ...
  );
  folder = data;
}

And in the catch block you'd probably do something like

catch {
  ...
  folder = null;
}

Comment on lines 42 to 46
/**
* Takes the pending upload and returns the # of images or size of the file based on the type and state
* @param {Object} pendingUpload - contains , status, type
* size, and list of files to upload.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* Takes the pending upload and returns the # of images or size of the file based on the type and state
* @param {Object} pendingUpload - contains , status, type
* size, and list of files to upload.
*/
/**
* @param {{ type: string, size: number, files: Array, uploading: boolean }} pendingUpload
* @returns {number} # of images or size of file depending on type and state
*/

I noticed that your comment was out of date already. pendingUpload.status was unused and pendingUpload.uploading wasn't mentioned.

Copy link
Contributor

@subdavis subdavis left a comment

Choose a reason for hiding this comment

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

One final comment, otherwise lgtm.

@subdavis subdavis requested a review from jjnesbitt March 30, 2020 14:17
@@ -41,7 +41,8 @@ export default {
},
/**
* Takes the pending upload and returns the # of images or size of the file based on the type and state
* @param {Object} pendingUpload - contains , status, type
* @param {{ type: string, size: number, files: Array, uploading: boolean }} pendingUpload
* @returns {number} # of images or size of file depending on type and state
* size, and list of files to upload.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Line 46 should be removed.
line 43 is duplicate information and should be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry, not thinking properly this morning.

@BryonLewis BryonLewis merged commit 435fd70 into master Mar 30, 2020
@BryonLewis BryonLewis deleted the upload-progress branch March 30, 2020 15:50
@BryonLewis BryonLewis linked an issue Mar 31, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upload progress reporting is insufficient.
3 participants