2017-03-29 23:09:28 +00:00
|
|
|
import React, {PropTypes, PureComponent} from 'react';
|
|
|
|
import autobind from 'autobind-decorator';
|
2016-08-15 17:04:36 +00:00
|
|
|
import {Cookie} from 'tough-cookie';
|
|
|
|
|
2017-03-29 23:09:28 +00:00
|
|
|
@autobind
|
|
|
|
class ResponseCookiesViewer extends PureComponent {
|
|
|
|
renderRow (h, i) {
|
|
|
|
const cookie = h ? Cookie.parse(h.value) : null;
|
|
|
|
const blank = <span className="super-duper-faint italic">--</span>;
|
2016-09-21 00:18:18 +00:00
|
|
|
return (
|
2017-03-29 23:09:28 +00:00
|
|
|
<tr className="selectable" key={i}>
|
|
|
|
<td>{cookie ? cookie.key : blank}</td>
|
|
|
|
<td className="force-wrap">{cookie ? cookie.value : blank}</td>
|
|
|
|
</tr>
|
2016-09-21 00:18:18 +00:00
|
|
|
);
|
2016-08-15 17:04:36 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 23:09:28 +00:00
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
headers,
|
|
|
|
showCookiesModal,
|
|
|
|
cookiesSent,
|
|
|
|
cookiesStored
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const notifyNotStored = !cookiesStored && headers.length;
|
|
|
|
|
|
|
|
let noticeMessage = null;
|
|
|
|
if (!cookiesSent && notifyNotStored) {
|
|
|
|
noticeMessage = 'sending and storing';
|
|
|
|
} else if (!cookiesSent) {
|
|
|
|
noticeMessage = 'sending';
|
|
|
|
} else if (notifyNotStored) {
|
|
|
|
noticeMessage = 'storing';
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2017-05-17 19:02:09 +00:00
|
|
|
{noticeMessage && (
|
2017-03-29 23:09:28 +00:00
|
|
|
<div className="notice info margin-bottom no-margin-top">
|
|
|
|
<p>
|
2017-03-30 18:52:07 +00:00
|
|
|
Automatic {noticeMessage} of cookies was disabled at the time this request was made
|
2017-03-29 23:09:28 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2017-05-17 19:02:09 +00:00
|
|
|
)}
|
2017-03-29 23:09:28 +00:00
|
|
|
|
|
|
|
<table className="table--fancy table--striped">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Value</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2017-05-17 19:02:09 +00:00
|
|
|
{!headers.length ? this.renderRow(null, -1) : headers.map(this.renderRow)}
|
2017-03-29 23:09:28 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<p className="pad-top">
|
|
|
|
<button className="pull-right btn btn--clicky"
|
|
|
|
onClick={e => showCookiesModal()}>
|
|
|
|
Manage Cookies
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-08-15 17:04:36 +00:00
|
|
|
|
|
|
|
ResponseCookiesViewer.propTypes = {
|
|
|
|
showCookiesModal: PropTypes.func.isRequired,
|
2017-03-29 23:09:28 +00:00
|
|
|
cookiesSent: PropTypes.bool.isRequired,
|
|
|
|
cookiesStored: PropTypes.bool.isRequired,
|
|
|
|
headers: PropTypes.array.isRequired,
|
|
|
|
handleShowRequestSettings: PropTypes.func.isRequired
|
2016-08-15 17:04:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponseCookiesViewer;
|