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

PTV-1886 staging area limit file size #3312

Open
wants to merge 30 commits into
base: develop
Choose a base branch
from

Conversation

eapearson
Copy link
Contributor

@eapearson eapearson commented Jul 10, 2023

Description of PR purpose/changes

The primary motivation for this set of changes is to ensure that the staging area widget applies a file size limit of 5GB to user uploads. This is achieved by setting that value in the Narrative config template, and propagating that value to the dropzone widget. This code was in place, although the max file size value was inaccurate.

In addition, there are changes around ensuring that this and related errors are properly displayed. And around this are changes to ensure that the staging upload widget communicates this file size limit to the user.

One related set of fixes applies to the usage of decimal and binary measurements of file size. In several cases these units were mixed and up and communicating incorrect information to the user. The important distinction is that users will be aware of decimal file size (e.g. MB, GB) as that is what is reported by most operating systems and tools that rely upon them. On the other hand, the dropzone widget and nginx work in binary file sizes (e.g. MiB, GiB). So there is code to convert back and forth and ensure that users see file sizes in decimal. Generally all code uses file size measurements in bytes.

A document attached shows the before and after ui states.

Jira Ticket / Issue

Related Jira ticket: https://kbase-jira.atlassian.net/browse/DATAUP-X

  • Added the Jira Ticket to the title of the PR (e.g. DATAUP-69 Adds a PR template)

Testing Instructions

  • Details for how to test the PR:
  • Tests pass locally and in GitHub Actions
  • Changes available by spinning up a local narrative and navigating to X to see Y

Dev Checklist:

  • My code follows the guidelines at https://sites.google.com/lbl.gov/trussresources/home?authuser=0
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • (JavaScript) I have run Prettier and ESLint on changed code manually or with a git precommit hook
  • (Python) I have run Black and Flake8 on changed Python code manually or with a git precommit hook
  • Any dependent changes have been merged and published in downstream modules

Updating Version and Release Notes (if applicable)

eapearson added 15 commits June 20, 2023 09:44
… icon, add hover effect for the button (affordance), in detail show info tab by default, remove unnecessary bluebird, rename import that conflicts with built-ins, minor formatting improvements [PTV-1886]
Fixes case of 0-length file, uses Alert rather than showing warning in same style as file snippet, handle null as head/tail snippet as well as the bespoke text value "not text flie" [PTV-1886]
…n, set maxFileSize for dropzone widget, support decimal and binary file sizes explicitly (and in appropriate places), handle 413 (request entity too big) errors, generally improve dropzone layout and styling, display max file size in dropzone, fix globus link handling and use a dialog before opening a new window to catch and display errors [PTV-1886]
… it internally, especially when debugging tests! [PTV-1886]
note - need another pass at tests to cover changes during PR-preparation
some test cases added, some unused code removed, some code simplified
@codecov
Copy link

codecov bot commented Jul 10, 2023

Codecov Report

Merging #3312 (e45e547) into develop (3bccc58) will increase coverage by 0.04%.
The diff coverage is 79.05%.

❗ Current head e45e547 differs from pull request most recent head bb4f7e0. Consider uploading reports for the commit bb4f7e0 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3312      +/-   ##
===========================================
+ Coverage    29.22%   29.27%   +0.04%     
===========================================
  Files          495      495              
  Lines        50482    50545      +63     
===========================================
+ Hits         14755    14798      +43     
- Misses       35727    35747      +20     
Impacted Files Coverage Δ
...ets/narrative_core/kbaseNarrativeStagingDataTab.js 93.18% <ø> (ø)
...widgets/narrative_core/upload/stagingAreaViewer.js 73.74% <25.00%> (-1.19%) ⬇️
.../widgets/narrative_core/upload/fileUploadWidget.js 84.45% <83.20%> (+7.53%) ⬆️
...-extension/static/kbase/js/util/bootstrapDialog.js 97.43% <100.00%> (+0.06%) ⬆️
...ion/static/kbase/js/widgets/common/AlertMessage.js 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38873c4...bb4f7e0. Read the comment docs.

@eapearson
Copy link
Contributor Author

eapearson commented Jul 10, 2023

Before and after user interface:

PTV-1886_ Before and After.pdf

@eapearson eapearson requested a review from briehl July 10, 2023 23:28
@eapearson
Copy link
Contributor Author

@Bill @ialarmedalien resolved merge conflicts, merged the repaired tox.ini into .flake8, some code quality fixes to make the bots happier. Don't know why the integration tests aren't passing. I spot checked one of the narratives involved for a failing public data test, and it looks fine. (Such integration tests will occasionally fail due to changes in ref data since they use live CI services.)

