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/dashboard: propagate setOptions to StatusBar #5260

Merged
merged 12 commits into from
Jul 15, 2024
93 changes: 76 additions & 17 deletions packages/@uppy/dashboard/src/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,76 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
}
}

#getStatusBarOpts() {
const {
hideUploadButton,
hideRetryButton,
hidePauseResumeButton,
hideCancelButton,
showProgressDetails,
hideProgressAfterFinish,
locale: l,
doneButtonHandler,
} = this.opts
return {
hideUploadButton,
hideRetryButton,
hidePauseResumeButton,
hideCancelButton,
showProgressDetails,
hideAfterFinish: hideProgressAfterFinish,
locale: l,
doneButtonHandler,
}
}

#getThumbnailGeneratorOpts() {
const {
thumbnailWidth,
thumbnailHeight,
thumbnailType,
waitForThumbnailsBeforeUpload,
} = this.opts
return {
thumbnailWidth,
thumbnailHeight,
thumbnailType,
waitForThumbnailsBeforeUpload,
// If we don't block on thumbnails, we can lazily generate them
lazy: !waitForThumbnailsBeforeUpload,
}
}

// eslint-disable-next-line class-methods-use-this
#getInformerOpts() {
return {
// currently no options
}
}

setOptions(opts: Partial<DashboardOptions<M, B>>) {
super.setOptions(opts)
this.uppy
.getPlugin(this.#getStatusBarId())
?.setOptions(this.#getStatusBarOpts())
mifi marked this conversation as resolved.
Show resolved Hide resolved

this.uppy
.getPlugin(this.#getThumbnailGeneratorId())
?.setOptions(this.#getThumbnailGeneratorOpts())
}

#getStatusBarId() {
return `${this.id}:StatusBar`
}

#getThumbnailGeneratorId() {
return `${this.id}:ThumbnailGenerator`
}

#getInformerId() {
return `${this.id}:Informer`
}
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

install = (): void => {
// Set default state for Dashboard
this.setPluginState({
Expand Down Expand Up @@ -1343,35 +1413,24 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<

if (!this.opts.disableStatusBar) {
this.uppy.use(StatusBar, {
id: `${this.id}:StatusBar`,
id: this.#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,
...this.#getStatusBarOpts(),
})
}

if (!this.opts.disableInformer) {
this.uppy.use(Informer, {
id: `${this.id}:Informer`,
id: this.#getInformerId(),
target: this,
...this.#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,
// If we don't block on thumbnails, we can lazily generate them
lazy: !this.opts.waitForThumbnailsBeforeUpload,
id: this.#getThumbnailGeneratorId(),
...this.#getThumbnailGeneratorOpts(),
})
}

Expand Down
7 changes: 6 additions & 1 deletion packages/@uppy/react/src/nonHtmlPropsHaveChanged.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import getHTMLProps from './getHTMLProps.ts'

export default function nonHtmlPropsHaveChanged<
T extends Record<string, unknown>,
>(props: T, prevProps: T): boolean {
// todo instead rewrite the components that use nonHtmlPropsHaveChanged
// to hooks, so we can use useEffect on specific props instead of this hack
const htmlProps = getHTMLProps(props)
return Object.keys(props).some(
(key) => !Object.hasOwn(props, key) && props[key] !== prevProps[key],
(key) => !Object.hasOwn(htmlProps, key) && props[key] !== prevProps[key],
)
}