2016-07-16 02:06:10 +00:00
|
|
|
import React, {PropTypes} from 'react';
|
2016-04-23 06:08:52 +00:00
|
|
|
|
2016-07-16 02:06:10 +00:00
|
|
|
import Link from './base/Link';
|
2016-07-22 21:35:49 +00:00
|
|
|
import Editor from './base/Editor';
|
2016-07-16 02:06:10 +00:00
|
|
|
import Modal from './base/Modal';
|
|
|
|
import ModalBody from './base/ModalBody';
|
|
|
|
import ModalHeader from './base/ModalHeader';
|
|
|
|
import ModalFooter from './base/ModalFooter';
|
|
|
|
import ModalComponent from './lib/ModalComponent';
|
2016-04-15 05:23:54 +00:00
|
|
|
|
2016-07-15 00:26:04 +00:00
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
class EnvironmentEditModal extends ModalComponent {
|
2016-07-07 20:10:55 +00:00
|
|
|
constructor (props) {
|
2016-04-15 05:23:54 +00:00
|
|
|
super(props);
|
2016-07-22 21:35:49 +00:00
|
|
|
|
2016-04-15 05:23:54 +00:00
|
|
|
this.state = {
|
2016-07-22 21:35:49 +00:00
|
|
|
environmentJSON: '{}',
|
|
|
|
requestGroup: null
|
2016-04-15 05:23:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_saveChanges () {
|
2016-07-22 21:35:49 +00:00
|
|
|
const {requestGroup, environmentJSON} = this.state;
|
2016-04-15 05:23:54 +00:00
|
|
|
|
2016-07-22 21:35:49 +00:00
|
|
|
let environment;
|
|
|
|
try {
|
|
|
|
environment = JSON.parse(environmentJSON);
|
|
|
|
} catch (e) {
|
|
|
|
// That's OK. The user will (hopefully) fix the problem
|
|
|
|
console.warn('Failed to parse environment JSON', e);
|
|
|
|
return;
|
|
|
|
}
|
2016-04-15 05:23:54 +00:00
|
|
|
|
2016-07-22 21:35:49 +00:00
|
|
|
this.props.onChange(Object.assign({}, requestGroup, {environment}));
|
|
|
|
this.hide();
|
2016-04-17 01:52:10 +00:00
|
|
|
}
|
|
|
|
|
2016-07-22 21:35:49 +00:00
|
|
|
_handleChange (environmentJSON) {
|
|
|
|
this.setState({environmentJSON});
|
2016-04-17 01:52:10 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 00:26:04 +00:00
|
|
|
_update (requestGroup) {
|
2016-07-22 21:35:49 +00:00
|
|
|
const environmentJSON = JSON.stringify(requestGroup.environment, null, '\t');
|
|
|
|
this.setState({environmentJSON, requestGroup});
|
2016-07-06 20:18:26 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 00:26:04 +00:00
|
|
|
show (requestGroup) {
|
|
|
|
super.show();
|
|
|
|
this._update(requestGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle (requestGroup) {
|
|
|
|
super.toggle();
|
|
|
|
this._update(requestGroup);
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
render () {
|
2016-07-22 21:35:49 +00:00
|
|
|
const {environmentJSON} = this.state;
|
2016-07-06 22:11:37 +00:00
|
|
|
|
2016-04-15 05:23:54 +00:00
|
|
|
return (
|
2016-07-20 23:16:28 +00:00
|
|
|
<Modal ref="modal" top={true} {...this.props}>
|
2016-04-15 05:23:54 +00:00
|
|
|
<ModalHeader>Environment Variables</ModalHeader>
|
2016-05-01 20:46:11 +00:00
|
|
|
<ModalBody>
|
2016-07-22 21:35:49 +00:00
|
|
|
<div className="pad-bottom">
|
|
|
|
<Editor
|
|
|
|
onChange={this._handleChange.bind(this)}
|
|
|
|
value={environmentJSON}
|
|
|
|
lightTheme={true}
|
|
|
|
mode="application/json"
|
|
|
|
/>
|
|
|
|
</div>
|
2016-04-15 05:23:54 +00:00
|
|
|
</ModalBody>
|
2016-07-07 20:10:55 +00:00
|
|
|
<ModalFooter>
|
2016-07-09 04:49:09 +00:00
|
|
|
<div className="pull-right">
|
|
|
|
<button className="btn" onClick={this._saveChanges.bind(this)}>Save</button>
|
|
|
|
</div>
|
2016-07-22 21:35:49 +00:00
|
|
|
<div className="pad faint italic txt-sm tall">
|
|
|
|
* this data can be used for
|
|
|
|
<Link href="https://mozilla.github.io/nunjucks/templating.html">
|
|
|
|
Nunjucks Templating
|
|
|
|
</Link> in your requests
|
2016-07-07 20:10:55 +00:00
|
|
|
</div>
|
2016-04-15 05:23:54 +00:00
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-17 01:52:10 +00:00
|
|
|
EnvironmentEditModal.propTypes = {
|
2016-04-15 05:23:54 +00:00
|
|
|
onChange: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2016-04-17 01:52:10 +00:00
|
|
|
export default EnvironmentEditModal;
|