-
Notifications
You must be signed in to change notification settings - Fork 4k
refactor SB* file uploader into top-level HOC #4809
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
refactor SB* file uploader into top-level HOC #4809
Conversation
1b34449 to
4820132
Compare
2ce692c to
28a120a
Compare
src/reducers/project-state.js
Outdated
| }; | ||
| case LoadingState.LOADING_VM_NEW_DEFAULT: | ||
| return { | ||
| type: START_ERROR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If loading fails (success === false), recover by going back to just showing project as-is. But if we were loading the default project, a failure in loading probably indicates a serious error.
| }); | ||
|
|
||
| test('if canSave is alreatdy true and we show a project with an id, project will NOT be saved', () => { | ||
| test('if canSave is already true and we show a project with an id, project will NOT be saved', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed a typo
| @@ -0,0 +1,241 @@ | |||
| import bindAll from 'lodash.bindall'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to keep as much as possible in this file the same as before. There are very few differences, aside from what was necessary to refactor it into a top-level HOC wrapping GUI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to keep as much as possible in this file the same as before. There are very few differences, aside from what was necessary to refactor it into a top-level HOC wrapping GUI.
Now there are more differences -- as part of making the component dynamic, I reordered functions and added comments.
|
Ready for review; just blocking until after this week's deploy. |
|
@paulkaplan and I talked about this. Some takeaways: Concerns:
Possible alternative approaches:
Next step:
Labeling as blocked, per need for discussion. |
src/lib/sb-file-uploader-hoc.jsx
Outdated
| onStartSelectingFileUpload={this.handleStartSelectingFileUpload} | ||
| {...componentProps} | ||
| /> | ||
| {fileInput} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to create this element dynamically in the handler, rather than mounting it here, to avoid issues with components unmounting.
|
Discussed with @rschamp and @paulkaplan. Current plan:
|
draft of refactor to make custom confirm modal work for upload; need to further edit sb-file-uploader Add support for custom confirm modal to sb-file-uploader Show custom confirm modal when confirming project upload got custom upload refactor of file upload working, and tested failure case cleaned up debug code, make project file upload work simplified logic around canceling file upload removed old sb-file-uploader.jsx; fixed linter errors reverted two components to use old strings, not shared (can do that refactor another time) removed unnecessary confirm container removed stray comment moved, updated sb file uploader tests, related project state tests removed custom modal, to reduce scope of changes sb file uploader test uses intl
dd7b81b to
efed4d3
Compare
|
This PR is ready for review, but tests aren't passing; it's difficult to diagnose because the same tests pass locally. Update: tests are fixed. |
|
OK @rschamp, take a look at the dynamic way sb-file-uploader-hoc is now creating the element. |
rschamp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I found a couple of comments that seemed superfluous.
Also on comments, I personally find the "step #" style comments distracting because they imply a "correct" route for reading the code, so if you encounter a step number out of context you have to read it from beginning to end to understand what it's talking about. To convey the same type of information, I think I'd rather see a flow diagram showing the relationship between the functions at the top. Just my 2¢, not asking you to change it.
Resolves
Big step towards resolving #4762
Resolves #3365
Proposed Changes
sb-file-uploaderto a top-level HOC that wrapsguiproject-stateactionRETURN_TO_SHOWINGReason for Changes
sb-file-uploaderwould be unmounted any time the file menu closed; its existence/mounting should not depend on a menu.sb-file-uploader-hocwould correctly avoid loading the empty content; but it would be stuck in theLOADING_VM_FILE_UPLOADstate. SubmittingRETURN_TO_SHOWINGin this case makes sure we will stay in the right state in that case. (We shouldn't actually be missing the contents of the file to upload in practice, but just in case!)Test Coverage
Added a test and moved over tests to new HOC, but ideally we would test even more.