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/react: refactor to ESM #3780
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,33 @@ | ||
const React = require('react') | ||
const PropTypes = require('prop-types') | ||
const DashboardPlugin = require('@uppy/dashboard') | ||
const basePropTypes = require('./propTypes').dashboard | ||
const getHTMLProps = require('./getHTMLProps') | ||
const nonHtmlPropsHaveChanged = require('./nonHtmlPropsHaveChanged') | ||
|
||
const h = React.createElement | ||
import { createElement as h, Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import DashboardPlugin from '@uppy/dashboard' | ||
import { cssSize, locale, metaFields, plugins, uppy as uppyPropType } from './propTypes.js' | ||
import getHTMLProps from './getHTMLProps.js' | ||
import nonHtmlPropsHaveChanged from './nonHtmlPropsHaveChanged.js' | ||
|
||
/** | ||
* React Component that renders a Dashboard for an Uppy instance in a Modal | ||
* dialog. Visibility of the Modal is toggled using the `open` prop. | ||
*/ | ||
|
||
class DashboardModal extends React.Component { | ||
class DashboardModal extends Component { | ||
componentDidMount () { | ||
this.installPlugin() | ||
} | ||
|
||
componentDidUpdate (prevProps) { | ||
if (prevProps.uppy !== this.props.uppy) { | ||
const { uppy, open, onRequestClose } = this.props | ||
if (prevProps.uppy !== uppy) { | ||
this.uninstallPlugin(prevProps) | ||
this.installPlugin() | ||
} else if (nonHtmlPropsHaveChanged(this, prevProps)) { | ||
const options = { ...this.props, onRequestCloseModal: this.props.onRequestClose } | ||
const options = { ...this.props, onRequestCloseModal: onRequestClose } | ||
delete options.uppy | ||
this.plugin.setOptions(options) | ||
} | ||
if (prevProps.open && !this.props.open) { | ||
if (prevProps.open && !open) { | ||
this.plugin.closeModal() | ||
} else if (!prevProps.open && this.props.open) { | ||
} else if (!prevProps.open && open) { | ||
this.plugin.openModal() | ||
} | ||
} | ||
|
@@ -38,11 +37,82 @@ class DashboardModal extends React.Component { | |
} | ||
|
||
installPlugin () { | ||
const { uppy } = this.props | ||
const { | ||
uppy, | ||
target, | ||
open, | ||
onRequestClose, | ||
closeModalOnClickOutside, | ||
disablePageScrollWhenModalOpen, | ||
inline, | ||
plugins, // eslint-disable-line no-shadow | ||
width, | ||
height, | ||
showProgressDetails, | ||
note, | ||
metaFields, // eslint-disable-line no-shadow | ||
proudlyDisplayPoweredByUppy, | ||
autoOpenFileEditor, | ||
animateOpenClose, | ||
browserBackButtonClose, | ||
closeAfterFinish, | ||
disableStatusBar, | ||
disableInformer, | ||
disableThumbnailGenerator, | ||
disableLocalFiles, | ||
disabled, | ||
hideCancelButton, | ||
hidePauseResumeButton, | ||
hideProgressAfterFinish, | ||
hideRetryButton, | ||
hideUploadButton, | ||
showLinkToFileUploadResult, | ||
showRemoveButtonAfterComplete, | ||
showSelectedFiles, | ||
waitForThumbnailsBeforeUpload, | ||
fileManagerSelectionType, | ||
theme, | ||
thumbnailType, | ||
thumbnailWidth, | ||
locale, // eslint-disable-line no-shadow | ||
} = this.props | ||
const options = { | ||
id: 'react:DashboardModal', | ||
...this.props, | ||
onRequestCloseModal: this.props.onRequestClose, | ||
target, | ||
closeModalOnClickOutside, | ||
disablePageScrollWhenModalOpen, | ||
inline, | ||
plugins, | ||
width, | ||
height, | ||
showProgressDetails, | ||
note, | ||
metaFields, | ||
proudlyDisplayPoweredByUppy, | ||
autoOpenFileEditor, | ||
animateOpenClose, | ||
browserBackButtonClose, | ||
closeAfterFinish, | ||
disableStatusBar, | ||
disableInformer, | ||
disableThumbnailGenerator, | ||
disableLocalFiles, | ||
disabled, | ||
hideCancelButton, | ||
hidePauseResumeButton, | ||
hideProgressAfterFinish, | ||
hideRetryButton, | ||
hideUploadButton, | ||
showLinkToFileUploadResult, | ||
showRemoveButtonAfterComplete, | ||
showSelectedFiles, | ||
waitForThumbnailsBeforeUpload, | ||
fileManagerSelectionType, | ||
theme, | ||
thumbnailType, | ||
thumbnailWidth, | ||
locale, | ||
onRequestCloseModal: onRequestClose, | ||
} | ||
|
||
if (!options.target) { | ||
|
@@ -53,7 +123,7 @@ class DashboardModal extends React.Component { | |
uppy.use(DashboardPlugin, options) | ||
|
||
this.plugin = uppy.getPlugin(options.id) | ||
if (this.props.open) { | ||
if (open) { | ||
this.plugin.openModal() | ||
} | ||
} | ||
|
@@ -78,12 +148,85 @@ class DashboardModal extends React.Component { | |
} | ||
|
||
DashboardModal.propTypes = { | ||
uppy: uppyPropType.isRequired, | ||
target: typeof window !== 'undefined' ? PropTypes.instanceOf(window.HTMLElement) : PropTypes.any, | ||
open: PropTypes.bool, | ||
onRequestClose: PropTypes.func, | ||
closeModalOnClickOutside: PropTypes.bool, | ||
disablePageScrollWhenModalOpen: PropTypes.bool, | ||
...basePropTypes, | ||
inline: PropTypes.bool, | ||
plugins, | ||
width: cssSize, | ||
height: cssSize, | ||
showProgressDetails: PropTypes.bool, | ||
note: PropTypes.string, | ||
metaFields, | ||
proudlyDisplayPoweredByUppy: PropTypes.bool, | ||
autoOpenFileEditor: PropTypes.bool, | ||
animateOpenClose: PropTypes.bool, | ||
browserBackButtonClose: PropTypes.bool, | ||
closeAfterFinish: PropTypes.bool, | ||
disableStatusBar: PropTypes.bool, | ||
disableInformer: PropTypes.bool, | ||
disableThumbnailGenerator: PropTypes.bool, | ||
disableLocalFiles: PropTypes.bool, | ||
disabled: PropTypes.bool, | ||
hideCancelButton: PropTypes.bool, | ||
hidePauseResumeButton: PropTypes.bool, | ||
hideProgressAfterFinish: PropTypes.bool, | ||
hideRetryButton: PropTypes.bool, | ||
hideUploadButton: PropTypes.bool, | ||
showLinkToFileUploadResult: PropTypes.bool, | ||
showRemoveButtonAfterComplete: PropTypes.bool, | ||
showSelectedFiles: PropTypes.bool, | ||
waitForThumbnailsBeforeUpload: PropTypes.bool, | ||
fileManagerSelectionType: PropTypes.string, | ||
theme: PropTypes.string, | ||
// pass-through to ThumbnailGenerator | ||
thumbnailType: PropTypes.string, | ||
thumbnailWidth: PropTypes.number, | ||
locale, | ||
} | ||
// Must be kept in sync with @uppy/dashboard/src/Dashboard.jsx. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kudos for writing all these prop types. But yeah, this is why you want TS, this would be reused |
||
DashboardModal.defaultProps = { | ||
metaFields: [], | ||
plugins: [], | ||
inline: false, | ||
width: 750, | ||
height: 550, | ||
thumbnailWidth: 280, | ||
thumbnailType: 'image/jpeg', | ||
waitForThumbnailsBeforeUpload: false, | ||
showLinkToFileUploadResult: false, | ||
showProgressDetails: false, | ||
hideUploadButton: false, | ||
hideCancelButton: false, | ||
hideRetryButton: false, | ||
hidePauseResumeButton: false, | ||
hideProgressAfterFinish: false, | ||
note: null, | ||
closeModalOnClickOutside: false, | ||
closeAfterFinish: false, | ||
disableStatusBar: false, | ||
disableInformer: false, | ||
disableThumbnailGenerator: false, | ||
disablePageScrollWhenModalOpen: true, | ||
animateOpenClose: true, | ||
fileManagerSelectionType: 'files', | ||
proudlyDisplayPoweredByUppy: true, | ||
showSelectedFiles: true, | ||
showRemoveButtonAfterComplete: false, | ||
browserBackButtonClose: false, | ||
theme: 'light', | ||
autoOpenFileEditor: false, | ||
disabled: false, | ||
disableLocalFiles: false, | ||
|
||
// extra | ||
open: undefined, | ||
target: undefined, | ||
locale: null, | ||
onRequestClose: undefined, | ||
} | ||
|
||
module.exports = DashboardModal | ||
export default DashboardModal |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As we import Dashboard anyway, couldn't we export and use the default options?
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.
No, the linter wants them in the same file :/
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.
The linter is here to serve us, not the other way around. If we feel it's more maintainable to not having to remember to keep options in sync across the repo — we should slap an
eslint-disable
on it and reuse the settings :)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.
If we want to ignore the warning, we don’t need default props at all (I think) we can simply go back to how it was before that and pass the props along using
…this.props
. There could be good reasons not to do that though, I suppose the lint rule is there for a reason.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.
I read it wrong, I thought we had the same
defaultOptions
object in both Dashboard and react/Dashboard. But the latter has prop types instead of the same object. Probably makes most sense yeah