Copy link
Member

@briehl briehl left a comment

Choose a reason for hiding this comment

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

There's a lot happening here, but this looks good.
Got a couple minor changes and suggestions for you.


For a custom 413 response, first define a location within the server block handling the `staging_server`.

```nginx
Copy link
Member

Choose a reason for hiding this comment

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

Is this set up in the staging service? I know you were making changes there, too, with @bio-boris .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will come from changes to the nginx proxy. I've included the instructions, at least for what worked for me.

I tested this out by setting the kbase-ui proxy up with a low limit to trigger the 413 for arbitrary file sizes.

Yes, there is a set of changes coming for the staging service too, but the Narrative changes (other than the handling of a custom 413, which is auto-detected) don't depend on them. However, for anyone sending files between 4.4 and 5GB, the current staging service will crash. The upcoming changes address this.

@@ -78,8 +79,8 @@

.kb-dropzone {
border: 2px dashed use_color('mid-blue') !important;
margin-bottom: 5px;
max-height: 150px;
// margin-bottom: 5px;
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 just delete these. I don't think they need to come back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger that.

@@ -91,14 +92,23 @@
.dz-message {
color: rgb(0 0 0);
font: normal 400 24px/28px $typeface-page-text;
margin: 2em 4.5em;
// margin: 2em 4.5em;
Copy link
Member

Choose a reason for hiding this comment

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

Delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, ye ole "not sure this will work, keep an eye on it and remove later" that doesn't get removed.
Gone, and also rearranging a bit to put styles where they should be, and adding some of those "this is the full path of this style" comments. They do help clarify, as nested styles can be painful to follow...

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the nested styles are hard, having the full path as a comment is very helpful!

}

// .kb-dropzone__message--upload
&__message--upload {
font-family: $typeface-page-text;
font-weight: 700;
}
}

&.dropzone.dz-clickable button {
Copy link
Member

Choose a reason for hiding this comment

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

👍

// Bootstrap overrides

// necessary?
.progress-bar {
Copy link
Member

Choose a reason for hiding this comment

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

It might not be necessary at this point, but Bootstrap's progressbar is occasionally an oddball, and was annoying to work against Dropzone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bootstrap already sets the width for .progress-bar to 0, and I don't see anywhere in the KBase codebase that sets this class otherwise that would need overriding.

Also, in the widget code the width is set via direct style to '0' on reset, but should probably set it to '' to remove the style and let the class style take over.

Anyway, it is working, so I don't see any reason to change anything here, other than the fact that these files are being revised and who knows when the next opportunity will come.

Comment on lines +71 to +74
// Realistically, this should poll until the condition is met, or
// timeout. Reason being that in real usage (or if using a real service mock),
// the call that generates the error may take an indeterminate amount of time,
// and certainly will not be on the next tick of the event loop.
Copy link
Member

Choose a reason for hiding this comment

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

There's some tooling in testUtil that might be helpful to get the behavior you mention. The waitForElementState function might make the most sense here. Then you can make it an async test, await on that, and it'll fail if it times out.

Copy link
Member

Choose a reason for hiding this comment

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

The existing file upload widget tests don't use that, I guess, since it was made later. If this works and is stable for now, that's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it works, so I don't see a reason to just change it.
It was more of a note to preserve the fact that it only works because it is using a specific style of mock service. It would fail, e.g., in an integration test, or a mock service which is either a true http server or includes a modest delay to simulate a network call.
I had just been through evaluating the implementation with different browsers. If memory serves, I found that some browsers wait for a good long while before reporting back the 413, others immediately, but in all cases it is a network call to the service occurs first, which is certainly longer in duration than a 0ms timeout.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, that sounds reasonable.

@@ -0,0 +1,107 @@
define(['jquery', 'util/bootstrapDialog'], ($, Dialog) => {
Copy link
Member

Choose a reason for hiding this comment

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

🎉

@@ -1,14 +1,23 @@
<form class="kb-dropzone dropzone" style="min-height:200px">
<form class="kb-dropzone dropzone"
style="min-height:100px; display: flex; flex-direction: column; justify-content: center;">
Copy link
Member

Choose a reason for hiding this comment

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

Can you move the inline styles to SCSS?

@eapearson
Copy link
Contributor Author

Thanks for looking at it, @briehl, working on it.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
19.2% 19.2% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@briehl
Copy link
Member

briehl commented Aug 1, 2023

Let me know when this is ready for re-review, thanks!

@briehl briehl mentioned this pull request Oct 3, 2024
14 tasks
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.

2 participants