insomnia/packages/insomnia-app/app/ui/components/cookie-list.js

127 lines
4.1 KiB
JavaScript
Raw Normal View History

2017-08-22 23:54:31 +00:00
// @flow
import React from 'react';
2017-08-23 03:33:07 +00:00
import uuid from 'uuid';
import * as toughCookie from 'tough-cookie';
import autobind from 'autobind-decorator';
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';
2017-08-23 03:33:07 +00:00
import type {Cookie} from '../../models/cookie-jar';
2017-10-31 21:10:08 +00:00
import {Dropdown, DropdownButton, DropdownItem} from './base/dropdown/index';
type Props = {
2017-10-31 21:10:08 +00:00
handleCookieAdd: Function,
handleCookieDelete: Function,
handleDeleteAll: Function,
cookies: Array<Cookie>,
newCookieDomainName: string,
handleShowModifyCookieModal: Function,
handleRender: Function
};
2017-08-22 23:54:31 +00:00
@autobind
class CookieList extends React.PureComponent<Props> {
_handleCookieAdd () {
2017-08-23 03:33:07 +00:00
const newCookie: Cookie = {
id: uuid.v4(),
key: 'foo',
value: 'bar',
domain: this.props.newCookieDomainName,
2017-08-23 03:33:07 +00:00
expires: null,
2017-08-19 22:34:16 +00:00
path: '/',
secure: false,
httpOnly: false
2017-08-23 03:33:07 +00:00
};
2017-10-31 21:10:08 +00:00
this.props.handleCookieAdd(newCookie);
}
2017-08-22 23:54:31 +00:00
_handleDeleteCookie (cookie: Cookie) {
2017-10-31 21:10:08 +00:00
this.props.handleCookieDelete(cookie);
}
render () {
2017-08-19 22:34:16 +00:00
const {
cookies,
2017-10-31 21:10:08 +00:00
handleDeleteAll,
2017-08-22 22:30:57 +00:00
handleShowModifyCookieModal,
handleRender
2017-08-19 22:34:16 +00:00
} = this.props;
return (
<div>
2017-08-19 22:34:16 +00:00
<table className="table--fancy cookie-table table--striped">
<thead>
<tr>
<th style={{minWidth: '10rem'}}>Domain</th>
<th style={{width: '90%'}}>Cookie</th>
<th style={{width: '2rem'}} className="text-right">
2017-10-31 21:10:08 +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>
<DropdownItem onClick={handleDeleteAll} buttonClass={PromptButton}>
<i className="fa fa-trash-o"/> Delete All
</DropdownItem>
</Dropdown>
</th>
</tr>
</thead>
<tbody key={cookies.length}>
{cookies.map((cookie, i) => {
2017-08-23 03:33:07 +00:00
const cookieString = cookieToString(toughCookie.Cookie.fromJSON(cookie));
return (
<tr className="selectable" key={i}>
<td>
<RenderedText render={handleRender}>
{cookie.domain || ''}
</RenderedText>
</td>
<td className="force-wrap wide">
<RenderedText render={handleRender}>
{cookieString || ''}
</RenderedText>
</td>
2017-08-22 22:30:57 +00:00
<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"
addIcon
2017-01-23 22:41:31 +00:00
confirmMessage=" "
onClick={e => this._handleDeleteCookie(cookie)}
title="Delete cookie">
<i className="fa fa-trash-o"/>
2017-01-23 22:41:31 +00:00
</PromptButton>
</td>
</tr>
);
})}
</tbody>
</table>
{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"/>
</button>
</p>
</div>
)}
</div>
);
}
}
2017-08-19 22:34:16 +00:00
export default CookieList;