This commit is contained in:
Nathan Bierema 2020-10-16 09:38:18 -04:00
parent 75b01378e9
commit 185e760ec3
7 changed files with 87 additions and 60 deletions

View File

@ -18,6 +18,7 @@ import {
CLEAR_NOTIFICATION, CLEAR_NOTIFICATION,
UPDATE_STATE, UPDATE_STATE,
UPDATE_REPORTS, UPDATE_REPORTS,
REMOVE_INSTANCE,
} from '../constants/actionTypes'; } from '../constants/actionTypes';
import { import {
AUTH_ERROR, AUTH_ERROR,
@ -75,19 +76,37 @@ export function liftedDispatch(action) {
return { type: LIFTED_ACTION, message: 'DISPATCH', action }; return { type: LIFTED_ACTION, message: 'DISPATCH', action };
} }
export function selectInstance(selected) { interface SelectInstanceAction {
type: typeof SELECT_INSTANCE;
selected: string;
}
export function selectInstance(selected: string): SelectInstanceAction {
return { type: SELECT_INSTANCE, selected }; return { type: SELECT_INSTANCE, selected };
} }
export function selectMonitor(monitor) { interface SelectMonitorAction {
type: typeof SELECT_MONITOR;
monitor: string;
monitorState?: unknown;
}
export function selectMonitor(monitor: string): SelectMonitorAction {
return { type: SELECT_MONITOR, monitor }; return { type: SELECT_MONITOR, monitor };
} }
export function selectMonitorWithState(
export function selectMonitorWithState(value, monitorState) { value: string,
monitorState: unknown
): SelectMonitorAction {
return { type: SELECT_MONITOR, monitor: value, monitorState }; return { type: SELECT_MONITOR, monitor: value, monitorState };
} }
export function selectMonitorTab(subTabName) { interface NextState {
subTabName: string;
}
interface UpdateMonitorStateAction {
type: typeof UPDATE_MONITOR_STATE;
nextState: NextState;
}
export function selectMonitorTab(subTabName: string): UpdateMonitorStateAction {
return { type: UPDATE_MONITOR_STATE, nextState: { subTabName } }; return { type: UPDATE_MONITOR_STATE, nextState: { subTabName } };
} }
@ -196,6 +215,11 @@ export function getReport(report) {
return { type: GET_REPORT_REQUEST, report }; return { type: GET_REPORT_REQUEST, report };
} }
interface RemoveInstanceAction {
type: typeof REMOVE_INSTANCE;
id: string;
}
interface ConnectRequestAction { interface ConnectRequestAction {
type: typeof CONNECT_REQUEST; type: typeof CONNECT_REQUEST;
options: ConnectionOptions; options: ConnectionOptions;
@ -265,6 +289,9 @@ interface UnsubscribeAction {
export type StoreAction = export type StoreAction =
| ChangeSectionAction | ChangeSectionAction
| ChangeThemeAction | ChangeThemeAction
| SelectInstanceAction
| SelectMonitorAction
| UpdateMonitorStateAction
| ExportAction | ExportAction
| TogglePersistAction | TogglePersistAction
| ToggleSyncAction | ToggleSyncAction
@ -273,6 +300,7 @@ export type StoreAction =
| ReconnectAction | ReconnectAction
| ShowNotificationAction | ShowNotificationAction
| ClearNotificationAction | ClearNotificationAction
| RemoveInstanceAction
| ConnectRequestAction | ConnectRequestAction
| ConnectSuccessAction | ConnectSuccessAction
| ConnectErrorAction | ConnectErrorAction

View File

@ -31,6 +31,7 @@ class InstanceSelector extends Component<Props> {
return ( return (
<Select <Select
options={this.select} options={this.select}
// TODO Where's the type-checking?
onChange={this.props.onSelect} onChange={this.props.onSelect}
value={this.props.selected || ''} value={this.props.selected || ''}
/> />

View File

@ -1,12 +1,14 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux'; import { connect, ResolveThunks } from 'react-redux';
import { connect } from 'react-redux';
import { Button } from 'devui'; import { Button } from 'devui';
import { TiUpload } from 'react-icons/ti'; import { TiUpload } from 'react-icons/ti';
import { importState } from '../../actions'; import { importState } from '../../actions';
class ImportButton extends Component { type DispatchProps = ResolveThunks<typeof actionCreators>;
type Props = DispatchProps;
class ImportButton extends Component<Props> {
static propTypes = { static propTypes = {
importState: PropTypes.func.isRequired, importState: PropTypes.func.isRequired,
}; };
@ -55,10 +57,8 @@ class ImportButton extends Component {
} }
} }
function mapDispatchToProps(dispatch) { const actionCreators = {
return { importState,
importState: bindActionCreators(importState, dispatch), };
};
}
export default connect(null, mapDispatchToProps)(ImportButton); export default connect(null, actionCreators)(ImportButton);

View File

@ -1,7 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux'; import { connect, ResolveThunks } from 'react-redux';
import { connect } from 'react-redux';
import ChartMonitor from 'redux-devtools-chart-monitor'; import ChartMonitor from 'redux-devtools-chart-monitor';
import { selectMonitorWithState } from '../../actions'; import { selectMonitorWithState } from '../../actions';
@ -15,7 +14,10 @@ export function getPath(obj, inspectedStatePath) {
inspectedStatePath.push(name); inspectedStatePath.push(name);
} }
class ChartMonitorWrapper extends Component { type DispatchProps = ResolveThunks<typeof actionCreators>;
type Props = DispatchProps;
class ChartMonitorWrapper extends Component<Props> {
static update = ChartMonitor.update; static update = ChartMonitor.update;
onClickText = (data) => { onClickText = (data) => {
@ -47,13 +49,8 @@ ChartMonitorWrapper.propTypes = {
selectMonitorWithState: PropTypes.func.isRequired, selectMonitorWithState: PropTypes.func.isRequired,
}; };
function mapDispatchToProps(dispatch) { const actionCreators = {
return { selectMonitorWithState: selectMonitorWithState,
selectMonitorWithState: bindActionCreators( };
selectMonitorWithState,
dispatch
),
};
}
export default connect(null, mapDispatchToProps)(ChartMonitorWrapper); export default connect(null, actionCreators)(ChartMonitorWrapper);

View File

@ -1,7 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux'; import { connect, ResolveThunks } from 'react-redux';
import { connect } from 'react-redux';
import { withTheme } from 'styled-components'; import { withTheme } from 'styled-components';
import { tree } from 'd3-state-visualizer'; import { tree } from 'd3-state-visualizer';
import { getPath } from '../ChartMonitorWrapper'; import { getPath } from '../ChartMonitorWrapper';
@ -12,7 +11,10 @@ const style = {
height: '100%', height: '100%',
}; };
class ChartTab extends Component { type DispatchProps = ResolveThunks<typeof actionCreators>;
type Props = DispatchProps;
class ChartTab extends Component<Props> {
shouldComponentUpdate() { shouldComponentUpdate() {
return false; return false;
} }
@ -21,7 +23,7 @@ class ChartTab extends Component {
this.createChart(this.props); this.createChart(this.props);
} }
UNSAFE_componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps: Props) {
if ( if (
this.props.theme.scheme !== nextProps.theme.scheme || this.props.theme.scheme !== nextProps.theme.scheme ||
nextProps.theme.light !== this.props.theme.light nextProps.theme.light !== this.props.theme.light
@ -99,11 +101,9 @@ ChartTab.propTypes = {
theme: PropTypes.object.isRequired, theme: PropTypes.object.isRequired,
}; };
function mapDispatchToProps(dispatch) { const actionCreators = {
return { updateMonitorState,
updateMonitorState: bindActionCreators(updateMonitorState, dispatch), };
};
}
const ConnectedChartTab = connect(null, mapDispatchToProps)(ChartTab); const ConnectedChartTab = connect(null, actionCreators)(ChartTab);
export default withTheme(ConnectedChartTab); export default withTheme(ConnectedChartTab);

View File

@ -1,7 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux'; import { connect, ResolveThunks } from 'react-redux';
import { connect } from 'react-redux';
import { Tabs } from 'devui'; import { Tabs } from 'devui';
import StateTree from 'redux-devtools-inspector-monitor/lib/tabs/StateTab'; import StateTree from 'redux-devtools-inspector-monitor/lib/tabs/StateTab';
import ActionTree from 'redux-devtools-inspector-monitor/lib/tabs/ActionTab'; import ActionTree from 'redux-devtools-inspector-monitor/lib/tabs/ActionTab';
@ -10,14 +9,19 @@ import { selectMonitorTab } from '../../../actions';
import RawTab from './RawTab'; import RawTab from './RawTab';
import ChartTab from './ChartTab'; import ChartTab from './ChartTab';
import VisualDiffTab from './VisualDiffTab'; import VisualDiffTab from './VisualDiffTab';
import { StoreState } from '../../../reducers';
class SubTabs extends Component { type StateProps = ReturnType<typeof mapStateToProps>;
constructor(props) { type DispatchProps = ResolveThunks<typeof actionCreators>;
type Props = StateProps & DispatchProps;
class SubTabs extends Component<Props> {
constructor(props: Props) {
super(props); super(props);
this.updateTabs(props); this.updateTabs(props);
} }
UNSAFE_componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps: Props) {
if (nextProps.parentTab !== this.props.parentTab) { if (nextProps.parentTab !== this.props.parentTab) {
this.updateTabs(nextProps); this.updateTabs(nextProps);
} }
@ -34,7 +38,7 @@ class SubTabs extends Component {
} }
}; };
updateTabs(props) { updateTabs(props: Props) {
const parentTab = props.parentTab; const parentTab = props.parentTab;
if (parentTab === 'Diff') { if (parentTab === 'Diff') {
@ -96,17 +100,13 @@ SubTabs.propTypes = {
nextState: PropTypes.object, nextState: PropTypes.object,
}; };
function mapStateToProps(state) { const mapStateToProps = (state: StoreState) => ({
return {
parentTab: state.monitor.monitorState.tabName, parentTab: state.monitor.monitorState.tabName,
selected: state.monitor.monitorState.subTabName, selected: state.monitor.monitorState.subTabName,
}; });
}
function mapDispatchToProps(dispatch) { const actionCreators = {
return { selectMonitorTab,
selectMonitorTab: bindActionCreators(selectMonitorTab, dispatch), };
};
}
export default connect(mapStateToProps, mapDispatchToProps)(SubTabs); export default connect(mapStateToProps, actionCreators)(SubTabs);

View File

@ -12,9 +12,12 @@ import parseJSON from '../utils/parseJSON';
import { recompute } from '../utils/updateState'; import { recompute } from '../utils/updateState';
import { StoreAction } from '../actions'; import { StoreAction } from '../actions';
interface InstancesState {} interface InstancesState {
sync: boolean;
persisted?: boolean;
}
export const initialState = { export const initialState: InstancesState = {
selected: null, selected: null,
current: 'default', current: 'default',
sync: false, sync: false,
@ -170,7 +173,7 @@ export function dispatchAction(state, { action }) {
return state; return state;
} }
function removeState(state, connectionId) { function removeState(state: InstancesState, connectionId: string) {
const instanceIds = state.connections[connectionId]; const instanceIds = state.connections[connectionId];
if (!instanceIds) return state; if (!instanceIds) return state;
@ -310,7 +313,5 @@ export default function instances(state = initialState, action: StoreAction) {
} }
} }
/* eslint-disable no-shadow */ export const getActiveInstance = (instances: InstancesState) =>
export const getActiveInstance = (instances) =>
instances.selected || instances.current; instances.selected || instances.current;
/* eslint-enable */