Jelajahi Sumber

remove resetProgress and reset-progress (#5221)

* remove resetProgress and reset-progress

* adjust no longer valid test

* fix lint
Mikael Finstad 10 bulan lalu
induk
melakukan
b81b7fb9a3

+ 0 - 11
docs/uppy-core.mdx

@@ -1328,17 +1328,6 @@ uppy.on('restriction-failed', (file, error) => {
 });
 ```
 
-#### `reset-progress`
-
-Fired when `resetProgress()` is called, each file has its upload progress reset
-to zero.
-
-```js
-uppy.on('reset-progress', () => {
-	// progress was reset
-});
-```
-
 ## `new BasePlugin(uppy, options?)`
 
 The initial building block for a plugin.

+ 1 - 23
packages/@uppy/core/src/Uppy.test.ts

@@ -1899,10 +1899,8 @@ describe('src/Core', () => {
       expect(core.getState().totalProgress).toEqual(66)
     })
 
-    it('should reset the progress', () => {
-      const resetProgressEvent = vi.fn()
+    it('should emit the progress', () => {
       const core = new Core()
-      core.on('reset-progress', resetProgressEvent)
 
       core.addFile({
         source: 'vi',
@@ -1943,29 +1941,9 @@ describe('src/Core', () => {
       core.calculateProgress.flush()
 
       expect(core.getState().totalProgress).toEqual(66)
-
-      core.resetProgress()
-
-      expect(core.getFile(file1.id).progress).toEqual({
-        percentage: 0,
-        bytesUploaded: false,
-        bytesTotal: 17175,
-        uploadComplete: false,
-        uploadStarted: null,
-      })
-      expect(core.getFile(file2.id).progress).toEqual({
-        percentage: 0,
-        bytesUploaded: false,
-        bytesTotal: 17175,
-        uploadComplete: false,
-        uploadStarted: null,
-      })
-      expect(core.getState().totalProgress).toEqual(0)
       expect(core.getState().allowNewUpload).toEqual(true)
       expect(core.getState().error).toEqual(null)
       expect(core.getState().recoveredState).toEqual(null)
-
-      expect(resetProgressEvent.mock.calls.length).toEqual(1)
     })
   })
 

+ 1 - 30
packages/@uppy/core/src/Uppy.ts

@@ -23,10 +23,7 @@ import type {
   CompanionClientProvider,
   CompanionClientSearchProvider,
 } from '@uppy/utils/lib/CompanionClientProvider'
-import type {
-  FileProgressNotStarted,
-  FileProgressStarted,
-} from '@uppy/utils/lib/FileProgress'
+import type { FileProgressStarted } from '@uppy/utils/lib/FileProgress'
 import type {
   Locale,
   I18n,
@@ -259,7 +256,6 @@ export interface _UppyEventMap<M extends Meta, B extends Body> {
     progress: NonNullable<FileProgressStarted['preprocess']>,
   ) => void
   progress: (progress: number) => void
-  'reset-progress': () => void
   restored: (pluginData: any) => void
   'restore-confirmed': () => void
   'restore-canceled': () => void
@@ -560,31 +556,6 @@ export class Uppy<M extends Meta, B extends Body> {
     this.setState(undefined) // so that UI re-renders with new options
   }
 
-  resetProgress(): void {
-    const defaultProgress: Omit<FileProgressNotStarted, 'bytesTotal'> = {
-      percentage: 0,
-      bytesUploaded: false,
-      uploadComplete: false,
-      uploadStarted: null,
-    }
-    const files = { ...this.getState().files }
-    const updatedFiles: State<M, B>['files'] = {}
-
-    Object.keys(files).forEach((fileID) => {
-      updatedFiles[fileID] = {
-        ...files[fileID],
-        progress: {
-          ...files[fileID].progress,
-          ...defaultProgress,
-        },
-      }
-    })
-
-    this.setState({ files: updatedFiles, ...defaultUploadState })
-
-    this.emit('reset-progress')
-  }
-
   clear(): void {
     this.setState({ ...defaultUploadState, files: {} })
   }

+ 0 - 18
packages/@uppy/tus/src/index.ts

@@ -147,22 +147,6 @@ export default class Tus<M extends Meta, B extends Body> extends BasePlugin<
 
     this.uploaders = Object.create(null)
     this.uploaderEvents = Object.create(null)
-
-    this.handleResetProgress = this.handleResetProgress.bind(this)
-  }
-
-  handleResetProgress(): void {
-    const files = { ...this.uppy.getState().files }
-    Object.keys(files).forEach((fileID) => {
-      // Only clone the file object if it has a Tus `uploadUrl` attached.
-      if (files[fileID]?.tus?.uploadUrl) {
-        const tusState = { ...files[fileID].tus }
-        delete tusState.uploadUrl
-        files[fileID] = { ...files[fileID], tus: tusState }
-      }
-    })
-
-    this.uppy.setState({ files })
   }
 
   /**
@@ -623,8 +607,6 @@ export default class Tus<M extends Meta, B extends Body> extends BasePlugin<
       },
     })
     this.uppy.addUploader(this.#handleUpload)
-
-    this.uppy.on('reset-progress', this.handleResetProgress)
   }
 
   uninstall(): void {