From 891e176bd53d30e3cb34ca77cd1069d7918a6d7e Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Tue, 1 Aug 2023 10:17:03 +0200 Subject: [PATCH] @uppy/provider-views: fix ProviderView error on empty plugin.icon (#4553) The dashboard provides a default/fallback icon for plugins without icon. The ProviderView does not - so a plugin that can be shown just fine on the overview panel, produces an error when it's actually opened. Let's use the same fallback icon. --- packages/@uppy/dashboard/src/Dashboard.jsx | 11 ++--------- .../src/ProviderView/ProviderView.jsx | 16 +++++++++++++--- .../provider-views/src/ProviderView/index.js | 2 +- packages/@uppy/provider-views/src/index.js | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/@uppy/dashboard/src/Dashboard.jsx b/packages/@uppy/dashboard/src/Dashboard.jsx index 0c103dcbb..4a4353621 100644 --- a/packages/@uppy/dashboard/src/Dashboard.jsx +++ b/packages/@uppy/dashboard/src/Dashboard.jsx @@ -1,4 +1,3 @@ -import { h } from 'preact' import { UIPlugin } from '@uppy/core' import StatusBar from '@uppy/status-bar' import Informer from '@uppy/informer' @@ -6,6 +5,8 @@ import ThumbnailGenerator from '@uppy/thumbnail-generator' import findAllDOMElements from '@uppy/utils/lib/findAllDOMElements' import toArray from '@uppy/utils/lib/toArray' import getDroppedFiles from '@uppy/utils/lib/getDroppedFiles' +import { defaultPickerIcon } from '@uppy/provider-views' + import { nanoid } from 'nanoid/non-secure' import memoizeOne from 'memoize-one' import * as trapFocus from './utils/trapFocus.js' @@ -29,14 +30,6 @@ function createPromise () { return o } -function defaultPickerIcon () { - return ( - - ) -} - /** * Dashboard UI with previews, metadata editing, tabs for various services and more */ diff --git a/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx b/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx index c4ccfccbf..be2e1c7dc 100644 --- a/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx +++ b/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx @@ -41,6 +41,14 @@ function prependPath (path, component) { return `${path}/${component}` } +export function defaultPickerIcon () { + return ( + + ) +} + /** * Class to easily generate generic views for Provider plugins */ @@ -453,11 +461,13 @@ export default class ProviderView extends View { const { files, folders, filterInput, loading, currentSelection } = this.plugin.getPluginState() const { isChecked, toggleCheckbox, recordShiftKeyPress, filterItems } = this const hasInput = filterInput !== '' + const pluginIcon = this.plugin.icon || defaultPickerIcon + const headerProps = { showBreadcrumbs: targetViewOptions.showBreadcrumbs, getFolder: this.getFolder, breadcrumbs: this.plugin.getPluginState().breadcrumbs, - pluginIcon: this.plugin.icon, + pluginIcon, title: this.plugin.title, logout: this.logout, username: this.username, @@ -495,7 +505,7 @@ export default class ProviderView extends View { viewType: targetViewOptions.viewType, showTitles: targetViewOptions.showTitles, showBreadcrumbs: targetViewOptions.showBreadcrumbs, - pluginIcon: this.plugin.icon, + pluginIcon, i18n: this.plugin.uppy.i18n, uppyFiles: this.plugin.uppy.getFiles(), validateRestrictions: (...args) => this.plugin.uppy.validateRestrictions(...args), @@ -514,7 +524,7 @@ export default class ProviderView extends View {