Browse Source

Dashboard: emit fileId on both file-edit-start and file-edit-complete events (#2729)

* emit fileId on both file-edit-start and file-edit-complete

* update docs

* fileId  --> fileID

* fileID --> file
Artur Paikin 4 năm trước cách đây
mục cha
commit
1eff05ede7

+ 1 - 1
packages/@uppy/dashboard/src/components/FileCard/index.js

@@ -45,7 +45,7 @@ class FileCard extends Component {
   }
 
   handleCancel = () => {
-    this.props.toggleFileCard()
+    this.props.toggleFileCard(false)
   }
 
   renderMetaFields = () => {

+ 1 - 1
packages/@uppy/dashboard/src/components/FileItem/Buttons/index.js

@@ -96,7 +96,7 @@ module.exports = function Buttons (props) {
 
   const editAction = () => {
     if (metaFields && metaFields.length > 0) {
-      toggleFileCard(file.id)
+      toggleFileCard(true, file.id)
     } else {
       openFileEditor(file)
     }

+ 8 - 7
packages/@uppy/dashboard/src/index.js

@@ -399,16 +399,17 @@ module.exports = class Dashboard extends Plugin {
     this.setDarkModeCapability(isDarkModeOnNow)
   }
 
-  toggleFileCard = (fileId) => {
-    if (fileId) {
-      this.uppy.emit('dashboard:file-edit-start')
+  toggleFileCard = (show, fileID) => {
+    const file = this.uppy.getFile(fileID)
+    if (show) {
+      this.uppy.emit('dashboard:file-edit-start', file)
     } else {
-      this.uppy.emit('dashboard:file-edit-complete')
+      this.uppy.emit('dashboard:file-edit-complete', file)
     }
 
     this.setPluginState({
-      fileCardFor: fileId || null,
-      activeOverlayType: fileId ? 'FileCard' : null
+      fileCardFor: show ? fileID : null,
+      activeOverlayType: show ? 'FileCard' : null
     })
   }
 
@@ -765,7 +766,7 @@ module.exports = class Dashboard extends Plugin {
 
   saveFileCard = (meta, fileID) => {
     this.uppy.setFileMeta(fileID, meta)
-    this.toggleFileCard()
+    this.toggleFileCard(false, fileID)
   }
 
   _attachRenderFunctionToTarget = (target) => {

+ 8 - 0
website/src/docs/dashboard.md

@@ -467,8 +467,16 @@ Fired when the Dashboard modal is closed.
 
 ### `dashboard:file-edit-start`
 
+**Parameters:**
+
+- `file` — The [File Object](https://uppy.io/docs/uppy/#File-Objects) representing the file that was opened for editing.
+
 Fired when the user clicks “edit” icon next to a file in the Dashboard. The FileCard panel is then open with file metadata available for editing.
 
 ### `dashboard:file-edit-complete`
 
+**Parameters:**
+
+- `file` — The [File Object](https://uppy.io/docs/uppy/#File-Objects) representing the file that was edited.
+
 Fired when the user finished editing the file metadata.