2017-02-28 21:32:23 +00:00
|
|
|
import React, {PropTypes, PureComponent} from 'react';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-03-08 05:52:17 +00:00
|
|
|
import EnvironmentEditor from '../editors/environment-editor';
|
|
|
|
import Modal from '../base/modal';
|
|
|
|
import ModalBody from '../base/modal-body';
|
|
|
|
import ModalHeader from '../base/modal-header';
|
|
|
|
import ModalFooter from '../base/modal-footer';
|
2016-04-15 05:23:54 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-02-28 21:32:23 +00:00
|
|
|
class EnvironmentEditModal extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
requestGroup: null,
|
|
|
|
isValid: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_setModalRef (n) {
|
|
|
|
this.modal = n;
|
|
|
|
}
|
2016-04-15 05:23:54 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_setEditorRef (n) {
|
|
|
|
this._envEditor = n;
|
|
|
|
}
|
2017-02-27 21:00:13 +00:00
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_saveChanges () {
|
2016-08-15 17:04:36 +00:00
|
|
|
if (!this._envEditor.isValid()) {
|
2016-07-22 21:35:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-15 05:23:54 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
const environment = this._envEditor.getValue();
|
|
|
|
const {requestGroup} = this.state;
|
|
|
|
|
2016-07-22 21:35:49 +00:00
|
|
|
this.props.onChange(Object.assign({}, requestGroup, {environment}));
|
2016-04-17 01:52:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_didChange () {
|
2016-08-15 17:04:36 +00:00
|
|
|
this._saveChanges();
|
|
|
|
|
|
|
|
const isValid = this._envEditor.isValid();
|
2016-04-17 01:52:10 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
if (this.state.isValid !== isValid) {
|
|
|
|
this.setState({isValid});
|
|
|
|
}
|
2016-07-06 20:18:26 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 00:26:04 +00:00
|
|
|
show (requestGroup) {
|
2016-08-15 17:04:36 +00:00
|
|
|
this.modal.show();
|
|
|
|
this.setState({requestGroup});
|
2016-07-15 00:26:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 06:23:23 +00:00
|
|
|
hide () {
|
|
|
|
this.modal.hide();
|
|
|
|
}
|
|
|
|
|
2016-07-15 00:26:04 +00:00
|
|
|
toggle (requestGroup) {
|
2016-08-15 17:04:36 +00:00
|
|
|
this.modal.toggle();
|
|
|
|
this.setState({requestGroup});
|
2016-07-15 00:26:04 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
render () {
|
2017-02-26 23:47:45 +00:00
|
|
|
const {
|
|
|
|
editorKeyMap,
|
|
|
|
editorFontSize,
|
|
|
|
lineWrapping,
|
2017-02-27 21:00:13 +00:00
|
|
|
render,
|
2017-03-12 00:31:23 +00:00
|
|
|
getRenderContext,
|
2017-02-26 23:47:45 +00:00
|
|
|
...extraProps
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const {
|
|
|
|
requestGroup,
|
|
|
|
isValid
|
|
|
|
} = this.state;
|
2016-07-06 22:11:37 +00:00
|
|
|
|
2016-04-15 05:23:54 +00:00
|
|
|
return (
|
2017-03-01 21:15:56 +00:00
|
|
|
<Modal ref={this._setModalRef} tall top {...extraProps}>
|
2016-08-15 17:04:36 +00:00
|
|
|
<ModalHeader>Environment Overrides (JSON Format)</ModalHeader>
|
2017-03-01 21:15:56 +00:00
|
|
|
<ModalBody noScroll>
|
2016-08-15 17:04:36 +00:00
|
|
|
<EnvironmentEditor
|
2017-03-01 21:15:56 +00:00
|
|
|
lightTheme
|
2017-01-23 22:41:31 +00:00
|
|
|
editorFontSize={editorFontSize}
|
2017-01-24 22:18:11 +00:00
|
|
|
editorKeyMap={editorKeyMap}
|
2017-02-28 21:32:23 +00:00
|
|
|
ref={this._setEditorRef}
|
2016-08-15 17:04:36 +00:00
|
|
|
key={requestGroup ? requestGroup._id : 'n/a'}
|
2017-02-26 23:47:45 +00:00
|
|
|
lineWrapping={lineWrapping}
|
2016-08-15 17:04:36 +00:00
|
|
|
environment={requestGroup ? requestGroup.environment : {}}
|
2017-02-27 21:00:13 +00:00
|
|
|
didChange={this._didChange}
|
|
|
|
render={render}
|
2017-03-12 00:31:23 +00:00
|
|
|
getRenderContext={getRenderContext}
|
2016-08-15 17:04:36 +00:00
|
|
|
/>
|
2016-04-15 05:23:54 +00:00
|
|
|
</ModalBody>
|
2016-07-07 20:10:55 +00:00
|
|
|
<ModalFooter>
|
2016-10-21 17:20:36 +00:00
|
|
|
<div className="margin-left faint italic txt-sm">
|
2016-08-15 17:04:36 +00:00
|
|
|
* this can be used to override data in the global environment
|
2016-07-07 20:10:55 +00:00
|
|
|
</div>
|
2017-03-09 06:23:23 +00:00
|
|
|
<button className="btn" disabled={!isValid} onClick={this.hide}>
|
2016-10-21 17:20:36 +00:00
|
|
|
Done
|
|
|
|
</button>
|
2016-04-15 05:23:54 +00:00
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-17 01:52:10 +00:00
|
|
|
EnvironmentEditModal.propTypes = {
|
2017-01-23 22:41:31 +00:00
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
editorFontSize: PropTypes.number.isRequired,
|
2017-01-24 22:18:11 +00:00
|
|
|
editorKeyMap: PropTypes.string.isRequired,
|
2017-02-27 21:00:13 +00:00
|
|
|
render: PropTypes.func.isRequired,
|
2017-03-12 00:31:23 +00:00
|
|
|
getRenderContext: PropTypes.func.isRequired,
|
2017-03-03 20:09:08 +00:00
|
|
|
lineWrapping: PropTypes.bool.isRequired
|
2016-04-15 05:23:54 +00:00
|
|
|
};
|
|
|
|
|
2016-04-17 01:52:10 +00:00
|
|
|
export default EnvironmentEditModal;
|