@@ -19,7 +19,11 @@ import ActionEditor from './ActionEditor';
19
19
import Loader from '../common/Loader' ;
20
20
import Main from '../common/Main' ;
21
21
import { getDatabase } from '../../actions' ;
22
- import { FILTER_ALL_SPACE_ID , USER_MODES } from '../../config/constants' ;
22
+ import {
23
+ FILTER_ALL_SPACES_ID ,
24
+ FILTER_ALL_USERS_ID ,
25
+ USER_MODES ,
26
+ } from '../../config/constants' ;
23
27
import { DASHBOARD_MAIN_ID } from '../../config/selectors' ;
24
28
25
29
const styles = theme => ( {
@@ -36,7 +40,8 @@ const styles = theme => ({
36
40
37
41
export class Dashboard extends Component {
38
42
state = {
39
- spaceId : FILTER_ALL_SPACE_ID ,
43
+ spaceId : FILTER_ALL_SPACES_ID ,
44
+ filteredUserId : FILTER_ALL_USERS_ID ,
40
45
} ;
41
46
42
47
static propTypes = {
@@ -69,6 +74,7 @@ export class Dashboard extends Component {
69
74
database : PropTypes . shape ( {
70
75
user : PropTypes . object ,
71
76
spaces : PropTypes . arrayOf ( PropTypes . object ) ,
77
+ users : PropTypes . arrayOf ( PropTypes . object ) ,
72
78
actions : PropTypes . arrayOf ( PropTypes . object ) ,
73
79
} ) ,
74
80
dispatchGetDatabase : PropTypes . func . isRequired ,
@@ -89,6 +95,10 @@ export class Dashboard extends Component {
89
95
this . setState ( { spaceId : event . target . value } ) ;
90
96
} ;
91
97
98
+ handleUserChange = event => {
99
+ this . setState ( { filteredUserId : event . target . value } ) ;
100
+ } ;
101
+
92
102
renderSpaceFilter = ( ) => {
93
103
const { database, t } = this . props ;
94
104
const { spaceId } = this . state ;
@@ -105,7 +115,7 @@ export class Dashboard extends Component {
105
115
value = { spaceId }
106
116
onChange = { this . handleSpaceChange }
107
117
>
108
- < MenuItem value = { FILTER_ALL_SPACE_ID } >
118
+ < MenuItem value = { FILTER_ALL_SPACES_ID } >
109
119
< em > { t ( 'All Spaces' ) } </ em >
110
120
</ MenuItem >
111
121
{ database . spaces . map ( space => (
@@ -116,19 +126,54 @@ export class Dashboard extends Component {
116
126
) ;
117
127
} ;
118
128
129
+ renderUserFilter = ( ) => {
130
+ const { database, t, userMode } = this . props ;
131
+ const { filteredUserId } = this . state ;
132
+
133
+ if ( ! database || _ . isEmpty ( database ) ) {
134
+ return < Loader /> ;
135
+ }
136
+
137
+ if ( userMode !== USER_MODES . TEACHER ) {
138
+ return null ;
139
+ }
140
+
141
+ return (
142
+ < FormControl variant = "outlined" fullWidth >
143
+ < InputLabel > { t ( 'Filter by User' ) } </ InputLabel >
144
+ < Select
145
+ label = "Filter by User"
146
+ value = { filteredUserId }
147
+ onChange = { this . handleUserChange }
148
+ >
149
+ < MenuItem value = { FILTER_ALL_USERS_ID } >
150
+ < em > { t ( 'All Users' ) } </ em >
151
+ </ MenuItem >
152
+ { database . users . map ( user => (
153
+ < MenuItem value = { user . id } > { user . username } </ MenuItem >
154
+ ) ) }
155
+ </ Select >
156
+ </ FormControl >
157
+ ) ;
158
+ } ;
159
+
119
160
renderActionWidgets = ( ) => {
120
161
const { database, t, classes, userMode, userId } = this . props ;
121
- const { spaceId } = this . state ;
162
+ const { spaceId, filteredUserId } = this . state ;
122
163
123
164
let filteredActions = database . actions ;
124
165
125
- // filter action per user if userMode is student
166
+ // filter action per user if userMode is student or with filter
126
167
if ( userMode === USER_MODES . STUDENT ) {
127
168
filteredActions = filteredActions . filter ( ( { user } ) => user === userId ) ;
169
+ } else if ( filteredUserId !== FILTER_ALL_USERS_ID ) {
170
+ filteredActions = filteredActions . filter (
171
+ ( { user } ) => user === filteredUserId
172
+ ) ;
128
173
}
129
174
130
175
// filter action per space
131
- if ( spaceId !== FILTER_ALL_SPACE_ID ) {
176
+ if ( spaceId !== FILTER_ALL_SPACES_ID ) {
132
177
filteredActions = filteredActions . filter (
133
178
( { spaceId : id } ) => id === spaceId
134
179
) ;
@@ -164,7 +209,7 @@ export class Dashboard extends Component {
164
209
165
210
render ( ) {
166
211
const { classes, t, database } = this . props ;
167
- const { spaceId } = this . state ;
212
+ const { spaceId, filteredUserId } = this . state ;
168
213
169
214
if ( ! database ) {
170
215
return < Loader /> ;
@@ -184,19 +229,22 @@ export class Dashboard extends Component {
184
229
alignItems = "center"
185
230
spacing = { 3 }
186
231
>
187
- < Grid item xs = { 12 } sm = { 9 } >
232
+ < Grid item xs = { 12 } sm = { 6 } >
188
233
< Typography variant = "h4" className = { classes . screenTitle } >
189
234
{ t ( 'Dashboard' ) }
190
235
</ Typography >
191
236
</ Grid >
237
+ < Grid item xs = { 12 } sm = { 3 } >
238
+ { this . renderUserFilter ( ) }
239
+ </ Grid >
192
240
< Grid item xs = { 12 } sm = { 3 } >
193
241
{ this . renderSpaceFilter ( ) }
194
242
</ Grid >
195
243
</ Grid >
196
244
197
245
{ this . renderActionWidgets ( ) }
198
246
199
- < ActionEditor spaceId = { spaceId } />
247
+ < ActionEditor spaceId = { spaceId } userId = { filteredUserId } />
200
248
</ div >
201
249
</ Main >
202
250
) ;
0 commit comments