Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/core: pass file to events consistently #5136

Merged
merged 6 commits into from
May 29, 2024
Merged

Conversation

Murderlon
Copy link
Member

@Murderlon Murderlon commented May 2, 2024

Closes #3938

@Murderlon Murderlon requested review from mifi and aduh95 May 2, 2024 14:26
@Murderlon Murderlon self-assigned this May 2, 2024
Copy link
Contributor

github-actions bot commented May 2, 2024

Diff output files
diff --git a/packages/@uppy/companion-client/lib/RequestClient.js b/packages/@uppy/companion-client/lib/RequestClient.js
index a7ef904..6dbea5e 100644
--- a/packages/@uppy/companion-client/lib/RequestClient.js
+++ b/packages/@uppy/companion-client/lib/RequestClient.js
@@ -466,8 +466,8 @@ async function _awaitRemoteFileUpload2(_ref4) {
         this.uppy.log(`upload ${file.id} was canceled`, "info");
         resolve();
       };
-      const onFilePausedChange = (targetFileId, newPausedState) => {
-        if (targetFileId !== file.id) return;
+      const onFilePausedChange = (targetFile, newPausedState) => {
+        if ((targetFile == null ? void 0 : targetFile.id) !== file.id) return;
         pause(newPausedState);
       };
       const onPauseAll = () => pause(true);
diff --git a/packages/@uppy/core/lib/EventManager.js b/packages/@uppy/core/lib/EventManager.js
index 05ee7f4..54d8574 100644
--- a/packages/@uppy/core/lib/EventManager.js
+++ b/packages/@uppy/core/lib/EventManager.js
@@ -32,8 +32,8 @@ export default class EventManager {
     }
   }
   onFilePause(fileID, cb) {
-    this.on("upload-pause", (targetFileID, isPaused) => {
-      if (fileID === targetFileID) {
+    this.on("upload-pause", (file, isPaused) => {
+      if (fileID === (file == null ? void 0 : file.id)) {
         cb(isPaused);
       }
     });
@@ -44,15 +44,15 @@ export default class EventManager {
     });
   }
   onPause(fileID, cb) {
-    this.on("upload-pause", (targetFileID, isPaused) => {
-      if (fileID === targetFileID) {
+    this.on("upload-pause", (file, isPaused) => {
+      if (fileID === (file == null ? void 0 : file.id)) {
         cb(isPaused);
       }
     });
   }
   onRetry(fileID, cb) {
-    this.on("upload-retry", targetFileID => {
-      if (fileID === targetFileID) {
+    this.on("upload-retry", file => {
+      if (fileID === (file == null ? void 0 : file.id)) {
         cb();
       }
     });
diff --git a/packages/@uppy/core/lib/Uppy.js b/packages/@uppy/core/lib/Uppy.js
index 3b2edee..8bbd650 100644
--- a/packages/@uppy/core/lib/Uppy.js
+++ b/packages/@uppy/core/lib/Uppy.js
@@ -632,12 +632,13 @@ export class Uppy {
     if (!this.getState().capabilities.resumableUploads || this.getFile(fileID).progress.uploadComplete) {
       return undefined;
     }
-    const wasPaused = this.getFile(fileID).isPaused || false;
+    const file = this.getFile(fileID);
+    const wasPaused = file.isPaused || false;
     const isPaused = !wasPaused;
     this.setFileState(fileID, {
       isPaused,
     });
-    this.emit("upload-pause", fileID, isPaused);
+    this.emit("upload-pause", file, isPaused);
     return isPaused;
   }
   pauseAll() {
@@ -698,7 +699,7 @@ export class Uppy {
       files: updatedFiles,
       error: null,
     });
-    this.emit("retry-all", filesToRetry);
+    this.emit("retry-all", Object.values(updatedFiles));
     if (filesToRetry.length === 0) {
       return Promise.resolve({
         successful: [],
@@ -733,7 +734,7 @@ export class Uppy {
       error: null,
       isPaused: false,
     });
-    this.emit("upload-retry", fileID);
+    this.emit("upload-retry", this.getFile(fileID));
     const uploadID = _classPrivateFieldLooseBase(this, _createUpload)[_createUpload]([fileID], {
       forceAllowNewUpload: true,
     });
@@ -1444,10 +1445,7 @@ function _createUpload2(fileIDs, opts) {
     throw new Error("Cannot create a new upload: already uploading.");
   }
   const uploadID = nanoid();
-  this.emit("upload", {
-    id: uploadID,
-    fileIDs,
-  });
+  this.emit("upload", uploadID, this.getFilesByIds(fileIDs));
   this.setState({
     allowNewUpload: this.opts.allowMultipleUploadBatches !== false && this.opts.allowMultipleUploads !== false,
     currentUploads: {

@Murderlon Murderlon marked this pull request as draft May 2, 2024 15:17
@Murderlon Murderlon marked this pull request as ready for review May 6, 2024 08:53
@mifi
Copy link
Contributor

mifi commented May 8, 2024

Leaving upload and retry-all events as IDs because it might be a lot of files and it's less likely you want to do something with all files there.

did we agree to also convert these for consistency?

@Murderlon
Copy link
Member Author

did we agree to also convert these for consistency?

Done

Co-authored-by: Mikael Finstad <finstaden@gmail.com>
@aduh95 aduh95 added the notable change Changes that deserve a mention in a migration guide label May 13, 2024
* 4.x: (24 commits)
  @uppy/companion: encode `uploadId` (#5168)
  @uppy/companion: bump `express-session` (#5177)
  @uppy/companion: remove dependency on `express-request-id` (#5176)
  @uppy/companion: bump prom to v15 (#5175)
  docs: fix linter
  meta: remove `nodemon` from the deps (#5172)
  docs: update `@uppy/aws-s3` docs (#5093)
  meta: update more dependencies (#5171)
  @uppy/companion: upgrade deps (#5119)
  Release: uppy@4.0.0-beta.7 (#5162)
  @uppy/companion: switch from `node-redis` to `ioredis` (#4623)
  Fix headings in xhr.mdx
  @uppy/xhr-upload: introduce hooks similar to tus (#5094)
  @uppy/core: close->destroy, clearUploadedFiles->clear (#5154)
  Use `title` consistently from locales (#5134)
  Release: uppy@4.0.0-beta.6 (#5152)
  Release: uppy@4.0.0-beta.5 (#5141)
  meta: run Prettier in the release workflow
  Release: uppy@3.25.1 (#5139)
  Bump ejs from 3.1.9 to 3.1.10 (#5135)
  ...
@Murderlon Murderlon merged commit 453eb0f into 4.x May 29, 2024
17 checks passed
@Murderlon Murderlon deleted the consistent-event-file-args branch May 29, 2024 11:09
github-actions bot added a commit that referenced this pull request Jun 4, 2024
| Package                |       Version | Package                |       Version |
| ---------------------- | ------------- | ---------------------- | ------------- |
| @uppy/angular          |  0.7.0-beta.5 | @uppy/instagram        |  4.0.0-beta.6 |
| @uppy/audio            |  2.0.0-beta.6 | @uppy/locales          |  4.0.0-beta.2 |
| @uppy/aws-s3           |  4.0.0-beta.5 | @uppy/onedrive         |  4.0.0-beta.6 |
| @uppy/aws-s3-multipart |  4.0.0-beta.6 | @uppy/provider-views   |  4.0.0-beta.7 |
| @uppy/box              |  3.0.0-beta.6 | @uppy/status-bar       |  4.0.0-beta.9 |
| @uppy/companion        |  5.0.0-beta.9 | @uppy/transloadit      |  4.0.0-beta.7 |
| @uppy/companion-client |  4.0.0-beta.7 | @uppy/tus              |  4.0.0-beta.6 |
| @uppy/core             |  4.0.0-beta.9 | @uppy/unsplash         |  4.0.0-beta.7 |
| @uppy/dashboard        |  4.0.0-beta.9 | @uppy/url              |  4.0.0-beta.7 |
| @uppy/drop-target      |  3.0.0-beta.5 | @uppy/utils            |  6.0.0-beta.8 |
| @uppy/dropbox          |  4.0.0-beta.7 | @uppy/webcam           |  4.0.0-beta.8 |
| @uppy/facebook         |  4.0.0-beta.6 | @uppy/xhr-upload       |  4.0.0-beta.6 |
| @uppy/form             |  4.0.0-beta.4 | @uppy/zoom             |  3.0.0-beta.6 |
| @uppy/golden-retriever |  4.0.0-beta.5 | uppy                   | 4.0.0-beta.10 |
| @uppy/google-drive     |  4.0.0-beta.6 |                        |               |

- @uppy/audio: remove unused component props (Antoine du Hamel / #5209)
- @uppy/angular: fix invalid char in `package.json` (Antoine du Hamel / #5224)
- meta: use default argument value instead of `defaultProps` (Antoine du Hamel / #5222)
- @uppy/angular: upgrade to Angular 18 (Antoine du Hamel / #5215)
- @uppy/utils: remove unused `settle` (Antoine du Hamel / #5210)
- @uppy/form: move internal property to private field (Antoine du Hamel / #5214)
- @uppy/dashboard: remove unused component props (Antoine du Hamel / #5213)
- @uppy/status-bar: remove unused component props (Antoine du Hamel / #5211)
- @uppy/audio: move internal property to private field (Antoine du Hamel / #5207)
- @uppy/aws-s3: remove todo (Mikael Finstad / #5200)
- @uppy/core: remove unnecessary todo (Mikael Finstad / #5200)
- @uppy/aws-s3: do not expose internal `assertHost` method (Mikael Finstad / #5200)
- @uppy/aws-s3: make passing `signal` consistent (Mikael Finstad / #5200)
- @uppy/core: remove `'upload-started'` event (Mikael Finstad / #5200)
- @uppy/aws-s3: remove `chunkState` getter (Mikael Finstad / #5200)
- @uppy/drop-target: remove `title` property (Mikael Finstad / #5200)
- @uppy/golden-retriever: remove unused `ready` setters (Mikael Finstad / #5200)
- @uppy/dashboard: remove deprecated `autoOpenFileEditor` option (Mikael Finstad / #5200)
- @uppy/aws-s3: remove `uploaderSockets` (Mikael Finstad / #5200)
- @uppy/locales: remove hacks for legacy bundle (Mikael Finstad / #5200)
- @uppy/status-bar: rename `StatusBar` to `StatusBarUI` (Mikael Finstad / #5200)
- @uppy/url: remove unused error handler (Mikael Finstad / #5200)
- @uppy/aws-s3,@uppy/tus,@uppy/utils,@uppy/xhr-upload: remove `uploader` from `upload-progress` event (Mikael Finstad / #5200)
- @uppy/webcam: remove `facingMode` option (Mikael Finstad / #5200)
- @uppy/companion: invert some internal boolean options (Mikael Finstad / #5198)
- @uppy/companion: rename `authProvider` to `oauthProvider` (Mikael Finstad / #5198)
- @uppy/companion: remove unused headers (Mikael Finstad / #5198)
- @uppy/companion: remove sanitizing of metadata (Mikael Finstad / #5198)
- @uppy/companion-client: do not allow boolean `RequestOptions` (Mikael Finstad / #5198)
- @uppy/companion-client: remove deprecated options (Mikael Finstad / #5198)
- @uppy/companion: remove `error.extraData` (Mikael Finstad / #5198)
- @uppy/companion-client: make `supportsRefreshToken` default (Mikael Finstad / #5198)
- @uppy/companion-client: remove optional chaining (Mikael Finstad / #5198)
- @uppy/companion: capitalize POST (Mikael Finstad / #5198)
- @uppy/companion: simplify code by using modern Node.js APIs (Mikael Finstad / #5198)
- @uppy/companion-client: remove `Socket` (Mikael Finstad / #5198)
- @uppy/companion: rename `getExtraConfig` to `getExtraGrantConfig` (Mikael Finstad / #5198)
- @uppy/companion: change `COMPANION_ENABLE_URL_ENDPOINT` default (Mikael Finstad / #5198)
- @uppy/companion: change default value for Redis session prefix (Mikael Finstad / #5198)
- examples: make React example up-to-date (Merlijn Vos / #5205)
- @uppy/core: add type tests (Merlijn Vos / #5153)
- @uppy/provider-views: PartialTree - get rid of `.onFirstRender()` (Evgenia Karunus / #5187)
- @uppy/core: pass file to events consistently (Merlijn Vos / #5136)
- docs: assume tree-shaking bundler is the most common case (Antoine du Hamel / #5160)
- @uppy/core: remove `reason` (Antoine du Hamel / #5159)
- @uppy/core: remove `resetProgress` and `reset-progress` (Mikael Finstad / #5221)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notable change Changes that deserve a mention in a migration guide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants