forked from swagger-api/swagger-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.jsx
79 lines (70 loc) · 2.33 KB
/
layout.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React from "react"
import PropTypes from "prop-types"
import Dropzone from "react-dropzone"
export default class EditorLayout extends React.Component {
static propTypes = {
errSelectors: PropTypes.object.isRequired,
errActions: PropTypes.object.isRequired,
specActions: PropTypes.object.isRequired,
specSelectors: PropTypes.object.isRequired,
getComponent: PropTypes.func.isRequired,
layoutSelectors: PropTypes.object.isRequired,
layoutActions: PropTypes.object.isRequired
}
onChange = (newYaml) => {
this.props.specActions.updateSpec(newYaml)
}
onDrop = (acceptedFiles, rejectedFiles) => {
const someFilesWereRejected = rejectedFiles && rejectedFiles.length > 0
const thereIsExactlyOneAcceptedFile = acceptedFiles && acceptedFiles.length === 1
if ( someFilesWereRejected || !thereIsExactlyOneAcceptedFile) {
alert("Sorry, there was an error processing your file(s).\nPlease drag and drop one (and only one) .yaml or .json OpenAPI spec file.")
} else {
const file = acceptedFiles[0]
const reader = new FileReader()
reader.onloadend = () => {
const spec = reader.result
this.onChange(spec)
}
reader.readAsText(file, "utf-8")
}
}
render() {
let { getComponent } = this.props
let UIBaseLayout = getComponent("BaseLayout", true)
let Container = getComponent("Container")
let EditorContainer = getComponent("EditorContainer", true)
const SplitPaneMode = getComponent("SplitPaneMode", true)
return (
<div>
<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>
)
}
}