Skip to content

Commit

Permalink
change cancel logic
Browse files Browse the repository at this point in the history
to make canceling assemblies optional
possibly fixes #3547
  • Loading branch information
mifi committed Mar 16, 2022
1 parent ca15897 commit 1775410
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
18 changes: 15 additions & 3 deletions packages/@uppy/core/src/Uppy.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ class Uppy {
return this.#runUpload(uploadID)
}

cancelAll () {
cancelAllExceptAssemblies () {
this.emit('cancel-all')

const { files } = this.getState()
Expand All @@ -824,6 +824,16 @@ class Uppy {
})
}

// https://github.com/transloadit/uppy/issues/3547
cancelAllAssemblies () {
this.emit('cancel-all-assemblies')
}

cancelAll () {
this.cancelAllExceptAssemblies()
this.cancelAllAssemblies()
}

retryUpload (fileID) {
this.setFileState(fileID, {
error: null,
Expand All @@ -838,6 +848,7 @@ class Uppy {
return this.#runUpload(uploadID)
}

// todo what is the point of the reset method when we have cancelAll or vice versa?
reset () {
this.cancelAll()
}
Expand Down Expand Up @@ -1234,10 +1245,11 @@ class Uppy {
/**
* Uninstall all plugins and close down this Uppy instance.
*/
close () {
close ({ cancelAssemblies = true } = {}) {
this.log(`Closing Uppy instance ${this.opts.id}: removing all files and uninstalling plugins`)

this.reset()
this.cancelAllExceptAssemblies()
if (cancelAssemblies) this.cancelAllAssemblies()

this.#storeUnsubscribe()

Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/react/src/useUppy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function useUppy (factory) {

useEffect(() => {
return () => {
uppy.current.close()
uppy.current.close({ cancelAssemblies: false })
}
}, [])

Expand Down
10 changes: 4 additions & 6 deletions website/src/docs/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,6 @@ Retry an upload (after an error, for example).

Retry all uploads (after an error, for example).

### `uppy.cancelAll()`

Cancel all uploads, reset progress and remove all files.

### `uppy.setState(patch)`

Update Uppy’s internal state. Usually, this method is called internally, but in some cases it might be useful to alter something directly, especially when implementing your own plugins.
Expand Down Expand Up @@ -673,14 +669,16 @@ uppy.getPlugin('Dashboard').setOptions({
})
```

### `uppy.reset()`
### `uppy.reset()` (alias `uppy.cancelAll()`)

Stop all uploads in progress and clear file selection, set progress to 0. More or less, it returns things to the way they were before any user input.

### `uppy.close()`
### `uppy.close({ cancelAssemblies })`

Uninstall all plugins and close down this Uppy instance. Also runs `uppy.reset()` before uninstalling.

* `cancelAllAssemblies`: Option whether to also cancel all running Transloadit assemblies (default `true`)

### `uppy.logout()`

Calls `provider.logout()` on each remote provider plugin (Google Drive, Instagram, etc). Useful, for example, after your users log out of their account in your app — this will clean things up with Uppy cloud providers as well, for extra security.
Expand Down

0 comments on commit 1775410

Please sign in to comment.