From 12e7ca5366a6355f399d3397f33d755fa3cb8065 Mon Sep 17 00:00:00 2001 From: Merlijn Vos Date: Wed, 8 May 2024 15:33:04 +0200 Subject: [PATCH] @uppy/core: close->destroy, clearUploadedFiles->clear (#5154) --- e2e/cypress/integration/dashboard-ui.spec.ts | 4 ++-- packages/@uppy/core/src/UIPlugin.ts | 2 +- packages/@uppy/core/src/Uppy.test.ts | 6 +++--- packages/@uppy/core/src/Uppy.ts | 11 ++--------- packages/@uppy/dashboard/src/Dashboard.tsx | 2 +- packages/@uppy/dashboard/src/index.test.ts | 14 +++++++------- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/e2e/cypress/integration/dashboard-ui.spec.ts b/e2e/cypress/integration/dashboard-ui.spec.ts index e38e9ec3e3..31439e685e 100644 --- a/e2e/cypress/integration/dashboard-ui.spec.ts +++ b/e2e/cypress/integration/dashboard-ui.spec.ts @@ -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', @@ -15,7 +15,7 @@ describe('dashboard-ui', () => { ) cy.window().then(({ uppy }) => { - expect(uppy.close()).to.not.throw + expect(uppy.destroy()).to.not.throw }) }) diff --git a/packages/@uppy/core/src/UIPlugin.ts b/packages/@uppy/core/src/UIPlugin.ts index b9be3f6373..74a68fccba 100644 --- a/packages/@uppy/core/src/UIPlugin.ts +++ b/packages/@uppy/core/src/UIPlugin.ts @@ -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) diff --git a/packages/@uppy/core/src/Uppy.test.ts b/packages/@uppy/core/src/Uppy.test.ts index 9985c45f20..f126be11fc 100644 --- a/packages/@uppy/core/src/Uppy.test.ts +++ b/packages/@uppy/core/src/Uppy.test.ts @@ -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' }, @@ -1808,7 +1808,7 @@ describe('src/Core', () => { await uploadPromise - core.close() + core.destroy() }) it('should estimate progress for unsized files', () => { @@ -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', () => { diff --git a/packages/@uppy/core/src/Uppy.ts b/packages/@uppy/core/src/Uppy.ts index 9a33497c73..69da0fcef9 100644 --- a/packages/@uppy/core/src/Uppy.ts +++ b/packages/@uppy/core/src/Uppy.ts @@ -571,7 +571,6 @@ export class Uppy { this.setState(undefined) // so that UI re-renders with new options } - // todo next major: remove resetProgress(): void { const defaultProgress: Omit = { percentage: 0, @@ -597,9 +596,7 @@ export class Uppy { 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: {} }) } @@ -1799,11 +1796,7 @@ export class Uppy { /** * 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`, ) diff --git a/packages/@uppy/dashboard/src/Dashboard.tsx b/packages/@uppy/dashboard/src/Dashboard.tsx index e923d6373e..c3d56da15d 100644 --- a/packages/@uppy/dashboard/src/Dashboard.tsx +++ b/packages/@uppy/dashboard/src/Dashboard.tsx @@ -284,7 +284,7 @@ export default class Dashboard extends UIPlugin< // Dynamic default options: this.opts.doneButtonHandler ??= () => { - this.uppy.clearUploadedFiles() + this.uppy.clear() this.requestCloseModal() } this.opts.onRequestCloseModal ??= () => this.closeModal() diff --git a/packages/@uppy/dashboard/src/index.test.ts b/packages/@uppy/dashboard/src/index.test.ts index d584cb927a..07693700f7 100644 --- a/packages/@uppy/dashboard/src/index.test.ts +++ b/packages/@uppy/dashboard/src/index.test.ts @@ -35,7 +35,7 @@ describe('Dashboard', () => { core.use(DashboardPlugin, { inline: false }) }).not.toThrow() - core.close() + core.destroy() }) it('works without any remote provider plugins', () => { @@ -48,7 +48,7 @@ describe('Dashboard', () => { }) }).not.toThrow() - core.close() + core.destroy() }) it('works when targeting remote provider plugins using `target`', () => { @@ -64,7 +64,7 @@ describe('Dashboard', () => { }) }).not.toThrow() - core.close() + core.destroy() }) it('works when passing plugins in `plugins` array', () => { @@ -79,7 +79,7 @@ describe('Dashboard', () => { }) }).not.toThrow() - core.close() + core.destroy() }) it('should automatically add plugins which have no target', () => { @@ -98,7 +98,7 @@ describe('Dashboard', () => { true, ) - core.close() + core.destroy() }) it('should not automatically add plugins which have a non-Dashboard target', () => { @@ -118,7 +118,7 @@ describe('Dashboard', () => { false, ) - core.close() + core.destroy() }) it('should change options on the fly', () => { @@ -168,6 +168,6 @@ describe('Dashboard', () => { }) }).not.toThrow() - core.close() + core.destroy() }) })