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
|
|
|
|
fixes 'previewHidden' of undefined error (#3409)
* readability improvements and reduced indirection
* adds type for handleShowModifyCookieModal
* correctly types wrapperProps property, thereby fixing bug.
if you add `console.log({ previewHidden, propsOne: this.props.wrapperProps.activeWorkspaceMeta });` to the third line of `_renderPreview()` you'll see that `activeWorkspaceMeta` is indeed, sometimes, `undefined.
Also, there's no reason to use `await` on `this.setState`. I didn't find any more of these in the codebase, I just found this one.
* adds type for swaggerUiSpec
* undoes lifting props to state
almost always, this is done for performance reasons, but I removed it the app is working pretty quick-and-snappy for me without needing to introduced duplicated application state and keep track of it.
I went ahead and measured it before and after this commit (using performance.now):
before = [
1.93500000750646,
1.149999996414408,
0.9499999869149178,
0.9950000094249845,
0.8650000090710819,
1.560000004246831,
1.5699999930802733,
0.8450000023003668,
1.4550000196322799,
1.3299999991431832,
1.3050000125076622,
1.4099999971222132,
1.3099999923724681,
1.3100000214762986,
1.1999999987892807,
1.0099999781232327,
0.830000004498288,
1.2449999921955168,
1.2500000011641532,
1.4349999837577343,
]
after = [
2.9400000057648867,
2.449999999953434,
2.33499999740161,
2.2849999950267375,
1.7700000025797635,
1.8149999959859997,
2.1249999990686774,
1.9150000007357448,
2.074999996693805,
1.9899999897461385,
2.0200000144541264,
2.869999996619299,
2.1450000058393925,
2.33499999740161,
2.130000008037314,
2.119999990100041,
2.144999976735562,
2.130000008037314,
2.380000009201467,
2.8999999922234565,
]
> R.mean(before)
> 1.2480000004870817
> R.mean(after)
> 2.243749999080319
> R.median(before)
> 1.2775000068359077
> R.median(after)
> 2.137499992386438
So basically, considering a 16ms render rate (i.e. 60hz), 1ms saved by lifting props to state makes no difference in application performance.
This is committed separately so that if there's any reason we want to keep the prior implementation, we can just still do so.
2021-05-24 14:14:00 +00:00
|
|
|
export interface CookieListProps {
|
2021-05-12 06:35:00 +00:00
|
|
|
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;
|
fixes 'previewHidden' of undefined error (#3409)
* readability improvements and reduced indirection
* adds type for handleShowModifyCookieModal
* correctly types wrapperProps property, thereby fixing bug.
if you add `console.log({ previewHidden, propsOne: this.props.wrapperProps.activeWorkspaceMeta });` to the third line of `_renderPreview()` you'll see that `activeWorkspaceMeta` is indeed, sometimes, `undefined.
Also, there's no reason to use `await` on `this.setState`. I didn't find any more of these in the codebase, I just found this one.
* adds type for swaggerUiSpec
* undoes lifting props to state
almost always, this is done for performance reasons, but I removed it the app is working pretty quick-and-snappy for me without needing to introduced duplicated application state and keep track of it.
I went ahead and measured it before and after this commit (using performance.now):
before = [
1.93500000750646,
1.149999996414408,
0.9499999869149178,
0.9950000094249845,
0.8650000090710819,
1.560000004246831,
1.5699999930802733,
0.8450000023003668,
1.4550000196322799,
1.3299999991431832,
1.3050000125076622,
1.4099999971222132,
1.3099999923724681,
1.3100000214762986,
1.1999999987892807,
1.0099999781232327,
0.830000004498288,
1.2449999921955168,
1.2500000011641532,
1.4349999837577343,
]
after = [
2.9400000057648867,
2.449999999953434,
2.33499999740161,
2.2849999950267375,
1.7700000025797635,
1.8149999959859997,
2.1249999990686774,
1.9150000007357448,
2.074999996693805,
1.9899999897461385,
2.0200000144541264,
2.869999996619299,
2.1450000058393925,
2.33499999740161,
2.130000008037314,
2.119999990100041,
2.144999976735562,
2.130000008037314,
2.380000009201467,
2.8999999922234565,
]
> R.mean(before)
> 1.2480000004870817
> R.mean(after)
> 2.243749999080319
> R.median(before)
> 1.2775000068359077
> R.median(after)
> 2.137499992386438
So basically, considering a 16ms render rate (i.e. 60hz), 1ms saved by lifting props to state makes no difference in application performance.
This is committed separately so that if there's any reason we want to keep the prior implementation, we can just still do so.
2021-05-24 14:14:00 +00:00
|
|
|
handleShowModifyCookieModal: (cookie: Cookie) => void;
|
2021-05-12 06:35:00 +00:00
|
|
|
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)
|
fixes 'previewHidden' of undefined error (#3409)
* readability improvements and reduced indirection
* adds type for handleShowModifyCookieModal
* correctly types wrapperProps property, thereby fixing bug.
if you add `console.log({ previewHidden, propsOne: this.props.wrapperProps.activeWorkspaceMeta });` to the third line of `_renderPreview()` you'll see that `activeWorkspaceMeta` is indeed, sometimes, `undefined.
Also, there's no reason to use `await` on `this.setState`. I didn't find any more of these in the codebase, I just found this one.
* adds type for swaggerUiSpec
* undoes lifting props to state
almost always, this is done for performance reasons, but I removed it the app is working pretty quick-and-snappy for me without needing to introduced duplicated application state and keep track of it.
I went ahead and measured it before and after this commit (using performance.now):
before = [
1.93500000750646,
1.149999996414408,
0.9499999869149178,
0.9950000094249845,
0.8650000090710819,
1.560000004246831,
1.5699999930802733,
0.8450000023003668,
1.4550000196322799,
1.3299999991431832,
1.3050000125076622,
1.4099999971222132,
1.3099999923724681,
1.3100000214762986,
1.1999999987892807,
1.0099999781232327,
0.830000004498288,
1.2449999921955168,
1.2500000011641532,
1.4349999837577343,
]
after = [
2.9400000057648867,
2.449999999953434,
2.33499999740161,
2.2849999950267375,
1.7700000025797635,
1.8149999959859997,
2.1249999990686774,
1.9150000007357448,
2.074999996693805,
1.9899999897461385,
2.0200000144541264,
2.869999996619299,
2.1450000058393925,
2.33499999740161,
2.130000008037314,
2.119999990100041,
2.144999976735562,
2.130000008037314,
2.380000009201467,
2.8999999922234565,
]
> R.mean(before)
> 1.2480000004870817
> R.mean(after)
> 2.243749999080319
> R.median(before)
> 1.2775000068359077
> R.median(after)
> 2.137499992386438
So basically, considering a 16ms render rate (i.e. 60hz), 1ms saved by lifting props to state makes no difference in application performance.
This is committed separately so that if there's any reason we want to keep the prior implementation, we can just still do so.
2021-05-24 14:14:00 +00:00
|
|
|
class CookieList extends PureComponent<CookieListProps> {
|
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"
|
fixes 'previewHidden' of undefined error (#3409)
* readability improvements and reduced indirection
* adds type for handleShowModifyCookieModal
* correctly types wrapperProps property, thereby fixing bug.
if you add `console.log({ previewHidden, propsOne: this.props.wrapperProps.activeWorkspaceMeta });` to the third line of `_renderPreview()` you'll see that `activeWorkspaceMeta` is indeed, sometimes, `undefined.
Also, there's no reason to use `await` on `this.setState`. I didn't find any more of these in the codebase, I just found this one.
* adds type for swaggerUiSpec
* undoes lifting props to state
almost always, this is done for performance reasons, but I removed it the app is working pretty quick-and-snappy for me without needing to introduced duplicated application state and keep track of it.
I went ahead and measured it before and after this commit (using performance.now):
before = [
1.93500000750646,
1.149999996414408,
0.9499999869149178,
0.9950000094249845,
0.8650000090710819,
1.560000004246831,
1.5699999930802733,
0.8450000023003668,
1.4550000196322799,
1.3299999991431832,
1.3050000125076622,
1.4099999971222132,
1.3099999923724681,
1.3100000214762986,
1.1999999987892807,
1.0099999781232327,
0.830000004498288,
1.2449999921955168,
1.2500000011641532,
1.4349999837577343,
]
after = [
2.9400000057648867,
2.449999999953434,
2.33499999740161,
2.2849999950267375,
1.7700000025797635,
1.8149999959859997,
2.1249999990686774,
1.9150000007357448,
2.074999996693805,
1.9899999897461385,
2.0200000144541264,
2.869999996619299,
2.1450000058393925,
2.33499999740161,
2.130000008037314,
2.119999990100041,
2.144999976735562,
2.130000008037314,
2.380000009201467,
2.8999999922234565,
]
> R.mean(before)
> 1.2480000004870817
> R.mean(after)
> 2.243749999080319
> R.median(before)
> 1.2775000068359077
> R.median(after)
> 2.137499992386438
So basically, considering a 16ms render rate (i.e. 60hz), 1ms saved by lifting props to state makes no difference in application performance.
This is committed separately so that if there's any reason we want to keep the prior implementation, we can just still do so.
2021-05-24 14:14: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;
|