redux-devtools/packages/redux-devtools-core/src/app/containers/Actions.tsx

77 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-01-03 17:14:25 +03:00
import React, { Component } from 'react';
import { connect, ResolveThunks } from 'react-redux';
2019-01-03 17:14:25 +03:00
import { Container } from 'devui';
import SliderMonitor from './monitors/Slider';
import { liftedDispatch as liftedDispatchAction, getReport } from '../actions';
import { getActiveInstance } from '../reducers/instances';
import DevTools from '../containers/DevTools';
import Dispatcher from './monitors/Dispatcher';
import TopButtons from '../components/TopButtons';
import BottomButtons from '../components/BottomButtons';
import { StoreState } from '../reducers';
2019-01-03 17:14:25 +03:00
type StateProps = ReturnType<typeof mapStateToProps>;
type DispatchProps = ResolveThunks<typeof actionCreators>;
type Props = StateProps & DispatchProps;
class Actions extends Component<Props> {
2019-01-03 17:14:25 +03:00
render() {
const {
2019-01-10 21:51:14 +03:00
monitor,
dispatcherIsOpen,
sliderIsOpen,
options,
liftedState,
liftedDispatch,
2019-01-03 17:14:25 +03:00
} = this.props;
return (
<Container>
<TopButtons
dispatch={liftedDispatch}
liftedState={liftedState}
options={options}
/>
<DevTools
monitor={monitor}
liftedState={liftedState}
monitorState={this.props.monitorState}
dispatch={liftedDispatch}
features={options.features}
/>
2019-01-10 21:51:14 +03:00
{sliderIsOpen && options.connectionId && options.features.jump && (
<SliderMonitor liftedState={liftedState} dispatch={liftedDispatch} />
)}
{dispatcherIsOpen &&
options.connectionId &&
options.features.dispatch && <Dispatcher options={options} />}
2019-01-03 17:14:25 +03:00
<BottomButtons
dispatcherIsOpen={dispatcherIsOpen}
sliderIsOpen={sliderIsOpen}
options={options}
/>
</Container>
);
}
}
const mapStateToProps = (state: StoreState) => {
2019-01-03 17:14:25 +03:00
const instances = state.instances;
const id = getActiveInstance(instances);
return {
liftedState: instances.states[id],
monitorState: state.monitor.monitorState,
options: instances.options[id],
monitor: state.monitor.selected,
dispatcherIsOpen: state.monitor.dispatcherIsOpen,
sliderIsOpen: state.monitor.sliderIsOpen,
reports: state.reports.data,
2019-01-03 17:14:25 +03:00
};
};
2019-01-03 17:14:25 +03:00
const actionCreators = {
liftedDispatch: liftedDispatchAction,
getReport,
};
2019-01-03 17:14:25 +03:00
export default connect(mapStateToProps, actionCreators)(Actions);