Skip to content

Commit c64eb5c

Browse files
authored
Merge pull request #16 from laincloud/redux
use redux
2 parents 9a1d391 + bd492f4 commit c64eb5c

37 files changed

+1389
-1266
lines changed

TODOs.org

Lines changed: 0 additions & 18 deletions
This file was deleted.

frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"moment": "^2.21.0",
1212
"react": "^16.2.0",
1313
"react-dom": "^16.2.0",
14+
"react-redux": "^5.0.7",
1415
"react-scripts": "1.1.1",
16+
"redux": "^3.7.2",
1517
"xterm": "^3.2.0"
1618
},
1719
"homepage": "/web",

frontend/src/actions/index.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// app
2+
export const changeFetchCommandsParameter = (name, value) => ({
3+
type: 'CHANGE_FETCH_COMMANDS_PARAMETER',
4+
name,
5+
value
6+
})
7+
8+
export const changeFetchSessionsParameter = (name, value) => ({
9+
type: 'CHANGE_FETCH_SESSIONS_PARAMETER',
10+
name,
11+
value
12+
})
13+
14+
export const changeReplaySessionID = sessionID => ({
15+
type: 'CHANGE_REPLAY_SESSION_ID',
16+
sessionID
17+
})
18+
19+
export const changeTabIndex = tabIndex => ({
20+
type: 'CHANGE_TAB_INDEX',
21+
tabIndex
22+
})
23+
24+
export const fetchCommands = (offset, onFulfilled) => ({
25+
type: 'FETCH_COMMANDS',
26+
offset,
27+
onFulfilled
28+
})
29+
30+
export const fetchSessions = (offset, onFulfilled) => ({
31+
type: 'FETCH_SESSIONS',
32+
offset,
33+
onFulfilled
34+
})
35+
36+
export const searchCommandsInOneSession = (sessionID, since) => ({
37+
type: 'SEARCH_COMMANDS_IN_ONE_SESSION',
38+
sessionID,
39+
since
40+
})
41+
42+
// commands
43+
export const changeCommandsPage = page => ({
44+
type: 'CHANGE_COMMANDS_PAGE',
45+
page
46+
})
47+
48+
export const changeCommandsRowsPerPage = rowsPerPage => ({
49+
type: 'CHANGE_COMMANDS_ROWS_PER_PAGE',
50+
rowsPerPage
51+
})
52+
53+
export const onFulfilledFetchCommands = offset => response => ({
54+
type: 'ON_FULFILLED_FETCH_COMMANDS',
55+
offset,
56+
response
57+
})
58+
59+
export const sortCommands = orderBy => ({
60+
type: 'SORT_COMMANDS',
61+
orderBy
62+
})
63+
64+
// session
65+
export const changeSessionsPage = page => ({
66+
type: 'CHANGE_SESSIONS_PAGE',
67+
page
68+
})
69+
70+
export const changeSessionsRowsPerPage = rowsPerPage => ({
71+
type: 'CHANGE_SESSIONS_ROWS_PER_PAGE',
72+
rowsPerPage
73+
})
74+
75+
export const onFulfilledFetchSessions = offset => response => ({
76+
type: 'ON_FULFILLED_FETCH_SESSIONS',
77+
offset,
78+
response
79+
})
80+
81+
export const sortSessions = orderBy => ({
82+
type: 'SORT_SESSIONS',
83+
orderBy
84+
})
Lines changed: 23 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import {
1515
} from 'material-ui-pickers';
1616
import DateFnsUtils from 'material-ui-pickers/utils/date-fns-utils';
1717

18-
import Commands from './Commands';
19-
import Sessions from './Sessions';
20-
import SessionReplay from './SessionReplay.jsx';
18+
import Commands from '../containers/Commands';
19+
import Sessions from '../containers/Sessions';
20+
import SessionReplay from '../containers/SessionReplay';
2121
import {
2222
get
23-
} from '../MyAxios.jsx';
23+
} from '../reducers/myAxios'
2424

