Skip to content

Commit

Permalink
@uppy/core: close->destroy, clearUploadedFiles->clear (#5154)
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon committed May 8, 2024
1 parent 1634263 commit 12e7ca5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
4 changes: 2 additions & 2 deletions e2e/cypress/integration/dashboard-ui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('dashboard-ui', () => {
cy.get('.uppy-Dashboard-AddFiles').as('drop-target')
})

it('should not throw when calling uppy.close()', () => {
it('should not throw when calling uppy.destroy()', () => {
cy.get('@file-input').selectFile(
[
'cypress/fixtures/images/cat.jpg',
Expand All @@ -15,7 +15,7 @@ describe('dashboard-ui', () => {
)

cy.window().then(({ uppy }) => {
expect(uppy.close()).to.not.throw
expect(uppy.destroy()).to.not.throw
})
})

Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/core/src/UIPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class UIPlugin<
// API for plugins that require a synchronous rerender.
this.#updateUI = debounce((state) => {
// plugin could be removed, but this.rerender is debounced below,
// so it could still be called even after uppy.removePlugin or uppy.close
// so it could still be called even after uppy.removePlugin or uppy.destroy
// hence the check
if (!this.uppy.getPlugin(this.id)) return
render(this.render(state), uppyRootElement)
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/core/src/Uppy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ describe('src/Core', () => {
core.on('cancel-all', coreCancelEventMock)
core.on('state-update', coreStateUpdateEventMock)

core.close()
core.destroy()

expect(coreCancelEventMock).toHaveBeenCalledWith(
{ reason: 'user' },
Expand Down Expand Up @@ -1808,7 +1808,7 @@ describe('src/Core', () => {

await uploadPromise

core.close()
core.destroy()
})

it('should estimate progress for unsized files', () => {
Expand Down Expand Up @@ -1852,7 +1852,7 @@ describe('src/Core', () => {
// foo.jpg at 35%, bar.jpg at 0%
expect(core.getState().totalProgress).toBe(18)

core.close()
core.destroy()
})

it('should calculate the total progress of all file uploads', () => {
Expand Down
11 changes: 2 additions & 9 deletions packages/@uppy/core/src/Uppy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ export class Uppy<M extends Meta, B extends Body> {
this.setState(undefined) // so that UI re-renders with new options
}

// todo next major: remove
resetProgress(): void {
const defaultProgress: Omit<FileProgressNotStarted, 'bytesTotal'> = {
percentage: 0,
Expand All @@ -597,9 +596,7 @@ export class Uppy<M extends Meta, B extends Body> {
this.emit('reset-progress')
}

// @todo next major: rename to `clear()`, make it also cancel ongoing uploads
// or throw and say you need to cancel manually
clearUploadedFiles(): void {
clear(): void {
this.setState({ ...defaultUploadState, files: {} })
}

Expand Down Expand Up @@ -1799,11 +1796,7 @@ export class Uppy<M extends Meta, B extends Body> {
/**
* Uninstall all plugins and close down this Uppy instance.
*/
// @todo next major: rename to `destroy`.
// Cancel local uploads, cancel remote uploads, DON'T cancel assemblies
// document that if you do want to cancel assemblies, you need to call smth manually.
// Potentially remove reason, as it’s confusing, just come up with a default behaviour.
close({ reason }: { reason?: FileRemoveReason } | undefined = {}): void {
destroy({ reason }: { reason?: FileRemoveReason } | undefined = {}): void {
this.log(
`Closing Uppy instance ${this.opts.id}: removing all files and uninstalling plugins`,
)
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/dashboard/src/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<

// Dynamic default options:
this.opts.doneButtonHandler ??= () => {
this.uppy.clearUploadedFiles()
this.uppy.clear()
this.requestCloseModal()
}
this.opts.onRequestCloseModal ??= () => this.closeModal()
Expand Down
14 changes: 7 additions & 7 deletions packages/@uppy/dashboard/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Dashboard', () => {
core.use(DashboardPlugin, { inline: false })
}).not.toThrow()

core.close()
core.destroy()
})

it('works without any remote provider plugins', () => {
Expand All @@ -48,7 +48,7 @@ describe('Dashboard', () => {
})
}).not.toThrow()

core.close()
core.destroy()
})

it('works when targeting remote provider plugins using `target`', () => {
Expand All @@ -64,7 +64,7 @@ describe('Dashboard', () => {
})
}).not.toThrow()

core.close()
core.destroy()
})

it('works when passing plugins in `plugins` array', () => {
Expand All @@ -79,7 +79,7 @@ describe('Dashboard', () => {
})
}).not.toThrow()

core.close()
core.destroy()
})

it('should automatically add plugins which have no target', () => {
Expand All @@ -98,7 +98,7 @@ describe('Dashboard', () => {
true,
)

core.close()
core.destroy()
})

it('should not automatically add plugins which have a non-Dashboard target', () => {
Expand All @@ -118,7 +118,7 @@ describe('Dashboard', () => {
false,
)

core.close()
core.destroy()
})

it('should change options on the fly', () => {
Expand Down Expand Up @@ -168,6 +168,6 @@ describe('Dashboard', () => {
})
}).not.toThrow()

core.close()
core.destroy()
})
})

0 comments on commit 12e7ca5

Please sign in to comment.