Forráskód Böngészése

@uppy/core: close->destroy, clearUploadedFiles->clear (#5154)

Merlijn Vos 11 hónapja
szülő
commit
12e7ca5366

+ 2 - 2
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
     })
   })
 

+ 1 - 1
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)

+ 3 - 3
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', () => {

+ 2 - 9
packages/@uppy/core/src/Uppy.ts

@@ -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,
@@ -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: {} })
   }
 
@@ -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`,
     )

+ 1 - 1
packages/@uppy/dashboard/src/Dashboard.tsx

@@ -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()

+ 7 - 7
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()
   })
 })