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

don't cancel all files when clicking "done" #4771

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions packages/@uppy/core/src/Uppy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import {
import packageJson from '../package.json'
import locale from './locale.js'


const getDefaultUploadState = () => ({
totalProgress: 0,
allowNewUpload: true,
error: null,
recoveredState: null,
});

/**
* Uppy Core module.
* Manages plugins, state updates, acts as an event bus,
Expand Down Expand Up @@ -91,19 +99,17 @@ class Uppy {

this.store = this.opts.store
this.setState({
...getDefaultUploadState(),
plugins: {},
files: {},
currentUploads: {},
allowNewUpload: true,
capabilities: {
uploadProgress: supportsUploadProgress(),
individualCancellation: true,
resumableUploads: false,
},
totalProgress: 0,
meta: { ...this.opts.meta },
info: [],
recoveredState: null,
})

this.#restricter = new Restricter(() => this.opts, this.i18n)
Expand Down Expand Up @@ -230,6 +236,7 @@ class Uppy {
this.setState() // so that UI re-renders with new options
}

// todo next major: rename to something better? (it doesn't just reset progress)
resetProgress () {
const defaultProgress = {
percentage: 0,
Expand All @@ -249,17 +256,16 @@ class Uppy {
}
})

this.setState({
files: updatedFiles,
totalProgress: 0,
allowNewUpload: true,
error: null,
recoveredState: null,
})
this.setState({ files: updatedFiles, ...getDefaultUploadState() })

this.emit('reset-progress')
}

/** @protected */
resetUploadState() {
mifi marked this conversation as resolved.
Show resolved Hide resolved
this.setState({ ...getDefaultUploadState(), files: {} })
}

addPreProcessor (fn) {
this.#preProcessors.add(fn)
}
Expand Down Expand Up @@ -854,11 +860,8 @@ class Uppy {
this.removeFiles(fileIDs, 'cancel-all')
}

this.setState({
totalProgress: 0,
error: null,
recoveredState: null,
})
this.setState(getDefaultUploadState())
// todo should we call this.emit('reset-progress') like we do for resetProgress?
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/@uppy/core/src/Uppy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ describe('src/Core', () => {
capabilities: { individualCancellation: true, uploadProgress: true, resumableUploads: false },
files: {},
currentUploads: {},
error: null,
allowNewUpload: true,
foo: 'baar',
info: [],
Expand All @@ -175,6 +176,7 @@ describe('src/Core', () => {
capabilities: { individualCancellation: true, uploadProgress: true, resumableUploads: false },
files: {},
currentUploads: {},
error: null,
allowNewUpload: true,
foo: 'bar',
info: [],
Expand All @@ -189,6 +191,7 @@ describe('src/Core', () => {
capabilities: { individualCancellation: true, uploadProgress: true, resumableUploads: false },
files: {},
currentUploads: {},
error: null,
allowNewUpload: true,
foo: 'baar',
info: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/dashboard/src/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class Dashboard extends UIPlugin {
hidePauseResumeButton: false,
hideProgressAfterFinish: false,
doneButtonHandler: () => {
this.uppy.cancelAll()
this.uppy.resetUploadState()
mifi marked this conversation as resolved.
Show resolved Hide resolved
this.requestCloseModal()
},
note: null,
Expand Down