mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-12-01 14:03:52 +03:00
removed TextArea component and replaced with prompts
This commit is contained in:
parent
38158191ce
commit
1f0ed7a18a
|
@ -3,8 +3,7 @@ const ActionTypes = {
|
||||||
RESET: 'RESET',
|
RESET: 'RESET',
|
||||||
ROLLBACK: 'ROLLBACK',
|
ROLLBACK: 'ROLLBACK',
|
||||||
COMMIT: 'COMMIT',
|
COMMIT: 'COMMIT',
|
||||||
EXPORT: 'EXPORT',
|
IMPORT_STATE: 'IMPORT_STATE',
|
||||||
IMPORT: 'IMPORT',
|
|
||||||
SWEEP: 'SWEEP',
|
SWEEP: 'SWEEP',
|
||||||
TOGGLE_ACTION: 'TOGGLE_ACTION',
|
TOGGLE_ACTION: 'TOGGLE_ACTION',
|
||||||
JUMP_TO_STATE: 'JUMP_TO_STATE',
|
JUMP_TO_STATE: 'JUMP_TO_STATE',
|
||||||
|
@ -88,8 +87,7 @@ function liftReducer(reducer, initialState) {
|
||||||
skippedActions: {},
|
skippedActions: {},
|
||||||
currentStateIndex: 0,
|
currentStateIndex: 0,
|
||||||
monitorState: {
|
monitorState: {
|
||||||
isVisible: true,
|
isVisible: true
|
||||||
exportMode: false
|
|
||||||
},
|
},
|
||||||
timestamps: [Date.now()]
|
timestamps: [Date.now()]
|
||||||
};
|
};
|
||||||
|
@ -124,24 +122,15 @@ function liftReducer(reducer, initialState) {
|
||||||
currentStateIndex = 0;
|
currentStateIndex = 0;
|
||||||
timestamps = [liftedAction.timestamp];
|
timestamps = [liftedAction.timestamp];
|
||||||
break;
|
break;
|
||||||
case ActionTypes.EXPORT:
|
case ActionTypes.IMPORT_STATE:
|
||||||
monitorState = Object.assign(
|
({
|
||||||
{},
|
stagedActions,
|
||||||
|
skippedActions,
|
||||||
|
computedStates,
|
||||||
|
currentStateIndex,
|
||||||
monitorState,
|
monitorState,
|
||||||
{ exportMode: !monitorState.exportMode }
|
timestamps
|
||||||
);
|
} = liftedAction.nextLiftedState);
|
||||||
break;
|
|
||||||
case ActionTypes.IMPORT:
|
|
||||||
(
|
|
||||||
{
|
|
||||||
stagedActions,
|
|
||||||
skippedActions,
|
|
||||||
computedStates,
|
|
||||||
currentStateIndex,
|
|
||||||
monitorState,
|
|
||||||
timestamps
|
|
||||||
} = liftedAction.newState
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case ActionTypes.ROLLBACK:
|
case ActionTypes.ROLLBACK:
|
||||||
stagedActions = [INIT_ACTION];
|
stagedActions = [INIT_ACTION];
|
||||||
|
@ -280,11 +269,8 @@ export const ActionCreators = {
|
||||||
commit() {
|
commit() {
|
||||||
return { type: ActionTypes.COMMIT, timestamp: Date.now() };
|
return { type: ActionTypes.COMMIT, timestamp: Date.now() };
|
||||||
},
|
},
|
||||||
export() {
|
importState(nextLiftedState) {
|
||||||
return { type: ActionTypes.EXPORT };
|
return { type: ActionTypes.IMPORT_STATE, nextLiftedState };
|
||||||
},
|
|
||||||
import(newState) {
|
|
||||||
return { type: ActionTypes.IMPORT, newState };
|
|
||||||
},
|
},
|
||||||
sweep() {
|
sweep() {
|
||||||
return { type: ActionTypes.SWEEP };
|
return { type: ActionTypes.SWEEP };
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
|
/* eslint-disable no-alert */
|
||||||
import React, { PropTypes, findDOMNode, Component } from 'react';
|
import React, { PropTypes, findDOMNode, Component } from 'react';
|
||||||
import LogMonitorEntry from './LogMonitorEntry';
|
import LogMonitorEntry from './LogMonitorEntry';
|
||||||
import LogMonitorButton from './LogMonitorButton';
|
import LogMonitorButton from './LogMonitorButton';
|
||||||
import LogMonitorTextarea from './LogMonitorTextarea';
|
|
||||||
import * as themes from './themes';
|
import * as themes from './themes';
|
||||||
|
|
||||||
const EXPORT_CONTAINER_HEIGHT = 150;
|
|
||||||
const ELEMENTS_CONTAINER_TOP = 38;
|
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
container: {
|
container: {
|
||||||
fontFamily: 'monaco, Consolas, Lucida Console, monospace',
|
fontFamily: 'monaco, Consolas, Lucida Console, monospace',
|
||||||
|
@ -29,7 +26,7 @@ const styles = {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
top: ELEMENTS_CONTAINER_TOP,
|
top: 38,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
overflowX: 'hidden',
|
overflowX: 'hidden',
|
||||||
overflowY: 'auto'
|
overflowY: 'auto'
|
||||||
|
@ -123,11 +120,18 @@ export default class LogMonitor extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleExport() {
|
handleExport() {
|
||||||
this.props.export();
|
window.prompt('Current state\'s schema', JSON.stringify(this.props.store.getState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleImport(newState) {
|
handleImport() {
|
||||||
this.props.import(newState);
|
try {
|
||||||
|
let nextLiftedState = window.prompt('Please paste a valid action log');
|
||||||
|
if (nextLiftedState) {
|
||||||
|
this.props.importState(JSON.parse(nextLiftedState));
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('There was an error parsing the new state. Please enter a valid schema.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleToggleAction(index) {
|
handleToggleAction(index) {
|
||||||
|
@ -196,13 +200,14 @@ export default class LogMonitor extends Component {
|
||||||
<LogMonitorButton theme={theme} onClick={::this.handleRollback} enabled={computedStates.length}>Revert</LogMonitorButton>
|
<LogMonitorButton theme={theme} onClick={::this.handleRollback} enabled={computedStates.length}>Revert</LogMonitorButton>
|
||||||
<LogMonitorButton theme={theme} onClick={::this.handleSweep} enabled={Object.keys(skippedActions).some(key => skippedActions[key])}>Sweep</LogMonitorButton>
|
<LogMonitorButton theme={theme} onClick={::this.handleSweep} enabled={Object.keys(skippedActions).some(key => skippedActions[key])}>Sweep</LogMonitorButton>
|
||||||
<LogMonitorButton theme={theme} onClick={::this.handleCommit} enabled={computedStates.length > 1}>Commit</LogMonitorButton>
|
<LogMonitorButton theme={theme} onClick={::this.handleCommit} enabled={computedStates.length > 1}>Commit</LogMonitorButton>
|
||||||
|
<LogMonitorButton theme={theme} onClick={::this.handleImport} enabled={true}>Import</LogMonitorButton>
|
||||||
<LogMonitorButton theme={theme} onClick={::this.handleExport} enabled={computedStates.length}>Export</LogMonitorButton>
|
<LogMonitorButton theme={theme} onClick={::this.handleExport} enabled={computedStates.length}>Export</LogMonitorButton>
|
||||||
</div>
|
</div>
|
||||||
<LogMonitorTextarea theme={theme} handleImport={::this.handleImport} currentState={this.props.store.getState()} />
|
<div style={styles.elements} ref="elements">
|
||||||
<div style={{...styles.elements, top: monitorState.exportMode ? EXPORT_CONTAINER_HEIGHT : ELEMENTS_CONTAINER_TOP }} ref="elements">
|
|
||||||
{elements}
|
{elements}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* eslint-enable no-alert */
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
import React, { PropTypes, findDOMNode, Component } from 'react';
|
|
||||||
|
|
||||||
const EXPORT_CONTAINER_HEIGHT = 150;
|
|
||||||
const ELEMENTS_CONTAINER_TOP = 38;
|
|
||||||
|
|
||||||
var styles = {
|
|
||||||
exportContainer: {
|
|
||||||
width: '100%',
|
|
||||||
height: EXPORT_CONTAINER_HEIGHT
|
|
||||||
},
|
|
||||||
exportArea: {
|
|
||||||
position: 'relative',
|
|
||||||
resize: 'none',
|
|
||||||
width: '100%',
|
|
||||||
height: 112,
|
|
||||||
backgroundColor: '#4F5A66',
|
|
||||||
color: 'white'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default class LogMonitorTextarea extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
}
|
|
||||||
|
|
||||||
parseInput(event) {
|
|
||||||
try {
|
|
||||||
this.props.handleImport(JSON.parse(event.target.value))
|
|
||||||
} catch(err) {
|
|
||||||
console.warn('There was an error parsing the new state. Please enter a valid schema.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
let { handleImport, currentState, theme } = this.props;
|
|
||||||
return currentState.monitorState.exportMode ? (
|
|
||||||
<div style={{...styles.exportContainer, backgroundColor: theme.base00}}>
|
|
||||||
<textarea style={styles.exportArea} value={JSON.stringify(currentState)} onChange={::this.parseInput} />
|
|
||||||
</div>
|
|
||||||
) : null;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user