Browse Source

move canEditFile to dashboard/index.js to pass down as a prop

Artur Paikin 4 years ago
parent
commit
373a2d0f32

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

@@ -85,11 +85,7 @@ class FileCard extends Component {
 
   render () {
     const file = this.props.files[this.props.fileCardFor]
-
-    let showEditButton
-    this.props.editors.forEach((target) => {
-      showEditButton = this.props.getPlugin(target.id).сanEditFile(file)
-    })
+    const showEditButton = this.props.canEditFile(file)
 
     return (
       <div

+ 10 - 0
packages/@uppy/dashboard/src/index.js

@@ -235,6 +235,15 @@ module.exports = class Dashboard extends Plugin {
     })
   }
 
+  canEditFile = (file) => {
+    const { targets } = this.getPluginState()
+    const editors = this._getEditors(targets)
+
+    return editors.some((target) => (
+      this.uppy.getPlugin(target.id).сanEditFile(file)
+    ))
+  }
+
   openFileEditor = (file) => {
     const { targets } = this.getPluginState()
 
@@ -889,6 +898,7 @@ module.exports = class Dashboard extends Plugin {
       showAddFilesPanel: pluginState.showAddFilesPanel,
       saveFileCard: this.saveFileCard,
       openFileEditor: this.openFileEditor,
+      canEditFile: this.canEditFile,
       width: this.opts.width,
       height: this.opts.height,
       showLinkToFileUploadResult: this.opts.showLinkToFileUploadResult,