2016-03-20 04:47:43 +00:00
|
|
|
import React, {Component, PropTypes} from 'react'
|
|
|
|
import {connect} from 'react-redux'
|
|
|
|
import {bindActionCreators} from 'redux'
|
2016-03-22 03:22:45 +00:00
|
|
|
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
|
2016-03-20 04:47:43 +00:00
|
|
|
|
2016-03-23 05:58:16 +00:00
|
|
|
import Editor from '../components/base/Editor'
|
2016-04-08 04:05:08 +00:00
|
|
|
import PromptModal from '../components/base/PromptModal'
|
2016-04-09 01:14:25 +00:00
|
|
|
import KeyValueEditor from '../components/base/KeyValueEditor'
|
2016-03-22 05:01:58 +00:00
|
|
|
import RequestBodyEditor from '../components/RequestBodyEditor'
|
2016-03-22 18:20:05 +00:00
|
|
|
import RequestUrlBar from '../components/RequestUrlBar'
|
2016-03-20 04:47:43 +00:00
|
|
|
import Sidebar from '../components/Sidebar'
|
2016-04-07 03:09:14 +00:00
|
|
|
import {Modal, ModalHeader, ModalBody, ModalFooter} from '../components/base/Modal'
|
2016-03-20 04:47:43 +00:00
|
|
|
|
|
|
|
import * as RequestActions from '../actions/requests'
|
2016-04-04 07:15:30 +00:00
|
|
|
import * as RequestGroupActions from '../actions/requestGroups'
|
2016-03-20 04:47:43 +00:00
|
|
|
import * as GlobalActions from '../actions/global'
|
|
|
|
|
2016-03-22 03:22:45 +00:00
|
|
|
// Don't inject component styles (use our own)
|
|
|
|
Tabs.setUseDefaultStyles(false);
|
|
|
|
|
2016-03-20 04:47:43 +00:00
|
|
|
class App extends Component {
|
2016-03-22 05:01:58 +00:00
|
|
|
renderPageBody (actions, activeRequest) {
|
2016-03-20 20:42:27 +00:00
|
|
|
|
2016-03-22 03:22:45 +00:00
|
|
|
if (!activeRequest) {
|
|
|
|
return <div></div>;
|
|
|
|
}
|
|
|
|
|
2016-03-20 20:42:27 +00:00
|
|
|
return (
|
2016-04-06 04:21:42 +00:00
|
|
|
<div className="grid__cell grid grid-collapse">
|
2016-04-06 16:50:11 +00:00
|
|
|
<section className="grid__cell grid--v section">
|
|
|
|
<div className="grid__cell grid__cell--no-flex section__header">
|
2016-04-06 07:19:36 +00:00
|
|
|
<RequestUrlBar
|
2016-04-08 04:05:08 +00:00
|
|
|
onUrlChange={url => {actions.updateRequest({id: activeRequest.id, url})}}
|
|
|
|
onMethodChange={method => {actions.updateRequest({id: activeRequest.id, method})}}
|
2016-04-06 07:19:36 +00:00
|
|
|
request={activeRequest}/>
|
|
|
|
</div>
|
2016-04-06 16:50:11 +00:00
|
|
|
<Tabs selectedIndex={0} className="grid__cell grid--v section__body">
|
2016-04-06 04:21:42 +00:00
|
|
|
<TabList className="grid grid--start">
|
2016-04-06 07:19:36 +00:00
|
|
|
<Tab><button className="btn btn--compact">Body</button></Tab>
|
|
|
|
<Tab><button className="btn btn--compact">Params</button></Tab>
|
|
|
|
<Tab><button className="btn btn--compact">Auth</button></Tab>
|
|
|
|
<Tab><button className="btn btn--compact">Headers</button></Tab>
|
2016-04-06 04:21:42 +00:00
|
|
|
</TabList>
|
|
|
|
<TabPanel className="grid__cell relative">
|
|
|
|
<RequestBodyEditor
|
2016-04-08 04:05:08 +00:00
|
|
|
onChange={body => {actions.updateRequest({id: activeRequest.id, body})}}
|
2016-04-06 04:21:42 +00:00
|
|
|
request={activeRequest}/>
|
|
|
|
</TabPanel>
|
2016-04-09 01:14:25 +00:00
|
|
|
<TabPanel className="grid__cell">
|
|
|
|
<KeyValueEditor
|
|
|
|
pairs={activeRequest.params}
|
|
|
|
onChange={params => actions.updateRequest({id: activeRequest.id, params})}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
2016-04-06 04:21:42 +00:00
|
|
|
<TabPanel className="grid__cell pad">Basic Auth</TabPanel>
|
2016-04-09 01:14:25 +00:00
|
|
|
<TabPanel className="grid__cell">
|
|
|
|
Hello
|
|
|
|
</TabPanel>
|
2016-04-06 04:21:42 +00:00
|
|
|
</Tabs>
|
2016-03-22 03:22:45 +00:00
|
|
|
</section>
|
2016-04-06 16:50:11 +00:00
|
|
|
<section className="grid__cell grid--v section">
|
|
|
|
<header className="grid grid--center header text-center bg-light txt-sm section__header">
|
2016-04-06 04:21:42 +00:00
|
|
|
<div className="tag success"><strong>200</strong> SUCCESS</div>
|
|
|
|
<div className="tag">TIME <strong>143ms</strong></div>
|
|
|
|
</header>
|
2016-04-06 16:50:11 +00:00
|
|
|
<Tabs selectedIndex={0} className="grid__cell grid--v section__body">
|
2016-04-06 04:21:42 +00:00
|
|
|
<TabList className="grid grid--start">
|
2016-04-09 01:14:25 +00:00
|
|
|
<Tab><button className="btn btn--compact">Preview</button></Tab>
|
2016-04-06 07:19:36 +00:00
|
|
|
<Tab><button className="btn btn--compact">Raw</button></Tab>
|
|
|
|
<Tab><button className="btn btn--compact">Headers</button></Tab>
|
2016-04-06 04:21:42 +00:00
|
|
|
</TabList>
|
|
|
|
<TabPanel className="grid__cell">
|
|
|
|
<Editor
|
|
|
|
options={{
|
|
|
|
mode: 'application/json',
|
|
|
|
readOnly: true,
|
|
|
|
placeholder: 'nothing yet...'
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
2016-04-06 07:19:36 +00:00
|
|
|
<TabPanel className="grid__cell">
|
2016-04-06 04:21:42 +00:00
|
|
|
<Editor
|
|
|
|
options={{
|
|
|
|
mode: 'application/json',
|
|
|
|
readOnly: true,
|
|
|
|
placeholder: 'nothing yet...'
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
2016-04-06 07:19:36 +00:00
|
|
|
<TabPanel className="pad grid__cell">Headers</TabPanel>
|
2016-04-06 04:21:42 +00:00
|
|
|
</Tabs>
|
2016-03-22 03:22:45 +00:00
|
|
|
</section>
|
|
|
|
</div>
|
2016-03-20 04:47:43 +00:00
|
|
|
)
|
|
|
|
}
|
2016-03-22 05:01:58 +00:00
|
|
|
|
2016-03-20 04:47:43 +00:00
|
|
|
render () {
|
2016-04-08 04:05:08 +00:00
|
|
|
const {actions, loading, requests, requestGroups, prompt} = this.props;
|
2016-03-22 05:01:58 +00:00
|
|
|
const activeRequest = requests.all.find(r => r.id === requests.active);
|
2016-03-22 03:22:45 +00:00
|
|
|
|
2016-03-20 04:47:43 +00:00
|
|
|
return (
|
2016-04-05 20:49:28 +00:00
|
|
|
<div className="grid bg-super-dark tall">
|
2016-04-07 03:27:45 +00:00
|
|
|
<Modal visible={false} ref="modal">
|
2016-04-07 03:09:14 +00:00
|
|
|
<ModalHeader>Header</ModalHeader>
|
|
|
|
<ModalBody>
|
|
|
|
<p>Hello</p>
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>Footer</ModalFooter>
|
|
|
|
</Modal>
|
2016-04-08 04:05:08 +00:00
|
|
|
{!prompt ? null : (
|
|
|
|
<PromptModal
|
|
|
|
headerName="Rename Request"
|
2016-04-09 01:14:25 +00:00
|
|
|
submitName="Rename"
|
2016-04-08 04:05:08 +00:00
|
|
|
visible={true}
|
|
|
|
onClose={() => actions.hidePrompt(prompt.id)}
|
|
|
|
onSubmit={name => actions.updateRequest({id: prompt.data.id, name})}/>
|
|
|
|
)}
|
2016-03-20 04:47:43 +00:00
|
|
|
<Sidebar
|
|
|
|
activateRequest={actions.activateRequest}
|
2016-03-23 05:26:27 +00:00
|
|
|
changeFilter={actions.changeFilter}
|
2016-03-20 04:47:43 +00:00
|
|
|
addRequest={actions.addRequest}
|
2016-04-04 07:15:30 +00:00
|
|
|
toggleRequestGroup={actions.toggleRequestGroup}
|
2016-04-07 03:09:14 +00:00
|
|
|
deleteRequestGroup={actions.deleteRequestGroup}
|
2016-03-20 23:20:00 +00:00
|
|
|
activeRequest={activeRequest}
|
2016-03-23 05:26:27 +00:00
|
|
|
activeFilter={requests.filter}
|
2016-03-22 05:01:58 +00:00
|
|
|
loading={loading}
|
2016-03-24 10:20:11 +00:00
|
|
|
requestGroups={requestGroups.all}
|
2016-03-22 05:01:58 +00:00
|
|
|
requests={requests.all}/>
|
2016-04-05 20:49:28 +00:00
|
|
|
<div className="grid__cell grid--v">
|
2016-04-06 07:19:36 +00:00
|
|
|
{/*<header className="header bg-light">
|
2016-04-07 03:09:14 +00:00
|
|
|
<div className="header__content"><h1>Hi World</h1></div>
|
|
|
|
</header>*/}
|
2016-04-06 04:21:42 +00:00
|
|
|
{this.renderPageBody(actions, activeRequest)}
|
2016-03-21 05:47:49 +00:00
|
|
|
</div>
|
2016-03-20 04:47:43 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
App.propTypes = {
|
2016-03-22 05:01:58 +00:00
|
|
|
actions: PropTypes.shape({
|
|
|
|
activateRequest: PropTypes.func.isRequired,
|
2016-04-07 03:09:14 +00:00
|
|
|
deleteRequestGroup: PropTypes.func.isRequired,
|
|
|
|
addRequest: PropTypes.func.isRequired,
|
2016-04-08 04:05:08 +00:00
|
|
|
updateRequest: PropTypes.func.isRequired,
|
2016-03-23 05:26:27 +00:00
|
|
|
changeFilter: PropTypes.func.isRequired,
|
2016-04-04 07:15:30 +00:00
|
|
|
updateRequestMethod: PropTypes.func.isRequired,
|
|
|
|
toggleRequestGroup: PropTypes.func.isRequired
|
2016-03-22 05:01:58 +00:00
|
|
|
}).isRequired,
|
|
|
|
requests: PropTypes.shape({
|
|
|
|
all: PropTypes.array.isRequired,
|
|
|
|
active: PropTypes.string // "required" but can be null
|
|
|
|
}).isRequired,
|
2016-03-24 10:20:11 +00:00
|
|
|
requestGroups: PropTypes.shape({
|
2016-04-04 07:15:30 +00:00
|
|
|
all: PropTypes.array.isRequired
|
2016-03-24 10:20:11 +00:00
|
|
|
}).isRequired,
|
2016-04-08 04:05:08 +00:00
|
|
|
loading: PropTypes.bool.isRequired,
|
|
|
|
prompt: PropTypes.object
|
2016-03-20 04:47:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
actions: state.actions,
|
2016-03-22 05:01:58 +00:00
|
|
|
requests: state.requests,
|
2016-03-24 10:20:11 +00:00
|
|
|
requestGroups: state.requestGroups,
|
2016-04-08 04:05:08 +00:00
|
|
|
loading: state.loading,
|
|
|
|
prompt: state.prompt
|
2016-03-20 04:47:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
|
|
|
actions: Object.assign(
|
|
|
|
{},
|
|
|
|
bindActionCreators(GlobalActions, dispatch),
|
2016-04-04 07:15:30 +00:00
|
|
|
bindActionCreators(RequestActions, dispatch),
|
2016-04-05 06:08:03 +00:00
|
|
|
bindActionCreators(RequestGroupActions, dispatch)
|
2016-03-20 04:47:43 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(App);
|
|
|
|
|