insomnia/app/ui/components/viewers/response-cookies-viewer.js
Gregory Schier 75fbf60274 A bunch more smaller things for v5 (#124)
* Use Curl constants for info

* Extra timeline info and cookie url encoding setting

* Add warning to environment selector

* Title attribute on the autocomplete types

* Added test
2017-03-29 16:09:28 -07:00

86 lines
2.3 KiB
JavaScript

import React, {PropTypes, PureComponent} from 'react';
import autobind from 'autobind-decorator';
import {Cookie} from 'tough-cookie';
@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>;
return (
<tr className="selectable" key={i}>
<td>{cookie ? cookie.key : blank}</td>
<td className="force-wrap">{cookie ? cookie.value : blank}</td>
</tr>
);
}
render () {
const {
headers,
showCookiesModal,
handleShowRequestSettings,
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>
{noticeMessage ? (
<div className="notice info margin-bottom no-margin-top">
<p>
Automatic {noticeMessage} of cookies was disabled for this request
</p>
<button className="btn btn--clicky-small margin-top-sm"
onClick={handleShowRequestSettings}>
Open Settings
</button>
</div>
) : null}
<table className="table--fancy table--striped">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{!headers.length
? this.renderRow(null, -1)
: headers.map(this.renderRow)
}
</tbody>
</table>
<p className="pad-top">
<button className="pull-right btn btn--clicky"
onClick={e => showCookiesModal()}>
Manage Cookies
</button>
</p>
</div>
);
}
}
ResponseCookiesViewer.propTypes = {
showCookiesModal: PropTypes.func.isRequired,
cookiesSent: PropTypes.bool.isRequired,
cookiesStored: PropTypes.bool.isRequired,
headers: PropTypes.array.isRequired,
handleShowRequestSettings: PropTypes.func.isRequired
};
export default ResponseCookiesViewer;