2525
function TabContainer(props) {
2626
return (
@@ -62,15 +62,11 @@ const styles = theme => ({
6262
class App extends React.Component {
6363
state = {
6464
user: window.localStorage.getItem('user'),
65-
commandsSessionID: '',
66-
commandsSince: new Date(),
67-
replaySessionID: 0,
68-
tabIndex: 0
6965
};
7066

7167
componentDidMount = () => {
7268
let params = new URLSearchParams(window.location.search.substring(1));
73-
let user = params.get("user");
69+
let user = params.get('user');
7470
if (user) {
7571
this.setState({
7672
user: user
@@ -106,49 +102,18 @@ class App extends React.Component {
106102
get('/api/logout', this.logout);
107103
};
108104

109-
handleReplay = (sessionID) => {
110-
this.setState({
111-
tabIndex: 2,
112-
replaySessionID: sessionID
113-
})
114-
}
115-
116-
handleSessionSearchCommands = (sessionID, since) => {
117-
this.setState({
118-
tabIndex: 1,
119-
commandsSessionID: sessionID,
120-
commandsSince: since
121-
});
122-
};
123-
124-
handleCommandsSessionIDChange = event => {
125-
this.setState({
126-
commandsSessionID: event.target.value
127-
})
128-
}
129-
130-
handleCommandsSinceChange = since => {
131-
this.setState({
132-
commandsSince: since
133-
})
134-
}
135-
136-
handleTabIndexChange = (event, tabIndex) => {
137-
this.setState({
138-
tabIndex: tabIndex,
139-
});
140-
};
141-
142105
render() {
143106
const {
144-
classes
107+
classes,
108+
commandsCount,
109+
commandsRowsPerPage,
110+
sessionsCount,
111+
sessionsRowsPerPage,
112+
tabIndex,
113+
onChangeTabIndex,
145114
} = this.props;
146115
const {
147116
user,
148-
tabIndex,
149-
commandsSessionID,
150-
commandsSince,
151-
replaySessionID
152117
} = this.state;
153118

154119
return (
@@ -177,7 +142,7 @@ class App extends React.Component {
177142
)}
178143
</Toolbar>
179144

180-
<Tabs value={tabIndex} onChange={this.handleTabIndexChange}>
145+
<Tabs value={tabIndex} onChange={onChangeTabIndex}>
181146
<Tab label="Sessions" />
182147
<Tab label="Commands" />
183148
{tabIndex === 2 && <Tab label="Replay" />}
@@ -187,25 +152,15 @@ class App extends React.Component {
187152
<div style={{display: (tabIndex === 0) ? 'block' : 'none'}}>
188153
<TabContainer>
189154
<div className={classes.main}>
190-
<Sessions
191-
onReplay={this.handleReplay}
192-
onSearchCommands={this.handleSessionSearchCommands}
193-
>
194-
</Sessions>
155+
<Sessions count={sessionsCount} rowsPerPage={sessionsRowsPerPage}/>
195156
</div>
196157
</TabContainer>
197158
</div>
198159

199160
<div style={{display: (tabIndex === 1) ? 'block' : 'none'}}>
200161
<TabContainer>
201162
<div className={classes.main}>
202-
<Commands
203-
sessionID={commandsSessionID}
204-
onSessionIDChange={this.handleCommandsSessionIDChange}
205-
since={commandsSince}
206-
onSinceChange={this.handleCommandsSinceChange}
207-
>
208-
</Commands>
163+
<Commands count={commandsCount} rowsPerPage={commandsRowsPerPage}/>
209164
</div>
210165
</TabContainer>
211166
</div>
@@ -214,10 +169,7 @@ class App extends React.Component {
214169
<div>
215170
<TabContainer>
216171
<div className={classes.main}>
217-
<SessionReplay
218-
sessionID={replaySessionID}
219-
>
220-
</SessionReplay>
172+
<SessionReplay />
221173
</div>
222174
</TabContainer>
223175
</div>
@@ -229,7 +181,13 @@ class App extends React.Component {
229181
};
230182

231183
App.propTypes = {
232-
classes: PropTypes.object.isRequired
184+
classes: PropTypes.object.isRequired,
185+
commandsCount: PropTypes.number.isRequired,
186+
commandsRowsPerPage: PropTypes.number.isRequired,
187+
sessionsCount: PropTypes.number.isRequired,
188+
sessionsRowsPerPage: PropTypes.number.isRequired,
189+
tabIndex: PropTypes.number.isRequired,
190+
onChangeTabIndex: PropTypes.func.isRequired
233191
};
234192

235193
export default withStyles(styles)(App);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import App from './App';
3+
import App from './App.jsx';
44

55
it('renders without crashing', () => {
66
const div = document.createElement('div');

0 commit comments

Comments
 (0)