2018-12-22 03:10:49 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PageHeader from 'react-bootstrap/lib/PageHeader';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import pkg from '../../../package.json';
|
|
|
|
import Button from 'react-bootstrap/lib/Button';
|
|
|
|
import FormGroup from 'react-bootstrap/lib/FormGroup';
|
|
|
|
import FormControl from 'react-bootstrap/lib/FormControl';
|
|
|
|
import ControlLabel from 'react-bootstrap/lib/ControlLabel';
|
|
|
|
import Form from 'react-bootstrap/lib/Form';
|
|
|
|
import Col from 'react-bootstrap/lib/Col';
|
|
|
|
import InputGroup from 'react-bootstrap/lib/InputGroup';
|
|
|
|
import * as base16 from 'base16';
|
|
|
|
import * as inspectorThemes from '../../../src/themes';
|
|
|
|
import getOptions from './getOptions';
|
2020-08-10 03:41:59 +03:00
|
|
|
import { push as pushRoute } from 'connected-react-router';
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
const styles = {
|
|
|
|
wrapper: {
|
|
|
|
height: '100vh',
|
|
|
|
width: '80%',
|
|
|
|
margin: '0 auto',
|
2020-08-08 23:26:39 +03:00
|
|
|
paddingTop: '1px',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
header: {},
|
2018-12-22 03:10:49 +03:00
|
|
|
content: {
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
2020-08-08 23:26:39 +03:00
|
|
|
height: '50%',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
buttons: {
|
|
|
|
display: 'flex',
|
|
|
|
width: '40rem',
|
|
|
|
justifyContent: 'center',
|
2020-08-08 23:26:39 +03:00
|
|
|
flexWrap: 'wrap',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
muted: {
|
2020-08-08 23:26:39 +03:00
|
|
|
color: '#CCCCCC',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
button: {
|
2020-08-08 23:26:39 +03:00
|
|
|
margin: '0.5rem',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
links: {
|
2020-08-08 23:26:39 +03:00
|
|
|
textAlign: 'center',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
link: {
|
|
|
|
margin: '0 0.5rem',
|
|
|
|
cursor: 'pointer',
|
2020-08-08 23:26:39 +03:00
|
|
|
display: 'block',
|
2018-12-22 03:10:49 +03:00
|
|
|
},
|
|
|
|
input: {
|
|
|
|
display: 'inline-block',
|
|
|
|
textAlign: 'left',
|
2020-08-08 23:26:39 +03:00
|
|
|
width: '30rem',
|
|
|
|
},
|
2018-12-22 03:10:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const themeOptions = [
|
2020-08-08 23:26:39 +03:00
|
|
|
...Object.keys(inspectorThemes).map((value) => ({
|
2019-01-10 21:51:14 +03:00
|
|
|
value,
|
2020-08-08 23:26:39 +03:00
|
|
|
label: inspectorThemes[value].scheme,
|
2019-01-10 21:51:14 +03:00
|
|
|
})),
|
2018-12-22 03:10:49 +03:00
|
|
|
null,
|
|
|
|
...Object.keys(base16)
|
2020-08-08 23:26:39 +03:00
|
|
|
.map((value) => ({ value, label: base16[value].scheme }))
|
|
|
|
.filter((opt) => opt.label),
|
2018-12-22 03:10:49 +03:00
|
|
|
];
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
const ROOT =
|
|
|
|
process.env.NODE_ENV === 'production' ? '/redux-devtools-inspector/' : '/';
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
function buildUrl(options) {
|
2019-01-10 21:51:14 +03:00
|
|
|
return (
|
|
|
|
`${ROOT}?` +
|
|
|
|
[
|
|
|
|
options.useExtension ? 'ext' : '',
|
|
|
|
options.supportImmutable ? 'immutable' : '',
|
|
|
|
options.theme ? 'theme=' + options.theme : '',
|
2020-08-08 23:26:39 +03:00
|
|
|
options.dark ? 'dark' : '',
|
2019-01-10 21:51:14 +03:00
|
|
|
]
|
2020-08-08 23:26:39 +03:00
|
|
|
.filter((s) => s)
|
2019-01-10 21:51:14 +03:00
|
|
|
.join('&')
|
|
|
|
);
|
2018-12-22 03:10:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class DemoApp extends React.Component {
|
|
|
|
render() {
|
2020-08-10 03:41:59 +03:00
|
|
|
const options = getOptions(this.props.router.location);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={styles.wrapper}>
|
|
|
|
<PageHeader style={styles.header}>
|
|
|
|
{pkg.name || <span style={styles.muted}>Package Name</span>}
|
|
|
|
</PageHeader>
|
2019-01-10 21:51:14 +03:00
|
|
|
<h5>
|
|
|
|
{pkg.description || (
|
|
|
|
<span style={styles.muted}>Package Description</span>
|
|
|
|
)}
|
|
|
|
</h5>
|
2018-12-22 03:10:49 +03:00
|
|
|
<div style={styles.links}>
|
|
|
|
<div style={styles.input}>
|
|
|
|
<Form horizontal>
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} sm={3}>
|
|
|
|
Theme:
|
|
|
|
</Col>
|
|
|
|
<Col sm={9}>
|
|
|
|
<InputGroup>
|
2020-08-08 19:13:59 +03:00
|
|
|
<FormControl
|
|
|
|
componentClass="select"
|
2020-08-08 23:26:39 +03:00
|
|
|
onChange={(event) =>
|
2020-08-08 19:13:59 +03:00
|
|
|
this.setTheme(options, event.currentTarget.value)
|
|
|
|
}
|
2019-01-10 21:51:14 +03:00
|
|
|
>
|
2020-08-08 23:26:39 +03:00
|
|
|
{themeOptions.map((theme) => (
|
2020-08-08 19:13:59 +03:00
|
|
|
<option
|
|
|
|
key={(theme && theme.label) || 'empty'}
|
|
|
|
label={(theme && theme.label) || '──────────'}
|
|
|
|
value={theme && theme.value}
|
|
|
|
disabled={!theme}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</FormControl>
|
2018-12-22 03:10:49 +03:00
|
|
|
<InputGroup.Addon>
|
2019-01-10 21:51:14 +03:00
|
|
|
<a onClick={this.toggleTheme} style={styles.link}>
|
2018-12-22 03:10:49 +03:00
|
|
|
{options.dark ? 'Light theme' : 'Dark theme'}
|
|
|
|
</a>
|
|
|
|
</InputGroup.Addon>
|
|
|
|
</InputGroup>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div style={styles.content}>
|
|
|
|
<div style={styles.buttons}>
|
|
|
|
<Button onClick={this.props.increment} style={styles.button}>
|
|
|
|
Increment
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.push} style={styles.button}>
|
|
|
|
Push
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.pop} style={styles.button}>
|
|
|
|
Pop
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.replace} style={styles.button}>
|
|
|
|
Replace
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.changeNested} style={styles.button}>
|
|
|
|
Change Nested
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.pushHugeArray} style={styles.button}>
|
|
|
|
Push Huge Array
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.addHugeObect} style={styles.button}>
|
|
|
|
Add Huge Object
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.addIterator} style={styles.button}>
|
|
|
|
Add Iterator
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.addRecursive} style={styles.button}>
|
|
|
|
Add Recursive
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.addNativeMap} style={styles.button}>
|
|
|
|
Add Native Map
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.addImmutableMap} style={styles.button}>
|
|
|
|
Add Immutable Map
|
|
|
|
</Button>
|
2019-01-10 21:51:14 +03:00
|
|
|
<Button
|
|
|
|
onClick={this.props.changeImmutableNested}
|
|
|
|
style={styles.button}
|
|
|
|
>
|
2018-12-22 03:10:49 +03:00
|
|
|
Change Immutable Nested
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.hugePayload} style={styles.button}>
|
|
|
|
Huge Payload
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.addFunction} style={styles.button}>
|
|
|
|
Add Function
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.addSymbol} style={styles.button}>
|
|
|
|
Add Symbol
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.toggleTimeoutUpdate} style={styles.button}>
|
|
|
|
Timeout Update {this.props.timeoutUpdateEnabled ? 'On' : 'Off'}
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.props.shuffleArray} style={styles.button}>
|
|
|
|
Shuffle Array
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div style={styles.links}>
|
2019-01-10 21:51:14 +03:00
|
|
|
<a onClick={this.toggleExtension} style={styles.link}>
|
|
|
|
{(options.useExtension ? 'Disable' : 'Enable') +
|
2020-08-10 03:41:59 +03:00
|
|
|
' Chrome Extension (will reload this page)'}
|
2018-12-22 03:10:49 +03:00
|
|
|
</a>
|
2019-01-10 21:51:14 +03:00
|
|
|
<a onClick={this.toggleImmutableSupport} style={styles.link}>
|
|
|
|
{(options.supportImmutable ? 'Disable' : 'Enable') +
|
|
|
|
' Full Immutable Support'}
|
2018-12-22 03:10:49 +03:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleExtension = () => {
|
2020-08-10 03:41:59 +03:00
|
|
|
const options = getOptions(this.props.router.location);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2020-08-10 03:41:59 +03:00
|
|
|
window.location.href = buildUrl({
|
|
|
|
...options,
|
|
|
|
useExtension: !options.useExtension,
|
|
|
|
});
|
2018-12-22 03:10:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
toggleImmutableSupport = () => {
|
2020-08-10 03:41:59 +03:00
|
|
|
const options = getOptions(this.props.router.location);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
this.props.pushRoute(
|
|
|
|
buildUrl({ ...options, supportImmutable: !options.supportImmutable })
|
|
|
|
);
|
2018-12-22 03:10:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
toggleTheme = () => {
|
2020-08-10 03:41:59 +03:00
|
|
|
const options = getOptions(this.props.router.location);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
this.props.pushRoute(buildUrl({ ...options, dark: !options.dark }));
|
|
|
|
};
|
|
|
|
|
|
|
|
setTheme = (options, theme) => {
|
|
|
|
this.props.pushRoute(buildUrl({ ...options, theme }));
|
|
|
|
};
|
|
|
|
|
|
|
|
toggleTimeoutUpdate = () => {
|
|
|
|
const enabled = !this.props.timeoutUpdateEnabled;
|
|
|
|
this.props.toggleTimeoutUpdate(enabled);
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
this.timeout = setInterval(this.props.timeoutUpdate, 1000);
|
|
|
|
} else {
|
|
|
|
clearTimeout(this.timeout);
|
|
|
|
}
|
2019-01-10 21:51:14 +03:00
|
|
|
};
|
2018-12-22 03:10:49 +03:00
|
|
|
}
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
export default connect((state) => state, {
|
|
|
|
toggleTimeoutUpdate: (timeoutUpdateEnabled) => ({
|
2020-08-05 16:12:31 +03:00
|
|
|
type: 'TOGGLE_TIMEOUT_UPDATE',
|
2020-08-08 23:26:39 +03:00
|
|
|
timeoutUpdateEnabled,
|
2020-08-05 16:12:31 +03:00
|
|
|
}),
|
|
|
|
timeoutUpdate: () => ({ type: 'TIMEOUT_UPDATE' }),
|
|
|
|
increment: () => ({ type: 'INCREMENT' }),
|
|
|
|
push: () => ({ type: 'PUSH' }),
|
|
|
|
pop: () => ({ type: 'POP' }),
|
|
|
|
replace: () => ({ type: 'REPLACE' }),
|
|
|
|
changeNested: () => ({ type: 'CHANGE_NESTED' }),
|
|
|
|
pushHugeArray: () => ({ type: 'PUSH_HUGE_ARRAY' }),
|
|
|
|
addIterator: () => ({ type: 'ADD_ITERATOR' }),
|
|
|
|
addHugeObect: () => ({ type: 'ADD_HUGE_OBJECT' }),
|
|
|
|
addRecursive: () => ({ type: 'ADD_RECURSIVE' }),
|
|
|
|
addNativeMap: () => ({ type: 'ADD_NATIVE_MAP' }),
|
|
|
|
addImmutableMap: () => ({ type: 'ADD_IMMUTABLE_MAP' }),
|
|
|
|
changeImmutableNested: () => ({ type: 'CHANGE_IMMUTABLE_NESTED' }),
|
|
|
|
hugePayload: () => ({
|
|
|
|
type: 'HUGE_PAYLOAD',
|
2020-08-08 23:26:39 +03:00
|
|
|
payload: Array.from({ length: 10000 }).map((_, i) => i),
|
2020-08-05 16:12:31 +03:00
|
|
|
}),
|
|
|
|
addFunction: () => ({ type: 'ADD_FUNCTION' }),
|
|
|
|
addSymbol: () => ({ type: 'ADD_SYMBOL' }),
|
|
|
|
shuffleArray: () => ({ type: 'SHUFFLE_ARRAY' }),
|
2020-08-08 23:26:39 +03:00
|
|
|
pushRoute,
|
2020-08-05 16:12:31 +03:00
|
|
|
})(DemoApp);
|