Added basic downloading
Slightly broken
This commit is contained in:
@@ -116,6 +116,7 @@
|
||||
"eslint-plugin-react": "^7.1.0",
|
||||
"extract-text-webpack-plugin": "^2.1.2",
|
||||
"file-loader": "0.11.2",
|
||||
"file-saver": "^1.3.8",
|
||||
"git-describe": "^4.0.1",
|
||||
"imports-loader": "0.7.1",
|
||||
"json-loader": "0.5.4",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { Component } from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import { highlight } from "core/utils"
|
||||
import { saveAs } from "file-saver"
|
||||
|
||||
export default class HighlightCode extends Component {
|
||||
static propTypes = {
|
||||
@@ -25,6 +26,12 @@ export default class HighlightCode extends Component {
|
||||
this.setState({ contentsHidden: !this.state.contentsHidden })
|
||||
}
|
||||
|
||||
downloadJSON = (value) => {
|
||||
let fileName = 'response'
|
||||
let fileToSave = new Blob([value], {type: 'text/json', name: fileName})
|
||||
saveAs(fileToSave)
|
||||
}
|
||||
|
||||
render () {
|
||||
let { value, className } = this.props
|
||||
let contentsHidden = this.state && this.state.contentsHidden
|
||||
@@ -42,6 +49,11 @@ export default class HighlightCode extends Component {
|
||||
{ contentsHidden ? 'See full contents' : 'Collapse contents'}
|
||||
</div>
|
||||
}
|
||||
{ value.length > 600 &&
|
||||
<div className='see-full-contents' onClick={this.downloadJSON(value)}>
|
||||
{'Download'}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user