Repository navigation
feat(uploads): select UploadInputV4 behind FILE_UPLOAD_USE_V4 #1141
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
Open
caseylocker
wants to merge
7
commits into
master
Choose a base branch
from
feature/upload-input-v4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b6b7781
fix: adjust for updated column counts, removed outdated test ids, and…
ako3131 0c43c89
chore(deps): update uicore to 5.0.75
smarcet ba9a0fe
feat(uploads): select UploadInputV4 behind FILE_UPLOAD_USE_V4
caseylocker ada8a04
fix(uploads): correct the FILE_UPLOAD_USE_V4 rollback comment
caseylocker ff0408d
feat(uploads): route the badge feature image upload through FileUploa…
caseylocker eb565e4
fix(uploads): clear the saving state when a new company cancels a log…
caseylocker f4749f1
fix(uploads): load the UploadInputV4 stylesheet
caseylocker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import React from "react"; | ||
| import { render } from "@testing-library/react"; | ||
| import FileUploadInput from "../file-upload-input"; | ||
|
|
||
| const renderedProps = {}; | ||
|
|
||
| jest.mock( | ||
| "openstack-uicore-foundation/lib/components/inputs/upload-input-v3", | ||
| () => ({ | ||
| __esModule: true, | ||
| default: (props) => { | ||
| renderedProps.v3 = props; | ||
| return null; | ||
| } | ||
| }) | ||
| ); | ||
|
|
||
| jest.mock( | ||
| "openstack-uicore-foundation/lib/components/inputs/upload-input-v4", | ||
| () => ({ | ||
| __esModule: true, | ||
| default: (props) => { | ||
| renderedProps.v4 = props; | ||
| return null; | ||
| } | ||
| }) | ||
| ); | ||
|
|
||
| const API_BASE = "https://file-upload-api.test"; | ||
|
|
||
| describe("FileUploadInput", () => { | ||
| const onUploadComplete = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| delete renderedProps.v3; | ||
| delete renderedProps.v4; | ||
| window.FILE_UPLOAD_API_BASE_URL = API_BASE; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| delete window.FILE_UPLOAD_API_BASE_URL; | ||
| delete window.FILE_UPLOAD_USE_V4; | ||
| }); | ||
|
|
||
| const renderInput = () => | ||
| render( | ||
| <FileUploadInput | ||
| id="slide" | ||
| value={[]} | ||
| onUploadComplete={onUploadComplete} | ||
| parallelChunkUploads | ||
| /> | ||
| ); | ||
|
|
||
| it("uploads direct to storage through V4 when the flag is 'true'", () => { | ||
| window.FILE_UPLOAD_USE_V4 = "true"; | ||
|
|
||
| renderInput(); | ||
|
|
||
| expect(renderedProps.v3).toBeUndefined(); | ||
| expect(renderedProps.v4.postUrl).toBe(`${API_BASE}/api/v1/files`); | ||
| expect(renderedProps.v4.onUploadComplete).toBe(onUploadComplete); | ||
| expect(renderedProps.v4).not.toHaveProperty("djsConfig"); | ||
| expect(renderedProps.v4).not.toHaveProperty("parallelChunkUploads"); | ||
| }); | ||
|
|
||
| it.each([undefined, "false", "1"])( | ||
| "keeps the chunked V3 upload when the flag is %p", | ||
| (flag) => { | ||
| if (flag !== undefined) window.FILE_UPLOAD_USE_V4 = flag; | ||
|
|
||
| renderInput(); | ||
|
|
||
| expect(renderedProps.v4).toBeUndefined(); | ||
| expect(renderedProps.v3.postUrl).toBe(`${API_BASE}/api/v1/files/upload`); | ||
| expect(renderedProps.v3.djsConfig).toEqual({ withCredentials: true }); | ||
| expect(renderedProps.v3.parallelChunkUploads).toBe(true); | ||
| expect(renderedProps.v3.onUploadComplete).toBe(onUploadComplete); | ||
| } | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@caseylocker Cancelling a logo upload on a new company (Add company page) leaves Save permanently disabled under V4, and uicore#385 does not fix this case.
onUploadStartsetsisSavingtotrue(line 378). In V3, cancelling an in-flight upload resets it by accident:removeFilecallscancelUpload, which emitscanceled.canceledhandler re-emits it aserror(dropzone/dist/dropzone.js:937-938).DropzoneJSpasses everyerrortoprops.onError(dropzone/index.js:692-698), which here issetIsSaving(false).removedfilethen callsonRemove.So V3 calls both
onErrorandonRemoveon a cancel.V4 calls neither. OpenStackweb/openstack-uicore-foundation#385 adds only
onRemovetohandleDeleteUploading, notonError. That is the right call, since a cancel is not an error. ButhandleLogoRemove(line 94) resetsisSavingonly wheninitialEntity?.idis set:With id 0,
isSavingstaystrue. Then Save is disabled (edit-company-page.js:169) andonSubmitreturns early (if (isSaving) return), so the user has to reload. An existing company recovers through theremoveLogo.finally, so the PR description's "Company form (existing company)" bullet doesn't cover this case. With the flag on and #385 pinned, the Add company form will still get stuck.Repro (after #385 is pinned): set
FILE_UPLOAD_USE_V4=true, open Companies → Add new, start a logo upload, delete the row while it is uploading, then try to save.Suggested fix: reset
isSavingon the no-id branch so the form doesn't depend on the upload input callingonErroron a cancel. That matches theelsebranch ofhandleLogoUploadCompleteabove andhandleRemoveImageinbadge-feature-type-form.js:Please add a test for it too: with the flag set to
"true", a new company cancels an in-flight logo upload and Save is enabled again.Uh oh!
There was an error while loading. Please reload this page.
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.
Confirmed, and fixed in 55c4e92. With id 0,
handleLogoRemovenever resetisSaving, and under V4 nothing else does, since OpenStackweb/openstack-uicore-foundation#385 addsonRemoveon cancel but notonError.I took your
elsebranch as written. It matches theelseinhandleLogoUploadComplete, and the form no longer depends on the input reporting a cancel as an error.Test added in
company-form.test.js: with the flag set to"true", a new company starts a logo upload, cancels it, and the saving state clears without calling the delete API. The upload input is mocked in that file, so the test drives the V4 callback contract (onUploadStart, thenonRemove, noonError) and not Uppy itself. It fails with theelsebranch removed.I also added the new-company case to the PR description under gate 2.