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: add new autoOpen option #5001

Merged
Merged
22 changes: 16 additions & 6 deletions packages/@uppy/dashboard/src/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,23 @@ export default class Dashboard extends UIPlugin {
showNativePhotoCameraButton: false,
showNativeVideoCameraButton: false,
theme: 'light',
autoOpenFileEditor: false,
autoOpen: false,
disabled: false,
disableLocalFiles: false,
}

// support for the legacy `autoOpenFileEditor` option,
// TODO: we can remove this code when we update the Uppy major version
let autoOpen
if (!opts) {
autoOpen = false
} else if (opts.autoOpen === undefined) {
autoOpen = opts.autoOpenFileEditor ? "fileEditor" : false
} else {
autoOpen = opts.autoOpen
}
// merge default options with the ones set by user
this.opts = { ...defaultOptions, ...opts }
this.opts = { ...defaultOptions, ...opts, autoOpen }

this.i18nInit()

Expand Down Expand Up @@ -753,9 +763,9 @@ export default class Dashboard extends UIPlugin {
const isMetaEditorEnabled = metaFields && metaFields.length > 0
const isFileEditorEnabled = this.canEditFile(firstFile)

if (isMetaEditorEnabled) {
if (isMetaEditorEnabled && this.opts.autoOpen === 'metaEditor') {
this.toggleFileCard(true, firstFile.id)
} else if (isFileEditorEnabled) {
} else if (isFileEditorEnabled && this.opts.autoOpen === 'fileEditor') {
this.openFileEditor(firstFile)
}
}
Expand Down Expand Up @@ -792,7 +802,7 @@ export default class Dashboard extends UIPlugin {
this.el.addEventListener('keydown', this.handleKeyDownInInline)
}

if (this.opts.autoOpenFileEditor) {
if (this.opts.autoOpen) {
this.uppy.on('files-added', this.#openFileEditorWhenFilesAdded)
}
}
Expand Down Expand Up @@ -823,7 +833,7 @@ export default class Dashboard extends UIPlugin {
this.el.removeEventListener('keydown', this.handleKeyDownInInline)
}

if (this.opts.autoOpenFileEditor) {
if (this.opts.autoOpen) {
this.uppy.off('files-added', this.#openFileEditorWhenFilesAdded)
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/dashboard/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export interface DashboardOptions extends Options {
theme?: 'auto' | 'dark' | 'light'
trigger?: string
width?: string | number
/** @deprecated use option autoOpen instead */
autoOpenFileEditor?: boolean
lakesare marked this conversation as resolved.
Show resolved Hide resolved
autoOpen?: 'metaEditor' | 'fileEditor' | false
disabled?: boolean
disableLocalFiles?: boolean
onRequestCloseModal?: () => void
Expand Down
8 changes: 4 additions & 4 deletions packages/@uppy/react/src/DashboardModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DashboardModal extends Component {
note,
metaFields, // eslint-disable-line no-shadow
proudlyDisplayPoweredByUppy,
autoOpenFileEditor,
autoOpen,
animateOpenClose,
browserBackButtonClose,
closeAfterFinish,
Expand Down Expand Up @@ -90,7 +90,7 @@ class DashboardModal extends Component {
note,
metaFields,
proudlyDisplayPoweredByUppy,
autoOpenFileEditor,
autoOpen,
animateOpenClose,
browserBackButtonClose,
closeAfterFinish,
Expand Down Expand Up @@ -161,7 +161,7 @@ DashboardModal.propTypes = {
note: PropTypes.string,
metaFields,
proudlyDisplayPoweredByUppy: PropTypes.bool,
autoOpenFileEditor: PropTypes.bool,
autoOpen: PropTypes.oneOf(['fileEditor', 'metaEditor', false]),
animateOpenClose: PropTypes.bool,
browserBackButtonClose: PropTypes.bool,
closeAfterFinish: PropTypes.bool,
Expand Down Expand Up @@ -217,7 +217,7 @@ DashboardModal.defaultProps = {
showRemoveButtonAfterComplete: false,
browserBackButtonClose: false,
theme: 'light',
autoOpenFileEditor: false,
autoOpen: false,
disabled: false,
disableLocalFiles: false,

Expand Down
Loading