2019-01-03 17:14:25 +03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-12-21 17:08:08 +03:00
|
|
|
import { ActionCreators, LiftedAction } from '@redux-devtools/core';
|
2019-01-10 20:23:33 +03:00
|
|
|
import { Button, Toolbar, Divider } from 'devui';
|
2020-10-26 02:32:04 +03:00
|
|
|
import { Action } from 'redux';
|
2019-01-03 17:14:25 +03:00
|
|
|
import RecordButton from './buttons/RecordButton';
|
|
|
|
import PersistButton from './buttons/PersistButton';
|
|
|
|
import LockButton from './buttons/LockButton';
|
|
|
|
import InstanceSelector from './InstanceSelector';
|
|
|
|
import SyncButton from './buttons/SyncButton';
|
2020-10-26 02:32:04 +03:00
|
|
|
import { Options, State } from '../reducers/instances';
|
2019-01-03 17:14:25 +03:00
|
|
|
|
2020-10-26 02:32:04 +03:00
|
|
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
2019-01-03 17:14:25 +03:00
|
|
|
const { reset, rollback, commit, sweep } = ActionCreators;
|
|
|
|
|
2020-10-26 02:32:04 +03:00
|
|
|
interface Props {
|
|
|
|
dispatch: (action: LiftedAction<unknown, Action<unknown>, unknown>) => void;
|
|
|
|
liftedState: State;
|
|
|
|
options: Options;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class TopButtons extends Component<Props> {
|
2019-01-03 17:14:25 +03:00
|
|
|
static propTypes = {
|
|
|
|
// shouldSync: PropTypes.bool,
|
|
|
|
liftedState: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2020-08-08 23:26:39 +03:00
|
|
|
options: PropTypes.object.isRequired,
|
2019-01-03 17:14:25 +03:00
|
|
|
};
|
|
|
|
|
2020-10-26 02:32:04 +03:00
|
|
|
shouldComponentUpdate(nextProps: Props) {
|
2019-01-10 21:51:14 +03:00
|
|
|
return (
|
|
|
|
nextProps.options !== this.props.options ||
|
|
|
|
nextProps.liftedState !== this.props.liftedState
|
|
|
|
);
|
2019-01-03 17:14:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
handleRollback = () => {
|
|
|
|
this.props.dispatch(rollback());
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSweep = () => {
|
|
|
|
this.props.dispatch(sweep());
|
|
|
|
};
|
|
|
|
|
|
|
|
handleCommit = () => {
|
|
|
|
this.props.dispatch(commit());
|
|
|
|
};
|
|
|
|
|
|
|
|
handleReset = () => {
|
|
|
|
this.props.dispatch(reset());
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const options = this.props.options;
|
|
|
|
const features = options.features;
|
2019-01-10 21:51:14 +03:00
|
|
|
const {
|
|
|
|
computedStates,
|
|
|
|
skippedActionIds,
|
|
|
|
isPaused,
|
2020-08-08 23:26:39 +03:00
|
|
|
isLocked,
|
2019-01-10 21:51:14 +03:00
|
|
|
} = this.props.liftedState;
|
2019-01-03 17:14:25 +03:00
|
|
|
const noStates = computedStates.length < 2;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Toolbar borderPosition="bottom">
|
2019-01-10 21:51:14 +03:00
|
|
|
{features.pause && <RecordButton paused={isPaused} />}
|
|
|
|
{features.persist && <PersistButton />}
|
|
|
|
{features.lock && (
|
|
|
|
<LockButton locked={isLocked} disabled={options.lib !== 'redux'} />
|
|
|
|
)}
|
2019-01-03 17:14:25 +03:00
|
|
|
<Divider />
|
|
|
|
<Button
|
|
|
|
title="Reset to the state you created the store with"
|
|
|
|
tooltipPosition="bottom"
|
|
|
|
onClick={this.handleReset}
|
|
|
|
>
|
|
|
|
Reset
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
title="Roll back to the last committed state"
|
|
|
|
tooltipPosition="bottom"
|
|
|
|
onClick={this.handleRollback}
|
|
|
|
disabled={noStates}
|
|
|
|
>
|
|
|
|
Revert
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
title="Remove all currently disabled actions from the log"
|
|
|
|
tooltipPosition="bottom"
|
|
|
|
onClick={this.handleSweep}
|
|
|
|
disabled={skippedActionIds.length === 0}
|
|
|
|
>
|
|
|
|
Sweep
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
title="Remove all actions from the log,\a and make the current state your initial state"
|
|
|
|
tooltipPosition="bottom"
|
|
|
|
onClick={this.handleCommit}
|
|
|
|
disabled={noStates}
|
|
|
|
>
|
|
|
|
Commit
|
|
|
|
</Button>
|
|
|
|
<Divider />
|
|
|
|
<InstanceSelector />
|
2019-01-10 21:51:14 +03:00
|
|
|
{features.sync && <SyncButton />}
|
2019-01-03 17:14:25 +03:00
|
|
|
</Toolbar>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|