2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-07-17 18:20:38 +00:00
|
|
|
import {Dropdown, DropdownButton, DropdownDivider, DropdownItem} from '../base/dropdown';
|
2017-03-08 05:52:17 +00:00
|
|
|
import SizeTag from '../tags/size-tag';
|
|
|
|
import StatusTag from '../tags/status-tag';
|
|
|
|
import TimeTag from '../tags/time-tag';
|
|
|
|
import PromptButton from '../base/prompt-button';
|
2016-12-05 22:42:40 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2016-11-27 21:42:38 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-02-28 21:32:23 +00:00
|
|
|
class ResponseHistoryDropdown extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleDeleteResponses () {
|
2016-12-05 22:42:40 +00:00
|
|
|
trackEvent('History', 'Delete Responses');
|
2016-11-27 21:42:38 +00:00
|
|
|
this.props.handleDeleteResponses(this.props.requestId);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-27 21:42:38 +00:00
|
|
|
|
2017-06-12 21:48:17 +00:00
|
|
|
_handleDeleteResponse () {
|
|
|
|
trackEvent('History', 'Delete Response');
|
2017-07-17 18:20:38 +00:00
|
|
|
this.props.handleDeleteResponse(this.props.activeResponse);
|
2017-06-12 21:48:17 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 18:20:38 +00:00
|
|
|
_handleSetActiveResponse (response) {
|
2016-12-05 22:42:40 +00:00
|
|
|
trackEvent('History', 'Activate Response');
|
2017-07-17 18:20:38 +00:00
|
|
|
this.props.handleSetActiveResponse(response);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-27 21:42:38 +00:00
|
|
|
|
|
|
|
componentWillUnmount () {
|
2017-03-06 17:51:58 +00:00
|
|
|
clearTimeout(this._interval);
|
2016-11-27 21:42:38 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
renderDropdownItem (response, i) {
|
2017-07-17 18:20:38 +00:00
|
|
|
const {activeResponse} = this.props;
|
|
|
|
const activeResponseId = activeResponse ? activeResponse._id : 'n/a';
|
2016-11-27 21:42:38 +00:00
|
|
|
const active = response._id === activeResponseId;
|
2017-06-12 21:49:46 +00:00
|
|
|
const message = 'Request will not be restored with this response because ' +
|
|
|
|
'it was created before this ability was added';
|
2017-07-17 18:20:38 +00:00
|
|
|
|
2016-11-27 21:42:38 +00:00
|
|
|
return (
|
|
|
|
<DropdownItem key={response._id}
|
|
|
|
disabled={active}
|
2017-07-17 18:20:38 +00:00
|
|
|
value={i === 0 ? null : response}
|
2016-12-05 22:42:40 +00:00
|
|
|
onClick={this._handleSetActiveResponse}>
|
2016-11-27 21:42:38 +00:00
|
|
|
{active ? <i className="fa fa-thumb-tack"/> : <i className="fa fa-empty"/>}
|
2017-03-03 20:09:08 +00:00
|
|
|
{' '}
|
2017-06-14 18:27:30 +00:00
|
|
|
<StatusTag
|
|
|
|
small
|
|
|
|
statusCode={response.statusCode}
|
|
|
|
statusMessage={response.statusMessage || null}
|
|
|
|
/>
|
2017-03-01 21:15:56 +00:00
|
|
|
<TimeTag milliseconds={response.elapsedTime} small/>
|
2017-08-11 21:44:34 +00:00
|
|
|
<SizeTag bytesRead={response.bytesRead} bytesContent={response.bytesContent} small/>
|
2017-06-12 21:49:46 +00:00
|
|
|
{!response.requestVersionId && <i className="icon fa fa-info-circle" title={message}/>}
|
2016-11-27 21:42:38 +00:00
|
|
|
</DropdownItem>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-27 21:42:38 +00:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const {
|
2017-07-17 18:20:38 +00:00
|
|
|
activeResponse, // eslint-disable-line no-unused-vars
|
2017-03-03 20:09:08 +00:00
|
|
|
handleSetActiveResponse, // eslint-disable-line no-unused-vars
|
|
|
|
handleDeleteResponses, // eslint-disable-line no-unused-vars
|
2017-06-12 21:48:17 +00:00
|
|
|
handleDeleteResponse, // eslint-disable-line no-unused-vars
|
2017-07-17 18:20:38 +00:00
|
|
|
responses,
|
2016-11-27 21:42:38 +00:00
|
|
|
...extraProps
|
|
|
|
} = this.props;
|
2017-06-12 21:48:17 +00:00
|
|
|
|
2017-07-17 18:20:38 +00:00
|
|
|
const isLatestResponseActive = !responses.length || activeResponse._id === responses[0]._id;
|
2016-11-27 21:42:38 +00:00
|
|
|
|
|
|
|
return (
|
2017-07-17 18:20:38 +00:00
|
|
|
<Dropdown key={activeResponse ? activeResponse._id : 'n/a'} {...extraProps}>
|
2016-11-27 21:42:38 +00:00
|
|
|
<DropdownButton className="btn btn--super-compact tall">
|
2017-03-03 20:09:08 +00:00
|
|
|
{isLatestResponseActive
|
|
|
|
? <i className="fa fa-history"/>
|
|
|
|
: <i className="fa fa-thumb-tack"/>}
|
2016-11-27 21:42:38 +00:00
|
|
|
</DropdownButton>
|
2016-12-21 23:37:48 +00:00
|
|
|
<DropdownDivider>Response History</DropdownDivider>
|
2017-06-12 21:48:17 +00:00
|
|
|
<DropdownItem buttonClass={PromptButton}
|
|
|
|
addIcon
|
|
|
|
onClick={this._handleDeleteResponse}>
|
|
|
|
<i className="fa fa-trash-o"/>
|
|
|
|
Delete Current Response
|
|
|
|
</DropdownItem>
|
2016-11-27 21:42:38 +00:00
|
|
|
<DropdownItem buttonClass={PromptButton}
|
2017-03-01 21:15:56 +00:00
|
|
|
addIcon
|
2016-11-27 21:42:38 +00:00
|
|
|
onClick={this._handleDeleteResponses}>
|
|
|
|
<i className="fa fa-trash-o"/>
|
|
|
|
Clear History
|
|
|
|
</DropdownItem>
|
2016-12-21 23:37:48 +00:00
|
|
|
<DropdownDivider>Past Responses</DropdownDivider>
|
2016-11-27 21:42:38 +00:00
|
|
|
{responses.map(this.renderDropdownItem)}
|
|
|
|
</Dropdown>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2016-11-27 21:42:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseHistoryDropdown.propTypes = {
|
|
|
|
handleSetActiveResponse: PropTypes.func.isRequired,
|
|
|
|
handleDeleteResponses: PropTypes.func.isRequired,
|
2017-06-12 21:48:17 +00:00
|
|
|
handleDeleteResponse: PropTypes.func.isRequired,
|
2016-11-27 21:42:38 +00:00
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
requestId: PropTypes.string.isRequired,
|
2017-07-17 18:20:38 +00:00
|
|
|
responses: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
|
|
|
|
// Optional
|
|
|
|
activeResponse: PropTypes.object
|
2016-11-27 21:42:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponseHistoryDropdown;
|