insomnia/app/components/SidebarRequestRow.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-07-08 06:02:40 +00:00
import React, {PropTypes, Component} from 'react'
2016-05-01 19:56:30 +00:00
import classnames from 'classnames'
2016-07-08 06:02:40 +00:00
import RequestActionsDropdown from '../containers/RequestActionsDropdown'
import Editable from './base/Editable'
import MethodTag from './MethodTag'
2016-06-18 21:31:17 +00:00
import * as db from '../database'
2016-07-08 06:02:40 +00:00
2016-05-01 19:56:30 +00:00
const SidebarRequestRow = ({request, requestGroup, isActive, activateRequest}) => {
if (!request) {
return (
<li className="sidebar__item">
2016-07-08 06:02:40 +00:00
<button className="sidebar__clickable" onClick={() => db.requestCreate({parentId: requestGroup._id})}>
2016-06-18 21:31:17 +00:00
<em>click to add first request...</em>
</button>
2016-05-01 19:56:30 +00:00
</li>
)
}
return (
<li className="sidebar__row">
<div className={classnames('sidebar__item', {active: isActive})}>
2016-07-08 06:02:40 +00:00
<button onClick={() => {activateRequest(request)}}>
<div className="sidebar__clickable">
<MethodTag method={request.method}/>
<Editable
value={request.name}
onSubmit={name => db.requestUpdate(request, {name})}
/>
</div>
2016-05-01 19:56:30 +00:00
</button>
<div className="sidebar__actions">
<RequestActionsDropdown
right={true}
request={request}
requestGroup={requestGroup}
/>
</div>
2016-04-29 03:37:49 +00:00
</div>
2016-05-01 19:56:30 +00:00
</li>
)
};
SidebarRequestRow.propTypes = {
// Functions
activateRequest: PropTypes.func.isRequired,
2016-04-29 03:37:49 +00:00
// Other
isActive: PropTypes.bool.isRequired,
2016-04-29 03:37:49 +00:00
// Optional
requestGroup: PropTypes.object,
request: PropTypes.object
};
export default SidebarRequestRow;