-
Notifications
You must be signed in to change notification settings - Fork 2k
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/dashboard: propagate setOptions to StatusBar #5260
base: 4.x
Are you sure you want to change the base?
Conversation
(when react props change) fixes #5248
ruse dashboard
Diff output filesdiff --git a/packages/@uppy/dashboard/lib/Dashboard.js b/packages/@uppy/dashboard/lib/Dashboard.js
index 1f2f804..2b4d6d6 100644
--- a/packages/@uppy/dashboard/lib/Dashboard.js
+++ b/packages/@uppy/dashboard/lib/Dashboard.js
@@ -85,6 +85,12 @@ var _getEditors = _classPrivateFieldLooseKey("getEditors");
var _addSpecifiedPluginsFromOptions = _classPrivateFieldLooseKey("addSpecifiedPluginsFromOptions");
var _autoDiscoverPlugins = _classPrivateFieldLooseKey("autoDiscoverPlugins");
var _addSupportedPluginIfNoTarget = _classPrivateFieldLooseKey("addSupportedPluginIfNoTarget");
+var _getStatusBarOpts = _classPrivateFieldLooseKey("getStatusBarOpts");
+var _getThumbnailGeneratorOpts = _classPrivateFieldLooseKey("getThumbnailGeneratorOpts");
+var _getInformerOpts = _classPrivateFieldLooseKey("getInformerOpts");
+var _getStatusBarId = _classPrivateFieldLooseKey("getStatusBarId");
+var _getThumbnailGeneratorId = _classPrivateFieldLooseKey("getThumbnailGeneratorId");
+var _getInformerId = _classPrivateFieldLooseKey("getInformerId");
export default class Dashboard extends UIPlugin {
constructor(uppy, _opts) {
var _opts$autoOpen, _this$opts4, _this$opts4$doneButto, _this$opts5, _this$opts5$onRequest;
@@ -94,6 +100,24 @@ export default class Dashboard extends UIPlugin {
..._opts,
autoOpen,
});
+ Object.defineProperty(this, _getInformerId, {
+ value: _getInformerId2,
+ });
+ Object.defineProperty(this, _getThumbnailGeneratorId, {
+ value: _getThumbnailGeneratorId2,
+ });
+ Object.defineProperty(this, _getStatusBarId, {
+ value: _getStatusBarId2,
+ });
+ Object.defineProperty(this, _getInformerOpts, {
+ value: _getInformerOpts2,
+ });
+ Object.defineProperty(this, _getThumbnailGeneratorOpts, {
+ value: _getThumbnailGeneratorOpts2,
+ });
+ Object.defineProperty(this, _getStatusBarOpts, {
+ value: _getStatusBarOpts2,
+ });
Object.defineProperty(this, _disabledNodes, {
writable: true,
value: void 0,
@@ -982,32 +1006,22 @@ export default class Dashboard extends UIPlugin {
}
if (!this.opts.disableStatusBar) {
this.uppy.use(StatusBar, {
- id: `${this.id}:StatusBar`,
+ id: _classPrivateFieldLooseBase(this, _getStatusBarId)[_getStatusBarId](),
target: this,
- hideUploadButton: this.opts.hideUploadButton,
- hideRetryButton: this.opts.hideRetryButton,
- hidePauseResumeButton: this.opts.hidePauseResumeButton,
- hideCancelButton: this.opts.hideCancelButton,
- showProgressDetails: this.opts.showProgressDetails,
- hideAfterFinish: this.opts.hideProgressAfterFinish,
- locale: this.opts.locale,
- doneButtonHandler: this.opts.doneButtonHandler,
+ ..._classPrivateFieldLooseBase(this, _getStatusBarOpts)[_getStatusBarOpts](),
});
}
if (!this.opts.disableInformer) {
this.uppy.use(Informer, {
- id: `${this.id}:Informer`,
+ id: _classPrivateFieldLooseBase(this, _getInformerId)[_getInformerId](),
target: this,
+ ..._classPrivateFieldLooseBase(this, _getInformerOpts)[_getInformerOpts](),
});
}
if (!this.opts.disableThumbnailGenerator) {
this.uppy.use(ThumbnailGenerator, {
- id: `${this.id}:ThumbnailGenerator`,
- thumbnailWidth: this.opts.thumbnailWidth,
- thumbnailHeight: this.opts.thumbnailHeight,
- thumbnailType: this.opts.thumbnailType,
- waitForThumbnailsBeforeUpload: this.opts.waitForThumbnailsBeforeUpload,
- lazy: !this.opts.waitForThumbnailsBeforeUpload,
+ id: _classPrivateFieldLooseBase(this, _getThumbnailGeneratorId)[_getThumbnailGeneratorId](),
+ ..._classPrivateFieldLooseBase(this, _getThumbnailGeneratorOpts)[_getThumbnailGeneratorOpts](),
});
}
this.darkModeMediaQuery = typeof window !== "undefined" && window.matchMedia
@@ -1069,5 +1083,51 @@ export default class Dashboard extends UIPlugin {
: _this$opts5.onRequestCloseModal = () => this.closeModal();
this.i18nInit();
}
+ setOptions(opts) {
+ var _this$uppy$getPlugin, _this$uppy$getPlugin2;
+ super.setOptions(opts);
+ (_this$uppy$getPlugin = this.uppy.getPlugin(_classPrivateFieldLooseBase(this, _getStatusBarId)[_getStatusBarId]()))
+ == null
+ || _this$uppy$getPlugin.setOptions(_classPrivateFieldLooseBase(this, _getStatusBarOpts)[_getStatusBarOpts]());
+ (_this$uppy$getPlugin2 = this.uppy.getPlugin(
+ _classPrivateFieldLooseBase(this, _getThumbnailGeneratorId)[_getThumbnailGeneratorId](),
+ )) == null
+ || _this$uppy$getPlugin2.setOptions(
+ _classPrivateFieldLooseBase(this, _getThumbnailGeneratorOpts)[_getThumbnailGeneratorOpts](),
+ );
+ }
+}
+function _getStatusBarOpts2() {
+ return {
+ hideUploadButton: this.opts.hideUploadButton,
+ hideRetryButton: this.opts.hideRetryButton,
+ hidePauseResumeButton: this.opts.hidePauseResumeButton,
+ hideCancelButton: this.opts.hideCancelButton,
+ showProgressDetails: this.opts.showProgressDetails,
+ hideAfterFinish: this.opts.hideProgressAfterFinish,
+ locale: this.opts.locale,
+ doneButtonHandler: this.opts.doneButtonHandler,
+ };
+}
+function _getThumbnailGeneratorOpts2() {
+ return {
+ thumbnailWidth: this.opts.thumbnailWidth,
+ thumbnailHeight: this.opts.thumbnailHeight,
+ thumbnailType: this.opts.thumbnailType,
+ waitForThumbnailsBeforeUpload: this.opts.waitForThumbnailsBeforeUpload,
+ lazy: !this.opts.waitForThumbnailsBeforeUpload,
+ };
+}
+function _getInformerOpts2() {
+ return {};
+}
+function _getStatusBarId2() {
+ return `${this.id}:StatusBar`;
+}
+function _getThumbnailGeneratorId2() {
+ return `${this.id}:ThumbnailGenerator`;
+}
+function _getInformerId2() {
+ return `${this.id}:Informer`;
}
Dashboard.VERSION = packageJson.version;
diff --git a/packages/@uppy/react/lib/nonHtmlPropsHaveChanged.js b/packages/@uppy/react/lib/nonHtmlPropsHaveChanged.js
index 57e0cdf..1d6700a 100644
--- a/packages/@uppy/react/lib/nonHtmlPropsHaveChanged.js
+++ b/packages/@uppy/react/lib/nonHtmlPropsHaveChanged.js
@@ -1,3 +1,5 @@
+import getHTMLProps from "./getHTMLProps";
export default function nonHtmlPropsHaveChanged(props, prevProps) {
- return Object.keys(props).some(key => !Object.hasOwn(props, key) && props[key] !== prevProps[key]);
+ const htmlProps = getHTMLProps(props);
+ return Object.keys(props).some(key => !Object.hasOwn(htmlProps, key) && props[key] !== prevProps[key]);
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking it up quickly
const [i, setI] = useState(0); | ||
|
||
// https://github.com/transloadit/uppy/issues/5248 | ||
const handleDoneButtonClick = useCallback(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be in e2e instead? We already have a react client there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optimally yes it should 😇
case '/dashboard.html': { | ||
const restrictions = undefined | ||
// const restrictions = { requiredMetaFields: ['caption'], maxNumberOfFiles: 3 } | ||
|
||
const uppy = DashboardUppy({ restrictions }) | ||
.use(Dashboard, { | ||
trigger: '#pick-files', | ||
// inline: true, | ||
target: '.foo', | ||
metaFields: [ | ||
{ id: 'license', name: 'License', placeholder: 'specify license' }, | ||
{ id: 'caption', name: 'Caption', placeholder: 'add caption' }, | ||
], | ||
showProgressDetails: true, | ||
proudlyDisplayPoweredByUppy: true, | ||
note: `${JSON.stringify(restrictions)}`, | ||
}) | ||
.use(Form, { target: '#upload-form' }) | ||
|
||
window.uppy = uppy | ||
|
||
const modalTrigger = document.querySelector('#pick-files') | ||
if (modalTrigger) modalTrigger.click() | ||
} | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why define uppy and its plugins both in index and the route files? I expect this to only link to the app file, not define it in two places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by the route files?
I wanted to reuse uppy initialisation with all dev env variables and logic between react (React.jsx) and non-react (index.js). but for react we cannot uppy.use(Dashboard)
so I pulled that out and instead do it only here in non-react (index.js). (and modalTrigger is not appliccable for react either, as well as window.uppy = uppy
).
return { | ||
hideUploadButton: this.opts.hideUploadButton, | ||
hideRetryButton: this.opts.hideRetryButton, | ||
hidePauseResumeButton: this.opts.hidePauseResumeButton, | ||
hideCancelButton: this.opts.hideCancelButton, | ||
showProgressDetails: this.opts.showProgressDetails, | ||
hideAfterFinish: this.opts.hideProgressAfterFinish, | ||
locale: this.opts.locale, | ||
doneButtonHandler: this.opts.doneButtonHandler, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it might be more readable to use destructuring here, not sure.
return { | |
hideUploadButton: this.opts.hideUploadButton, | |
hideRetryButton: this.opts.hideRetryButton, | |
hidePauseResumeButton: this.opts.hidePauseResumeButton, | |
hideCancelButton: this.opts.hideCancelButton, | |
showProgressDetails: this.opts.showProgressDetails, | |
hideAfterFinish: this.opts.hideProgressAfterFinish, | |
locale: this.opts.locale, | |
doneButtonHandler: this.opts.doneButtonHandler, | |
} | |
const { | |
hideUploadButton, | |
hideRetryButton, | |
hidePauseResumeButton, | |
hideCancelButton, | |
showProgressDetails, | |
hideAfterFinish, | |
locale, | |
doneButtonHandler, | |
} = this.opts | |
return { | |
hideUploadButton, | |
hideRetryButton, | |
hidePauseResumeButton, | |
hideCancelButton, | |
showProgressDetails, | |
hideAfterFinish, | |
locale, | |
doneButtonHandler, | |
} |
(when react props change) fixes [4.x] Dashboard doneButtonHandler resets parent state (without re-render) #5248