-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(deps): bump react-dropzone from 4.2.11 to 12.0.4 (#2921)
- Loading branch information
Showing
10 changed files
with
308 additions
and
192 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
import React from "react" | ||
import React, { useCallback } from "react" | ||
import PropTypes from "prop-types" | ||
import Dropzone from "react-dropzone" | ||
import { useDropzone } from "react-dropzone" | ||
|
||
Dropzone.displayName = "Dropzone" // For testing | ||
|
||
export default class EditorLayout extends React.Component { | ||
|
||
static propTypes = { | ||
errSelectors: PropTypes.object.isRequired, | ||
errActions: PropTypes.object.isRequired, | ||
specActions: PropTypes.object.isRequired, | ||
getComponent: PropTypes.func.isRequired, | ||
layoutSelectors: PropTypes.object.isRequired, | ||
layoutActions: PropTypes.object.isRequired | ||
} | ||
|
||
onChange = (newYaml, origin="editor") => { | ||
this.props.specActions.updateSpec(newYaml, origin) | ||
} | ||
|
||
onDrop = (acceptedFiles, rejectedFiles) => { | ||
const Dropzone = ({ children, onDrop }) => { | ||
const handleDrop = useCallback((acceptedFiles, rejectedFiles) => { | ||
const someFilesWereRejected = rejectedFiles && rejectedFiles.length > 0 | ||
const thereIsExactlyOneAcceptedFile = acceptedFiles && acceptedFiles.length === 1 | ||
if ( someFilesWereRejected || !thereIsExactlyOneAcceptedFile) { | ||
|
||
if (someFilesWereRejected || !thereIsExactlyOneAcceptedFile) { | ||
alert("Sorry, there was an error processing your file.\nPlease drag and drop exactly one .yaml or .json OpenAPI definition file.") | ||
} else { | ||
const file = acceptedFiles[0] | ||
const reader = new FileReader() | ||
reader.onloadend = () => { | ||
const spec = reader.result | ||
this.onChange(spec, "fileDrop") | ||
onDrop(spec, "fileDrop") | ||
} | ||
|
||
reader.readAsText(file, "utf-8") | ||
} | ||
} | ||
|
||
render() { | ||
const { getComponent } = this.props | ||
}, []) | ||
const {getRootProps, getInputProps, isDragActive} = useDropzone({ | ||
onDrop: handleDrop, | ||
accept: ".yaml,application/json", | ||
multiple: false, | ||
noClick: true, | ||
}) | ||
|
||
const UIBaseLayout = getComponent("BaseLayout", true) | ||
const EditorContainer = getComponent("EditorContainer", true) | ||
const SplitPaneMode = getComponent("SplitPaneMode", true) | ||
return ( | ||
<div className="dropzone" {...getRootProps()}> | ||
<input data-cy="dropzone" {...getInputProps()} /> | ||
{isDragActive | ||
? ( | ||
<div className="dropzone__overlay"> | ||
Please drop a .yaml or .json OpenAPI spec. | ||
</div> | ||
) | ||
: children | ||
} | ||
</div> | ||
) | ||
} | ||
Dropzone.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
onDrop: PropTypes.func.isRequired, | ||
} | ||
|
||
const Container = getComponent("Container") | ||
const EditorLayout = ({ specActions, getComponent }) => { | ||
const UIBaseLayout = getComponent("BaseLayout", true) | ||
const EditorContainer = getComponent("EditorContainer", true) | ||
const SplitPaneMode = getComponent("SplitPaneMode", true) | ||
const Container = getComponent("Container") | ||
|
||
return ( | ||
<div className="swagger-editor"> | ||
<Container className="container"> | ||
<Dropzone | ||
className="dropzone" | ||
accept=".yaml,application/json" | ||
multiple={false} | ||
onDrop={this.onDrop} | ||
disablePreview | ||
disableClick | ||
> | ||
{({ isDragActive }) => { | ||
if (isDragActive) { | ||
return ( | ||
<div className="dropzone__overlay"> | ||
Please drop a .yaml or .json OpenAPI spec. | ||
</div> | ||
) | ||
} else { | ||
return ( | ||
<SplitPaneMode> | ||
<EditorContainer onChange={this.onChange} /> | ||
<UIBaseLayout/> | ||
</SplitPaneMode> | ||
) | ||
} | ||
}} | ||
</Dropzone> | ||
</Container> | ||
</div> | ||
) | ||
const handleChange = (newYaml, origin="editor") => { | ||
specActions.updateSpec(newYaml, origin) | ||
} | ||
|
||
return ( | ||
<div className="swagger-editor"> | ||
<Container className="container"> | ||
<Dropzone onDrop={handleChange}> | ||
<SplitPaneMode> | ||
<EditorContainer onChange={handleChange} /> | ||
<UIBaseLayout/> | ||
</SplitPaneMode> | ||
</Dropzone> | ||
</Container> | ||
</div> | ||
) | ||
} | ||
EditorLayout.propTypes = { | ||
errSelectors: PropTypes.object.isRequired, | ||
errActions: PropTypes.object.isRequired, | ||
specActions: PropTypes.object.isRequired, | ||
getComponent: PropTypes.func.isRequired, | ||
layoutSelectors: PropTypes.object.isRequired, | ||
layoutActions: PropTypes.object.isRequired | ||
} | ||
|
||
export default EditorLayout |
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 |
---|---|---|
|
@@ -6,4 +6,6 @@ globals: | |
|
||
rules: | ||
"no-console": 0 | ||
"no-unused-vars": 0 | ||
"no-unused-vars": 0 | ||
"no-unused-expressions": 0 | ||
|
Oops, something went wrong.