2021-05-12 06:35:00 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2020-06-30 19:36:15 +00:00
|
|
|
import * as uuid from 'uuid';
|
2017-08-23 03:33:07 +00:00
|
|
|
import * as toughCookie from 'tough-cookie';
|
2021-02-02 22:23:42 +00:00
|
|
|
import { autoBindMethodsForReact } from 'class-autobind-decorator';
|
2018-06-25 17:42:50 +00:00
|
|
|
import { cookieToString } from 'insomnia-cookies';
|
2017-08-19 22:34:16 +00:00
|
|
|
import PromptButton from './base/prompt-button';
|
2017-08-22 22:30:57 +00:00
|
|
|
import RenderedText from './rendered-text';
|
2018-06-25 17:42:50 +00:00
|
|
|
import type { Cookie } from '../../models/cookie-jar';
|
|
|
|
import { Dropdown, DropdownButton, DropdownItem } from './base/dropdown/index';
|
2021-02-02 22:23:42 +00:00
|
|
|
import { AUTOBIND_CFG } from '../../common/constants';
|
2021-05-12 06:35:00 +00:00
|
|
|
import { HandleRender } from '../../common/render';
|
2016-08-15 17:04:36 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
interface Props {
|
|
|
|
handleCookieAdd: Function;
|
|
|
|
handleCookieDelete: Function;
|
|
|
|
handleDeleteAll: Function;
|
2021-05-18 20:32:18 +00:00
|
|
|
cookies: Cookie[];
|
2021-05-12 06:35:00 +00:00
|
|
|
newCookieDomainName: string;
|
|
|
|
handleShowModifyCookieModal: Function;
|
|
|
|
handleRender: HandleRender;
|
|
|
|
}
|
2017-08-22 23:54:31 +00:00
|
|
|
|
2020-12-15 11:19:40 +00:00
|
|
|
// Use tough-cookie MAX_DATE value
|
|
|
|
// https://github.com/salesforce/tough-cookie/blob/5ae97c6a28122f3fb309adcd8428274d9b2bd795/lib/cookie.js#L77
|
|
|
|
const MAX_TIME = 2147483647000;
|
|
|
|
|
2021-02-02 22:23:42 +00:00
|
|
|
@autoBindMethodsForReact(AUTOBIND_CFG)
|
2021-05-12 06:35:00 +00:00
|
|
|
class CookieList extends PureComponent<Props> {
|
2018-06-25 17:42:50 +00:00
|
|
|
_handleCookieAdd() {
|
2017-08-23 03:33:07 +00:00
|
|
|
const newCookie: Cookie = {
|
|
|
|
id: uuid.v4(),
|
2016-08-15 17:04:36 +00:00
|
|
|
key: 'foo',
|
|
|
|
value: 'bar',
|
|
|
|
domain: this.props.newCookieDomainName,
|
2020-12-15 11:19:40 +00:00
|
|
|
expires: MAX_TIME,
|
2017-08-19 22:34:16 +00:00
|
|
|
path: '/',
|
|
|
|
secure: false,
|
2018-12-12 17:36:11 +00:00
|
|
|
httpOnly: false,
|
2017-08-23 03:33:07 +00:00
|
|
|
};
|
2017-10-31 21:10:08 +00:00
|
|
|
this.props.handleCookieAdd(newCookie);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-29 22:28:55 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
_handleDeleteCookie(cookie: Cookie) {
|
2017-10-31 21:10:08 +00:00
|
|
|
this.props.handleCookieDelete(cookie);
|
2016-08-15 17:04:36 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
render() {
|
2018-10-17 16:42:33 +00:00
|
|
|
const { cookies, handleDeleteAll, handleShowModifyCookieModal, handleRender } = 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>
|
2018-06-25 17:42:50 +00:00
|
|
|
<tr>
|
2021-05-12 06:35:00 +00:00
|
|
|
<th
|
|
|
|
style={{
|
|
|
|
minWidth: '10rem',
|
|
|
|
}}>
|
|
|
|
Domain
|
|
|
|
</th>
|
|
|
|
<th
|
|
|
|
style={{
|
|
|
|
width: '90%',
|
|
|
|
}}>
|
|
|
|
Cookie
|
|
|
|
</th>
|
|
|
|
<th
|
|
|
|
style={{
|
|
|
|
width: '2rem',
|
|
|
|
}}
|
|
|
|
className="text-right">
|
2018-06-25 17:42:50 +00:00
|
|
|
<Dropdown right>
|
|
|
|
<DropdownButton
|
|
|
|
title="Add cookie"
|
|
|
|
className="btn btn--super-duper-compact btn--outlined txt-md">
|
|
|
|
Actions <i className="fa fa-caret-down" />
|
|
|
|
</DropdownButton>
|
|
|
|
<DropdownItem onClick={this._handleCookieAdd}>
|
|
|
|
<i className="fa fa-plus-circle" /> Add Cookie
|
|
|
|
</DropdownItem>
|
2018-10-17 16:42:33 +00:00
|
|
|
<DropdownItem onClick={handleDeleteAll} buttonClass={PromptButton}>
|
2018-06-25 17:42:50 +00:00
|
|
|
<i className="fa fa-trash-o" /> Delete All
|
|
|
|
</DropdownItem>
|
|
|
|
</Dropdown>
|
|
|
|
</th>
|
|
|
|
</tr>
|
2016-08-15 17:04:36 +00:00
|
|
|
</thead>
|
|
|
|
<tbody key={cookies.length}>
|
2018-06-25 17:42:50 +00:00
|
|
|
{cookies.map((cookie, i) => {
|
2018-10-17 16:42:33 +00:00
|
|
|
const cookieString = cookieToString(toughCookie.Cookie.fromJSON(cookie));
|
2018-06-25 17:42:50 +00:00
|
|
|
return (
|
|
|
|
<tr className="selectable" key={i}>
|
|
|
|
<td>
|
2018-10-17 16:42:33 +00:00
|
|
|
<RenderedText render={handleRender}>{cookie.domain || ''}</RenderedText>
|
2018-06-25 17:42:50 +00:00
|
|
|
</td>
|
|
|
|
<td className="force-wrap wide">
|
2018-10-17 16:42:33 +00:00
|
|
|
<RenderedText render={handleRender}>{cookieString || ''}</RenderedText>
|
2018-06-25 17:42:50 +00:00
|
|
|
</td>
|
2021-05-12 06:35:00 +00:00
|
|
|
<td onClick={() => {}} className="text-right no-wrap">
|
2018-06-25 17:42:50 +00:00
|
|
|
<button
|
|
|
|
className="btn btn--super-compact btn--outlined"
|
2021-05-12 06:35:00 +00:00
|
|
|
onClick={() => handleShowModifyCookieModal(cookie)}
|
2018-06-25 17:42:50 +00:00
|
|
|
title="Edit cookie properties">
|
|
|
|
Edit
|
|
|
|
</button>{' '}
|
|
|
|
<PromptButton
|
|
|
|
className="btn btn--super-compact btn--outlined"
|
|
|
|
addIcon
|
2019-04-18 00:50:03 +00:00
|
|
|
confirmMessage=""
|
2021-05-12 06:35:00 +00:00
|
|
|
onClick={() => this._handleDeleteCookie(cookie)}
|
2018-06-25 17:42:50 +00:00
|
|
|
title="Delete cookie">
|
|
|
|
<i className="fa fa-trash-o" />
|
|
|
|
</PromptButton>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
})}
|
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">
|
2018-06-25 17:42:50 +00:00
|
|
|
<p>I couldn't find any cookies for you.</p>
|
2017-05-17 19:02:09 +00:00
|
|
|
<p>
|
2021-05-12 06:35:00 +00:00
|
|
|
<button className="btn btn--clicky" onClick={() => this._handleCookieAdd()}>
|
2018-06-25 17:42:50 +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
|
|
|
export default CookieList;
|