-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathTopButtons.tsx
94 lines (85 loc) · 2.68 KB
/
TopButtons.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React, { Component } from 'react';
import { ActionCreators, LiftedAction } from '@redux-devtools/core';
import { Button, Toolbar, Divider } from '@redux-devtools/ui';
import { Action } from 'redux';
import RecordButton from './buttons/RecordButton';
import PersistButton from './buttons/PersistButton';
import LockButton from './buttons/LockButton';
import InstanceSelector from './InstanceSelector';
import SyncButton from './buttons/SyncButton';
import { Options, State } from '../reducers/instances';
const { reset, rollback, commit, sweep } = ActionCreators;
interface Props {
dispatch: (action: LiftedAction<unknown, Action<string>, unknown>) => void;
liftedState: State;
options: Options;
}
export default class TopButtons extends Component<Props> {
shouldComponentUpdate(nextProps: Props) {
return (
nextProps.options !== this.props.options ||
nextProps.liftedState !== this.props.liftedState
);
}
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;
const { computedStates, skippedActionIds, isPaused, isLocked } =
this.props.liftedState;
const noStates = computedStates.length < 2;
return (
<Toolbar borderPosition="bottom">
{features.pause && <RecordButton paused={isPaused} />}
{features.persist && <PersistButton />}
{features.lock && <LockButton locked={isLocked} />}
<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 />
{features.sync && <SyncButton />}
</Toolbar>
);
}
}