2016-08-15 17:04:36 +00:00
|
|
|
import React, {PropTypes, Component} from 'react';
|
2016-04-23 06:08:52 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
import EnvironmentEditor from '../editors/EnvironmentEditor';
|
2016-07-22 22:27:04 +00:00
|
|
|
import Modal from '../base/Modal';
|
|
|
|
import ModalBody from '../base/ModalBody';
|
|
|
|
import ModalHeader from '../base/ModalHeader';
|
|
|
|
import ModalFooter from '../base/ModalFooter';
|
2016-04-15 05:23:54 +00:00
|
|
|
|
2016-07-15 00:26:04 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
class EnvironmentEditModal extends Component {
|
2016-11-26 08:29:16 +00:00
|
|
|
state = {
|
|
|
|
requestGroup: null,
|
|
|
|
isValid: true
|
|
|
|
};
|
2016-04-15 05:23:54 +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
|
|
|
}
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
_didChange () {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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-01-24 22:18:11 +00:00
|
|
|
const {editorKeyMap, editorFontSize, ...extraProps} = this.props;
|
2016-08-15 17:04:36 +00:00
|
|
|
const {requestGroup, isValid} = this.state;
|
2016-07-06 22:11:37 +00:00
|
|
|
|
2016-04-15 05:23:54 +00:00
|
|
|
return (
|
2017-01-23 22:41:31 +00:00
|
|
|
<Modal ref={m => this.modal = m} tall={true} top={true} {...extraProps}>
|
2016-08-15 17:04:36 +00:00
|
|
|
<ModalHeader>Environment Overrides (JSON Format)</ModalHeader>
|
|
|
|
<ModalBody noScroll={true}>
|
|
|
|
<EnvironmentEditor
|
2017-01-23 22:41:31 +00:00
|
|
|
editorFontSize={editorFontSize}
|
2017-01-24 22:18:11 +00:00
|
|
|
editorKeyMap={editorKeyMap}
|
2016-08-15 17:04:36 +00:00
|
|
|
ref={node => this._envEditor = node}
|
|
|
|
key={requestGroup ? requestGroup._id : 'n/a'}
|
|
|
|
environment={requestGroup ? requestGroup.environment : {}}
|
|
|
|
didChange={this._didChange.bind(this)}
|
|
|
|
lightTheme={true}
|
|
|
|
/>
|
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>
|
2016-10-21 17:20:36 +00:00
|
|
|
<button className="btn" disabled={!isValid} onClick={e => this.modal.hide()}>
|
|
|
|
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,
|
2016-04-15 05:23:54 +00:00
|
|
|
};
|
|
|
|
|
2016-04-17 01:52:10 +00:00
|
|
|
export default EnvironmentEditModal;
|