diff --git a/app/actions/__tests__/requestgroups.test.js b/app/actions/__tests__/requestgroups.test.js index c4d63f194..e7b16763b 100644 --- a/app/actions/__tests__/requestgroups.test.js +++ b/app/actions/__tests__/requestgroups.test.js @@ -3,9 +3,6 @@ jest.unmock('../global'); jest.unmock('../../constants/global'); jest.unmock('../../constants/actionTypes'); jest.unmock('../../validators/requestGroup'); -jest.unmock('jsonschema'); -jest.unmock('redux-thunk'); -jest.unmock('redux-mock-store'); describe('RequestGroup Actions', () => { it('should add valid group', () => { diff --git a/app/actions/__tests__/requests.test.js b/app/actions/__tests__/requests.test.js index 3c1d3be0a..5591ddcbf 100644 --- a/app/actions/__tests__/requests.test.js +++ b/app/actions/__tests__/requests.test.js @@ -5,10 +5,6 @@ jest.unmock('../../constants/actionTypes'); jest.unmock('../../validators/request'); jest.unmock('../../reducers/requests'); jest.unmock('../../reducers/global'); -jest.unmock('jsonschema'); -jest.unmock('nunjucks'); -jest.unmock('redux-thunk'); -jest.unmock('redux-mock-store'); // Jest seems to barf when this isn't here jest.unmock('request'); diff --git a/app/actions/requests.js b/app/actions/requests.js index 2b05dd1aa..68a00d69c 100644 --- a/app/actions/requests.js +++ b/app/actions/requests.js @@ -1,6 +1,6 @@ import * as types from '../constants/actionTypes' import * as methods from '../constants/global' -import makeRequest from '../lib/request.electron' +import makeRequest from '../lib/request' import {loadStart, loadStop} from './global' import {showModal} from './modals' import {REQUEST_RENAME} from '../constants/modals' @@ -93,7 +93,7 @@ export function sendRequest (request) { if (err) { console.error(err); } - + dispatch(setResponse(request.id, response)); dispatch(loadStop()); }); diff --git a/app/components/base/Modal.js b/app/components/base/Modal.js index f7a53ba80..7c7892103 100644 --- a/app/components/base/Modal.js +++ b/app/components/base/Modal.js @@ -1,36 +1,6 @@ -import React, {Component, PropTypes} from 'react'; -import classnames from 'classnames'; - -const ModalHeader = (props) => ( -
-
-
-
- {props.children} -
-
-
- -
-
-
-); - -const ModalBody = (props) => ( -
- {props.children} -
-); - -const ModalFooter = (props) => ( -
-
- {props.children} -
-
-); +import React, {Component, PropTypes} from 'react' +import classnames from 'classnames' +import * as ModalActions from '../../actions/modals' class Modal extends Component { _handleClick (e) { @@ -70,7 +40,7 @@ class Modal extends Component { } componentDidMount () { - this.refs.modal.focus(); + this.refs.modal && this.refs.modal.focus(); } render () { @@ -80,7 +50,8 @@ class Modal extends Component { className={classnames('modal', 'grid', 'grid--center', this.props.className)} onKeyDown={this._keyDown.bind(this)} onClick={this._handleClick.bind(this)}> -
+
{this.props.children}
@@ -93,4 +64,5 @@ Modal.propTypes = { tall: PropTypes.bool }; -export {Modal, ModalHeader, ModalBody, ModalFooter}; +export default Modal; + diff --git a/app/components/base/ModalBody.js b/app/components/base/ModalBody.js new file mode 100644 index 000000000..ef8de94e4 --- /dev/null +++ b/app/components/base/ModalBody.js @@ -0,0 +1,10 @@ +import React from 'react'; +import classnames from 'classnames'; + +const ModalBody = (props) => ( +
+ {props.children} +
+); + +export default ModalBody; diff --git a/app/components/base/ModalFooter.js b/app/components/base/ModalFooter.js new file mode 100644 index 000000000..7dedb7fa4 --- /dev/null +++ b/app/components/base/ModalFooter.js @@ -0,0 +1,11 @@ +import React from 'react'; + +const ModalFooter = (props) => ( +
+
+ {props.children} +
+
+); + +export default ModalFooter; diff --git a/app/components/base/ModalHeader.js b/app/components/base/ModalHeader.js new file mode 100644 index 000000000..d145cdb20 --- /dev/null +++ b/app/components/base/ModalHeader.js @@ -0,0 +1,20 @@ +import React from 'react'; + +const ModalHeader = (props) => ( +
+
+
+
+ {props.children} +
+
+
+ +
+
+
+); + +export default ModalHeader; diff --git a/app/components/base/PromptModal.js b/app/components/base/PromptModal.js index 7efcff3fb..002b544fe 100644 --- a/app/components/base/PromptModal.js +++ b/app/components/base/PromptModal.js @@ -1,5 +1,8 @@ -import React, {Component, PropTypes} from 'react'; -import {Modal, ModalHeader, ModalBody, ModalFooter} from './Modal' +import React, {Component, PropTypes} from 'react' +import Modal from './Modal' +import ModalBody from './ModalBody' +import ModalHeader from './ModalHeader' +import ModalFooter from './ModalFooter' class PromptModal extends Component { _onSubmit (e) { @@ -29,9 +32,9 @@ class PromptModal extends Component { } render () { - const {onClose, submitName, headerName} = this.props; + const {onClose, submitName, headerName, ...extraProps} = this.props; return ( - + {headerName}
diff --git a/app/components/modals/EnvironmentEditModal.js b/app/components/modals/EnvironmentEditModal.js deleted file mode 100644 index be9b6d9f5..000000000 --- a/app/components/modals/EnvironmentEditModal.js +++ /dev/null @@ -1,44 +0,0 @@ -import React, {Component, PropTypes} from 'react' -import {Modal, ModalHeader, ModalBody, ModalFooter} from '../base/Modal' -import Editor from '../base/Editor' -import KeyValueEditor from '../base/KeyValueEditor' -import * as modalIds from '../../constants/modals' - -class EnvironmentEditModal extends Component { - render () { - const editorOptions = { - mode: 'application/json', - placeholder: '{ "array": [1, 2, 3, 4] }', - theme: 'neat' - }; - - return ( - - Environment Variables - -
- {}} - pairs={[{name: 'foo', value: 'hello'}]} - namePlaceholder="BASE_URL" - valuePlaceholder="https://api.insomnia.com/v1"/> -
- {/* -

Hello

- - */} -
- - - -
- ); - } -} - -EnvironmentEditModal.propTypes = {}; - -EnvironmentEditModal.defaultProps = { - id: modalIds.ENVIRONMENT_EDITOR -}; - -export default EnvironmentEditModal; diff --git a/app/components/modals/ModalContainer.js b/app/components/modals/Prompts.js similarity index 52% rename from app/components/modals/ModalContainer.js rename to app/components/modals/Prompts.js index ab3f3612b..f98073b44 100644 --- a/app/components/modals/ModalContainer.js +++ b/app/components/modals/Prompts.js @@ -7,14 +7,10 @@ import * as RequestGroupActions from '../../actions/requestGroups' import * as RequestActions from '../../actions/requests' import * as modalIds from '../../constants/modals' import PromptModal from '../base/PromptModal' -import EnvironmentEditModal from './EnvironmentEditModal' -class Modals extends Component { +class Prompts extends Component { constructor (props) { super(props); - this._modals = [ - EnvironmentEditModal - ]; this._prompts = {}; this._prompts[modalIds.REQUEST_RENAME] = { header: 'Rename Request', @@ -37,53 +33,33 @@ class Modals extends Component { const {modals, actions} = this.props; return ( -
-
- {Object.keys(this._prompts).map(id => { - const promptDef = this._prompts[id]; - const modal = modals.find(m => m.id === id); +
+ {Object.keys(this._prompts).map(id => { + const promptDef = this._prompts[id]; + const modal = modals.find(m => m.id === id); - if (!modal) { - return null; - } + if (!modal) { + return null; + } - return ( - actions.hideModal(modal.id)} - onSubmit={value => promptDef.onSubmit(modal, value)} - /> - ) - })} -
-
- {this._modals.map(c => { - const id = c.defaultProps.id; - const isVisible = modals.find(m => m.id === id); - const modal = React.createElement(c, { - key: id, - onClose: () => actions.hideModal(id) - }); - return isVisible ? modal : null; - })} -
-
- {/*
-
Request deleted
- -
*/} -
+ return ( + actions.hideModal(modal.id)} + onSubmit={value => promptDef.onSubmit(modal, value)} + /> + ) + })}
); } } -Modals.propTypes = { +Prompts.propTypes = { actions: PropTypes.shape({ hideModal: PropTypes.func.isRequired, updateRequestGroup: PropTypes.func.isRequired, @@ -113,5 +89,5 @@ function mapDispatchToProps (dispatch) { export default connect( mapStateToProps, mapDispatchToProps -)(Modals); +)(Prompts); diff --git a/app/components/modals/RequestGroupEnvironmentEditModal.js b/app/components/modals/RequestGroupEnvironmentEditModal.js new file mode 100644 index 000000000..4bcd37810 --- /dev/null +++ b/app/components/modals/RequestGroupEnvironmentEditModal.js @@ -0,0 +1,65 @@ +import React, {Component, PropTypes} from 'react' +import Modal from '../base/Modal' +import ModalBody from '../base/ModalBody' +import ModalHeader from '../base/ModalHeader' +import ModalFooter from '../base/ModalFooter' +import Editor from '../base/Editor' +import KeyValueEditor from '../base/KeyValueEditor' +import * as modalIds from '../../constants/modals' + +class RequestGroupEnvironmentEditModal extends Component { + constructor (props) { + super(props); + this.state = { + pairs: [] + } + } + + _saveChanges () { + this.props.onChange(this.state.pairs); + } + + _keyValueChange (pairs) { + this.setState({pairs}); + } + + render () { + const editorOptions = { + mode: 'application/json', + placeholder: '{ "array": [1, 2, 3, 4] }', + theme: 'neat' + }; + + return ( + + Environment Variables + +
+ +
+ {/* +

Hello

+ + */} +
+ + + +
+ ); + } +} + +RequestGroupEnvironmentEditModal.propTypes = { + // requestGroup: PropTypes.object.isRequired, + onChange: PropTypes.func.isRequired +}; + +RequestGroupEnvironmentEditModal.defaultProps = { + id: modalIds.ENVIRONMENT_EDITOR +}; + +export default RequestGroupEnvironmentEditModal; diff --git a/app/containers/App.js b/app/containers/App.js index 152a56a5d..3b6adde7b 100644 --- a/app/containers/App.js +++ b/app/containers/App.js @@ -4,17 +4,19 @@ import {bindActionCreators} from 'redux' import {Tab, Tabs, TabList, TabPanel} from 'react-tabs' import Editor from '../components/base/Editor' -import Modals from '../components/modals/ModalContainer' +import Prompts from '../components/modals/Prompts' import KeyValueEditor from '../components/base/KeyValueEditor' import RequestBodyEditor from '../components/RequestBodyEditor' import RequestAuthEditor from '../components/RequestAuthEditor' import RequestUrlBar from '../components/RequestUrlBar' import Sidebar from '../components/Sidebar' +import RequestGroupEnvironmentEditModal from '../components/modals/RequestGroupEnvironmentEditModal' import * as GlobalActions from '../actions/global' import * as RequestGroupActions from '../actions/requestGroups' import * as RequestActions from '../actions/requests' import * as ResponseActions from '../actions/responses' +import * as ModalActions from '../actions/modals' // Don't inject component styles (use our own) Tabs.setUseDefaultStyles(false); @@ -144,13 +146,19 @@ class App extends Component { } render () { - const {actions, requests, responses, requestGroups, tabs} = this.props; + const {actions, requests, responses, requestGroups, tabs, modals} = this.props; const activeRequest = requests.all.find(r => r.id === requests.active); const activeResponse = responses[activeRequest && activeRequest.id]; return (
- + + {!modals.find(m => m.id === RequestGroupEnvironmentEditModal.defaultProps.id) ? null : ( + actions.hideModal(RequestGroupEnvironmentEditModal.defaultProps.id)} + onChange={v => console.log(v)} + /> + )} /node_modules/redux-thunk", + "/node_modules/redux-mock-store", + "/node_modules/nunjucks", + "/node_modules/jsonschema", "/node_modules/react", "/node_modules/react-dom", "/node_modules/react-addons-test-utils" + ], + "testFileExtensions": [ + "test.js" + ], + "moduleFileExtensions": [ + "js", + "electron.js", + "chrome.js" ] } } diff --git a/webpack/dev.electron.config.js b/webpack/dev.electron.config.js index 73b053112..86871e485 100644 --- a/webpack/dev.electron.config.js +++ b/webpack/dev.electron.config.js @@ -37,7 +37,8 @@ base.plugins = [ base.target = webpackTargetElectronRenderer(base); -base.resolve.extensions.push('electron.js'); +base.resolve.extensions.push('.electron.js'); +console.log(base); module.exports = base;