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';
|
2016-08-15 17:04:36 +00:00
|
|
|
import {Cookie} from 'tough-cookie';
|
|
|
|
|
2017-08-19 22:34:16 +00:00
|
|
|
import {cookieToString} from '../../common/cookies';
|
|
|
|
import PromptButton from './base/prompt-button';
|
2017-08-22 22:30:57 +00:00
|
|
|
import RenderedText from './rendered-text';
|
2016-08-15 17:04:36 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-08-19 22:34:16 +00:00
|
|
|
class CookieList extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleCookieAdd () {
|
2016-08-15 17:04:36 +00:00
|
|
|
const newCookie = new Cookie({
|
|
|
|
key: 'foo',
|
|
|
|
value: 'bar',
|
|
|
|
domain: this.props.newCookieDomainName,
|
2017-08-19 22:34:16 +00:00
|
|
|
path: '/',
|
|
|
|
secure: false,
|
|
|
|
httpOnly: false
|
2016-08-15 17:04:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.props.onCookieAdd(newCookie);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-29 22:28:55 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
_handleDeleteCookie (cookie) {
|
|
|
|
this.props.onCookieDelete(cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-08-19 22:34:16 +00:00
|
|
|
const {
|
|
|
|
cookies,
|
2017-08-22 22:30:57 +00:00
|
|
|
handleShowModifyCookieModal,
|
|
|
|
handleRender
|
2017-08-19 22:34:16 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2017-08-19 22:34:16 +00:00
|
|
|
<table className="table--fancy cookie-table table--striped">
|
2016-08-15 17:04:36 +00:00
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th style={{minWidth: '10rem'}}>Domain</th>
|
|
|
|
<th style={{width: '90%'}}>Cookie</th>
|
|
|
|
<th style={{width: '2rem'}} className="text-right">
|
2017-08-22 22:30:57 +00:00
|
|
|
<button className="btn btn--super-duper-compact btn--outlined txt-md"
|
2016-11-29 22:28:55 +00:00
|
|
|
onClick={this._handleCookieAdd}
|
2016-08-15 17:04:36 +00:00
|
|
|
title="Add cookie">
|
2017-08-22 22:30:57 +00:00
|
|
|
Add Cookie
|
2016-08-15 17:04:36 +00:00
|
|
|
</button>
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody key={cookies.length}>
|
|
|
|
{cookies.map((cookie, i) => {
|
|
|
|
const cookieString = cookieToString(Cookie.fromJSON(JSON.stringify(cookie)));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<tr className="selectable" key={i}>
|
2017-08-22 22:30:57 +00:00
|
|
|
<RenderedText render={handleRender} component="td">
|
2017-08-19 22:34:16 +00:00
|
|
|
{cookie.domain}
|
2017-08-22 22:30:57 +00:00
|
|
|
</RenderedText>
|
|
|
|
<RenderedText render={handleRender} component="td">
|
2017-08-19 22:34:16 +00:00
|
|
|
{cookieString}
|
2017-08-22 22:30:57 +00:00
|
|
|
</RenderedText>
|
|
|
|
<td onClick={null} className="text-right no-wrap">
|
|
|
|
<button className="btn btn--super-compact btn--outlined"
|
|
|
|
onClick={e => handleShowModifyCookieModal(cookie)}
|
|
|
|
title="Edit cookie properties">
|
|
|
|
Edit
|
|
|
|
</button>
|
|
|
|
{' '}
|
|
|
|
<PromptButton className="btn btn--super-compact btn--outlined"
|
2017-03-01 21:15:56 +00:00
|
|
|
addIcon
|
2017-01-23 22:41:31 +00:00
|
|
|
confirmMessage=" "
|
|
|
|
onClick={e => this._handleDeleteCookie(cookie)}
|
|
|
|
title="Delete cookie">
|
2017-06-09 22:00:36 +00:00
|
|
|
<i className="fa fa-trash-o"/>
|
2017-01-23 22:41:31 +00:00
|
|
|
</PromptButton>
|
2016-08-15 17:04:36 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2016-08-15 17:04:36 +00:00
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2017-05-17 19:02:09 +00:00
|
|
|
{cookies.length === 0 && (
|
|
|
|
<div className="pad faint italic text-center">
|
|
|
|
<p>
|
|
|
|
I couldn't find any cookies for you.
|
|
|
|
</p>
|
|
|
|
<p>
|
2017-08-22 22:30:57 +00:00
|
|
|
<button className="btn btn--clicky" onClick={e => this._handleCookieAdd()}>
|
2017-07-25 22:28:53 +00:00
|
|
|
Add Cookie <i className="fa fa-plus-circle"/>
|
2017-05-17 19:02:09 +00:00
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
)}
|
2016-08-15 17:04:36 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-19 22:34:16 +00:00
|
|
|
CookieList.propTypes = {
|
2016-08-15 17:04:36 +00:00
|
|
|
onCookieAdd: PropTypes.func.isRequired,
|
|
|
|
onCookieDelete: PropTypes.func.isRequired,
|
|
|
|
cookies: PropTypes.array.isRequired,
|
2017-08-19 22:34:16 +00:00
|
|
|
newCookieDomainName: PropTypes.string.isRequired,
|
2017-08-22 22:30:57 +00:00
|
|
|
handleShowModifyCookieModal: PropTypes.func.isRequired,
|
|
|
|
handleRender: PropTypes.func.isRequired
|
2016-08-15 17:04:36 +00:00
|
|
|
};
|
|
|
|
|
2017-08-19 22:34:16 +00:00
|
|
|
export default CookieList;
|