Skip to content

Commit

Permalink
fix PropType linter errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed May 24, 2022
1 parent 04bf4fd commit ccdfb01
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/@uppy/dashboard/src/Dashboard.jsx
Expand Up @@ -53,7 +53,7 @@ export default class Dashboard extends UIPlugin {

this.defaultLocale = locale

// set default options
// set default options, must be kept in sync with
const defaultOptions = {
target: 'body',
metaFields: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/drag-drop/src/DragDrop.jsx
Expand Up @@ -22,7 +22,7 @@ export default class DragDrop extends UIPlugin {

this.defaultLocale = locale

// Default options
// Default options, must be kept in sync with @uppy/react/src/DragDrop.js.
const defaultOpts = {
target: null,
inputName: 'files[]',
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/file-input/src/FileInput.jsx
Expand Up @@ -16,7 +16,7 @@ export default class FileInput extends UIPlugin {

this.defaultLocale = locale

// Default options
// Default options, must be kept in sync with @uppy/react/src/FileInput.js.
const defaultOptions = {
target: null,
pretty: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/progress-bar/src/ProgressBar.jsx
Expand Up @@ -16,7 +16,7 @@ export default class ProgressBar extends UIPlugin {
this.title = 'Progress Bar'
this.type = 'progressindicator'

// set default options
// set default options, must kept in sync with @uppy/react/src/ProgressBar.js
const defaultOptions = {
target: 'body',
fixed: false,
Expand Down
165 changes: 155 additions & 10 deletions packages/@uppy/react/src/DashboardModal.js
@@ -1,7 +1,7 @@
import { createElement as h, Component } from 'react'
import PropTypes from 'prop-types'
import DashboardPlugin from '@uppy/dashboard'
import { dashboard as basePropTypes } from './propTypes.js'
import { cssSize, locale, metaFields, plugins, uppy as uppyPropType } from './propTypes.js'
import getHTMLProps from './getHTMLProps.js'
import nonHtmlPropsHaveChanged from './nonHtmlPropsHaveChanged.js'

Expand All @@ -16,17 +16,18 @@ class DashboardModal extends Component {
}

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()
}
}
Expand All @@ -36,11 +37,82 @@ class DashboardModal extends 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) {
Expand All @@ -51,7 +123,7 @@ class DashboardModal extends Component {
uppy.use(DashboardPlugin, options)

this.plugin = uppy.getPlugin(options.id)
if (this.props.open) {
if (open) {
this.plugin.openModal()
}
}
Expand All @@ -76,12 +148,85 @@ class DashboardModal extends 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.
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,
}

export default DashboardModal
29 changes: 26 additions & 3 deletions packages/@uppy/react/src/DragDrop.js
@@ -1,4 +1,5 @@
import { createElement as h, Component } from 'react'
import PropTypes from 'prop-types'
import DragDropPlugin from '@uppy/drag-drop'
import * as propTypes from './propTypes.js'
import getHTMLProps from './getHTMLProps.js'
Expand All @@ -15,6 +16,7 @@ class DragDrop extends Component {
}

componentDidUpdate (prevProps) {
// eslint-disable-next-line react/destructuring-assignment
if (prevProps.uppy !== this.props.uppy) {
this.uninstallPlugin(prevProps)
this.installPlugin()
Expand All @@ -30,10 +32,21 @@ class DragDrop extends Component {
}

installPlugin () {
const { uppy } = this.props
const {
uppy,
locale,
inputName,
width,
height,
note,
} = this.props
const options = {
id: 'react:DragDrop',
...this.props,
locale,
inputName,
width,
height,
note,
target: this.container,
}
delete options.uppy
Expand Down Expand Up @@ -63,10 +76,20 @@ class DragDrop extends Component {
}

DragDrop.propTypes = {
uppy: propTypes.uppy,
uppy: propTypes.uppy.isRequired,
locale: propTypes.locale,
inputName: PropTypes.string,
width: PropTypes.string,
height: PropTypes.string,
note: PropTypes.string,
}
// Must be kept in sync with @uppy/drag-drop/src/DragDrop.jsx.
DragDrop.defaultProps = {
locale: null,
inputName: 'files[]',
width: '100%',
height: '100%',
note: null,
}

export default DragDrop
13 changes: 10 additions & 3 deletions packages/@uppy/react/src/FileInput.js
Expand Up @@ -14,6 +14,7 @@ class FileInput extends Component {
}

componentDidUpdate (prevProps) {
// eslint-disable-next-line react/destructuring-assignment
if (prevProps.uppy !== this.props.uppy) {
this.uninstallPlugin(prevProps)
this.installPlugin()
Expand All @@ -25,10 +26,12 @@ class FileInput extends Component {
}

installPlugin () {
const { uppy } = this.props
const { uppy, locale, pretty, inputName } = this.props
const options = {
id: 'react:FileInput',
...this.props,
locale,
pretty,
inputName,
target: this.container,
}
delete options.uppy
Expand All @@ -55,12 +58,16 @@ class FileInput extends Component {
}

FileInput.propTypes = {
uppy: propTypes.uppy,
uppy: propTypes.uppy.isRequired,
locale: propTypes.locale,
pretty: PropTypes.bool,
inputName: PropTypes.string,
}
// Must be kept in sync with @uppy/file-input/src/FileInput.jsx
FileInput.defaultProps = {
locale: undefined,
pretty: true,
inputName: 'files[]',
}

export default FileInput
11 changes: 8 additions & 3 deletions packages/@uppy/react/src/ProgressBar.js
Expand Up @@ -15,6 +15,7 @@ class ProgressBar extends Component {
}

componentDidUpdate (prevProps) {
// eslint-disable-next-line react/destructuring-assignment
if (prevProps.uppy !== this.props.uppy) {
this.uninstallPlugin(prevProps)
this.installPlugin()
Expand All @@ -30,10 +31,11 @@ class ProgressBar extends Component {
}

installPlugin () {
const { uppy } = this.props
const { uppy, fixed, hideAfterFinish } = this.props
const options = {
id: 'react:ProgressBar',
...this.props,
fixed,
hideAfterFinish,
target: this.container,
}
delete options.uppy
Expand Down Expand Up @@ -63,11 +65,14 @@ class ProgressBar extends Component {
}

ProgressBar.propTypes = {
uppy: uppyPropType,
uppy: uppyPropType.isRequired,
fixed: PropTypes.bool,
hideAfterFinish: PropTypes.bool,
}
// Must be kept in sync with @uppy/progress-bar/src/ProgressBar.jsx
ProgressBar.defaultProps = {
fixed: false,
hideAfterFinish: true,
}

export default ProgressBar

0 comments on commit ccdfb01

Please sign in to comment.