insomnia/app/ui/components/editors/EnvironmentEditor.js
Gregory Schier bb57f360e0 Environment Tags and Such (#90)
* Sort of working nunjucks editor

* Some more tweaks

* Lots of stuff

* Gettingn pretty good

* Minor tweaks and test fixes

* Minor bug fixes and stuff

* Some fixes and perf

* Refactoring

* Good for now

* Codemirror URL

* More and more fixes and improvements

* Code single-line CSS perfect!!!

* Better nj editing

* Show preview in nj edit

* Some editor updates

* All inputs now covered

* A bunch of fixes and stuff

* Don't cache node modules because it's not needed

* More stuff

* Tweak

* Style tweaks

* Pull nunjucks mode into own file

* Move codemirror click overlay to own file

* Pull nunjucks tag stuff out

* Fixed key value editor

* raw/endraw and marks improvements

* Some tweaks
2017-02-27 13:00:13 -08:00

61 lines
1.4 KiB
JavaScript

import React, {PropTypes, Component} from 'react';
import Editor from '../codemirror/Editor';
import {DEBOUNCE_MILLIS} from '../../../common/constants';
class EnvironmentEditor extends Component {
_handleChange = () => this.props.didChange();
_setEditorRef = n => this._editor = n;
getValue () {
return JSON.parse(this._editor.getValue());
}
isValid () {
try {
return this.getValue() !== undefined;
} catch (e) {
// Failed to parse JSON
return false;
}
}
render () {
const {
environment,
editorFontSize,
editorKeyMap,
render,
lineWrapping,
...props
} = this.props;
return (
<Editor
ref={this._setEditorRef}
fontSize={editorFontSize}
lineWrapping={lineWrapping}
keyMap={editorKeyMap}
onChange={this._handleChange}
debounceMillis={DEBOUNCE_MILLIS * 6}
value={JSON.stringify(environment)}
autoPrettify={true}
render={render}
mode="application/json"
{...props}
/>
)
}
}
EnvironmentEditor.propTypes = {
environment: PropTypes.object.isRequired,
didChange: PropTypes.func.isRequired,
editorFontSize: PropTypes.number.isRequired,
editorKeyMap: PropTypes.string.isRequired,
render: PropTypes.func.isRequired,
lineWrapping: PropTypes.bool.isRequired,
};
export default EnvironmentEditor;