2020-08-04 23:13:22 +03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import shouldPureComponentUpdate from 'react-pure-render/function';
|
|
|
|
import * as themes from 'redux-devtools-themes';
|
|
|
|
import { ActionCreators } from 'redux-devtools';
|
|
|
|
import deepmerge from 'deepmerge';
|
|
|
|
|
|
|
|
import reducer from './reducers';
|
|
|
|
import Chart from './Chart';
|
|
|
|
const { reset, rollback, commit, sweep, toggleAction } = ActionCreators;
|
|
|
|
|
|
|
|
const styles = {
|
|
|
|
container: {
|
|
|
|
fontFamily: 'monaco, Consolas, Lucida Console, monospace',
|
|
|
|
position: 'relative',
|
|
|
|
overflowY: 'hidden',
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
2020-08-08 23:26:39 +03:00
|
|
|
minWidth: 300,
|
|
|
|
},
|
2020-08-04 23:13:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
function invertColors(theme) {
|
|
|
|
return {
|
|
|
|
...theme,
|
|
|
|
base00: theme.base07,
|
|
|
|
base01: theme.base06,
|
|
|
|
base02: theme.base05,
|
|
|
|
base03: theme.base04,
|
|
|
|
base04: theme.base03,
|
|
|
|
base05: theme.base02,
|
|
|
|
base06: theme.base01,
|
2020-08-08 23:26:39 +03:00
|
|
|
base07: theme.base00,
|
2020-08-04 23:13:22 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChartMonitor extends Component {
|
|
|
|
static update = reducer;
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
dispatch: PropTypes.func,
|
|
|
|
computedStates: PropTypes.array,
|
|
|
|
currentStateIndex: PropTypes.number,
|
|
|
|
actionsById: PropTypes.object,
|
|
|
|
stagedActionIds: PropTypes.array,
|
|
|
|
skippedActionIds: PropTypes.array,
|
|
|
|
monitorState: PropTypes.shape({
|
2020-08-08 23:26:39 +03:00
|
|
|
initialScrollTop: PropTypes.number,
|
2020-08-04 23:13:22 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
preserveScrollTop: PropTypes.bool,
|
|
|
|
select: PropTypes.func.isRequired,
|
2020-08-05 16:12:31 +03:00
|
|
|
theme: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
2020-08-08 23:26:39 +03:00
|
|
|
invertTheme: PropTypes.bool,
|
2020-08-04 23:13:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
2020-08-08 23:26:39 +03:00
|
|
|
select: (state) => state,
|
2020-08-04 23:13:22 +03:00
|
|
|
theme: 'nicinabox',
|
|
|
|
preserveScrollTop: true,
|
2020-08-08 23:26:39 +03:00
|
|
|
invertTheme: false,
|
2020-08-04 23:13:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
shouldComponentUpdate = shouldPureComponentUpdate;
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.handleToggleAction = this.handleToggleAction.bind(this);
|
|
|
|
this.handleReset = this.handleReset.bind(this);
|
|
|
|
this.handleRollback = this.handleRollback.bind(this);
|
|
|
|
this.handleSweep = this.handleSweep.bind(this);
|
|
|
|
this.handleCommit = this.handleCommit.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRollback() {
|
|
|
|
this.props.dispatch(rollback());
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSweep() {
|
|
|
|
this.props.dispatch(sweep());
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCommit() {
|
|
|
|
this.props.dispatch(commit());
|
|
|
|
}
|
|
|
|
|
|
|
|
handleToggleAction(id) {
|
|
|
|
this.props.dispatch(toggleAction(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
handleReset() {
|
|
|
|
this.props.dispatch(reset());
|
|
|
|
}
|
|
|
|
|
|
|
|
getTheme() {
|
|
|
|
let { theme, invertTheme } = this.props;
|
|
|
|
if (typeof theme !== 'string') {
|
|
|
|
return invertTheme ? invertColors(theme) : theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof themes[theme] !== 'undefined') {
|
|
|
|
return invertTheme ? invertColors(themes[theme]) : themes[theme];
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
2020-08-05 16:12:31 +03:00
|
|
|
console.warn(
|
|
|
|
'DevTools theme ' + theme + ' not found, defaulting to nicinabox'
|
|
|
|
);
|
2020-08-04 23:13:22 +03:00
|
|
|
return invertTheme ? invertColors(themes.nicinabox) : themes.nicinabox;
|
|
|
|
}
|
|
|
|
|
|
|
|
getChartStyle() {
|
|
|
|
const theme = this.getTheme();
|
|
|
|
|
|
|
|
return {
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
node: {
|
|
|
|
colors: {
|
2020-08-05 16:12:31 +03:00
|
|
|
default: theme.base0B,
|
2020-08-04 23:13:22 +03:00
|
|
|
collapsed: theme.base0B,
|
2020-08-08 23:26:39 +03:00
|
|
|
parent: theme.base0E,
|
2020-08-04 23:13:22 +03:00
|
|
|
},
|
2020-08-08 23:26:39 +03:00
|
|
|
radius: 7,
|
2020-08-04 23:13:22 +03:00
|
|
|
},
|
|
|
|
text: {
|
|
|
|
colors: {
|
2020-08-05 16:12:31 +03:00
|
|
|
default: theme.base0D,
|
2020-08-08 23:26:39 +03:00
|
|
|
hover: theme.base06,
|
|
|
|
},
|
|
|
|
},
|
2020-08-04 23:13:22 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getChartOptions(props = this.props) {
|
|
|
|
const { computedStates } = props;
|
|
|
|
const theme = this.getTheme();
|
|
|
|
|
|
|
|
const tooltipOptions = {
|
|
|
|
disabled: false,
|
2020-08-05 16:12:31 +03:00
|
|
|
offset: { left: 30, top: 10 },
|
2020-08-04 23:13:22 +03:00
|
|
|
indentationSize: 2,
|
|
|
|
style: {
|
|
|
|
'background-color': theme.base06,
|
2020-08-05 16:12:31 +03:00
|
|
|
opacity: '0.7',
|
2020-08-04 23:13:22 +03:00
|
|
|
'border-radius': '5px',
|
2020-08-08 23:26:39 +03:00
|
|
|
padding: '5px',
|
|
|
|
},
|
2020-08-04 23:13:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultOptions = {
|
2020-08-05 16:12:31 +03:00
|
|
|
state: computedStates.length
|
|
|
|
? computedStates[props.currentStateIndex].state
|
|
|
|
: null,
|
2020-08-04 23:13:22 +03:00
|
|
|
isSorted: false,
|
|
|
|
heightBetweenNodesCoeff: 1,
|
|
|
|
widthBetweenNodesCoeff: 1.3,
|
|
|
|
tooltipOptions,
|
2020-08-08 23:26:39 +03:00
|
|
|
style: this.getChartStyle(),
|
2020-08-04 23:13:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return deepmerge(defaultOptions, props);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const theme = this.getTheme();
|
|
|
|
|
|
|
|
return (
|
2020-08-05 16:12:31 +03:00
|
|
|
<div style={{ ...styles.container, backgroundColor: theme.base07 }}>
|
2020-08-04 23:13:22 +03:00
|
|
|
<Chart {...this.getChartOptions()} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ChartMonitor;
|