-
Notifications
You must be signed in to change notification settings - Fork 7
/
AppContainer.jsx
122 lines (112 loc) · 4.07 KB
/
AppContainer.jsx
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import TopBar from './TopBar/TopBar.jsx'
import LeftSideBar from './LeftSideBar.jsx'
import SpreadsheetContainer from './SpreadsheetContainer/SpreadsheetContainer.jsx'
import { ActionCreators as UndoActionCreators } from 'redux-undo'
import { connect } from 'react-redux'
import { DragDropContext } from 'react-dnd'
import HTML5Backend from 'react-dnd-html5-backend'
import { ToastContainer } from 'react-toastify'
import { JOYRIDE_STEPS, CALCULATOR_STEPS, COLORMAP_STEPS, LOAD_VARIABLE_STEPS } from '../constants/Constants.js'
import Joyride from 'react-joyride'
import 'react-joyride/lib/react-joyride.scss'
/* global jQuery */
class AppContainer extends Component{
constructor(props){
super(props)
this.state = {
jr_steps: JOYRIDE_STEPS,
jr_run: false,
jr_auto_start: false,
}
this.startTour = this.startTour.bind(this)
this.handleJoyrideEvents = this.handleJoyrideEvents.bind(this)
}
startTour(steps){
if(this.joyride){
var STEPS = {}
switch(steps){
case 0: STEPS = JOYRIDE_STEPS; break;
case 1: STEPS = CALCULATOR_STEPS; break;
case 2: STEPS = COLORMAP_STEPS; break;
case 3: STEPS = LOAD_VARIABLE_STEPS; break;
}
this.setState({jr_run: true, jr_steps: STEPS})
}
}
handleJoyrideEvents(event){
if(!event){
console.warn("jr event was undefined")
return
}
switch(event.type){
case "step:after":
if(event.action !== "close"){
return // Only continue to reset on a close action
}
// falls through.
case "overlay:click":
case "finished":
this.setState({jr_run: false},() => {
this.joyride.reset(false) // pass .reset(false) so it does not start the tour again immediately
})
return
case "error:target_not_found":
console.warn("Joyride element missing on step ", event.index)
}
}
render() {
return (
<div id='app-container'>
<Joyride
ref={(el)=>{this.joyride = el}}
steps={this.state.jr_steps}
run={this.state.jr_run}
autoStart={true}
type='continuous'
showSkipButton={true}
showStepsProgress={true}
scrollToSteps={false}
scrollToFirstStep={false}
holePadding={0}
locale={{ back: 'Back', close: 'Close', last: 'Finish', next: 'Next', skip: 'Skip' }}
callback={this.handleJoyrideEvents}
/>
<TopBar
onUndo={this.props.undo}
onRedo={this.props.redo}
undoEnabled={this.props.undoEnabled}
redoEnabled={this.props.redoEnabled}
startTour={this.startTour}
/>
<div id="main-container">
<LeftSideBar startTour={this.startTour} resizeSpreadsheet={this.resizeSpreadsheet} />
<SpreadsheetContainer />
</div>
<ToastContainer />
</div>
);
}
}
AppContainer.propTypes = {
undo: PropTypes.func,
redo: PropTypes.func,
undoEnabled: PropTypes.bool,
redoEnabled: PropTypes.bool
}
const mapStateToProps = (state) => {
var undoEnabled = state.past.length > 0;
var redoEnabled = state.future.length > 0;
return jQuery.extend({}, state.present, {
undoEnabled: undoEnabled,
redoEnabled: redoEnabled
});
};
const mapDispatchToProps = (dispatch) => {
return {
undo: () => dispatch(UndoActionCreators.undo()),
redo: () => dispatch(UndoActionCreators.redo())
};
};
export default DragDropContext(HTML5Backend)(connect(mapStateToProps, mapDispatchToProps)(AppContainer));