File tree Expand file tree Collapse file tree 7 files changed +81
-6
lines changed Expand file tree Collapse file tree 7 files changed +81
-6
lines changed Original file line number Diff line number Diff line change 8
8
margin : 100px 0 ;
9
9
10
10
}
11
+ .notices {
12
+ .test-message {
13
+ display : flex ;
14
+ align-items : center ;
15
+ justify-content : space-between ;
16
+ width : 500px ;
17
+ }
18
+ }
11
19
12
20
.exercisePreview-demo , .exercise-demo , .multipartExercise-demo {
13
21
max-width : 800px ;
Original file line number Diff line number Diff line change @@ -312,9 +312,26 @@ NoticesDemo = React.createClass
312
312
)
313
313
Notifications .startPolling ()
314
314
315
+ showMessage : ->
316
+ Notifications .display (
317
+ message : @refs .message .getDOMNode ().value ,
318
+ level : @refs .type .getDOMNode ().value
319
+ )
320
+
315
321
render : ->
316
322
<div className = " notices" >
317
323
<NotificationBar />
324
+ <div className = " test-message" >
325
+ <span >Test Message : </span >
326
+ <input type = " text" ref = " message" />
327
+ <select ref = " type" >
328
+ <option value = " success" >Success</option >
329
+ <option value = " notice" selected>Notice</option >
330
+ <option value = " alert" >Alert</option >
331
+ <option value = " error" >Error</option >
332
+ </select >
333
+ <button onClick = {@showMessage }>Display</button >
334
+ </div >
318
335
<button onClick = {@startPoll }>Start Polling</button >
319
336
</div >
320
337
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ _ = require 'underscore'
4
4
Notifications = require ' ../../model/notifications'
5
5
6
6
TYPES =
7
- tutor : require ' ./system'
7
+ system : require ' ./system'
8
8
accounts : require ' ./email'
9
9
10
10
NotificationBar = React .createClass
@@ -23,7 +23,7 @@ NotificationBar = React.createClass
23
23
24
24
<div className = " openstax-notifications-bar" >
25
25
{for notice in notifications
26
- Component = TYPES[notice .type ]
26
+ Component = TYPES[notice .type ] or TYPES[ ' system ' ]
27
27
<Component key = {notice .id } notice = {notice} />}
28
28
</div >
29
29
Original file line number Diff line number Diff line change 1
1
React = require ' react'
2
+ classnames = require ' classnames'
2
3
3
4
Notifications = require ' ../../model/notifications'
4
5
@@ -13,10 +14,19 @@ SystemNotification = React.createClass
13
14
Notifications .acknowledge (@props .notice )
14
15
undefined # silence React warning about return value
15
16
17
+ getIcon : ->
18
+ return @props .notice .icon if @props .notice .icon
19
+ switch @props .notice .level
20
+ when ' alert' then ' exclamation-triangle'
21
+ when ' error' , ' warning' then ' exclamation-circle'
22
+ else
23
+ ' info-circle'
24
+
16
25
render : ->
17
- <div className = " notification system" >
26
+
27
+ <div className = {classnames (' notification' , ' system' , @props .notice .level )}>
18
28
<span className = " body" >
19
- <i className = ' icon fa fa-info-circle ' />
29
+ <i className = { " icon fa fa-#{ @ getIcon () } " } />
20
30
{@props .notice .message }
21
31
</span >
22
32
<a className = ' dismiss' onClick = {@acknowledge }>Dismiss</a >
Original file line number Diff line number Diff line change @@ -5,10 +5,18 @@ URLs = require './urls'
5
5
EVENT_BUS = new EventEmitter2
6
6
POLLERS = {}
7
7
8
+ NOTICES = []
9
+
10
+ CLIENT_ID = ' client-specified'
8
11
Poller = require ' ./notifications/pollers'
9
12
10
13
Notifications = {
11
14
15
+ display : (notice ) ->
16
+ # fill in an id and type if not provided
17
+ NOTICES .push ( _ .defaults (_ .clone (notice), id : _ .uniqueId (CLIENT_ID), type : CLIENT_ID ))
18
+ @ emit (' change' )
19
+
12
20
_startPolling : (type , url ) ->
13
21
POLLERS[type] ||= Poller .forType (@ , type)
14
22
POLLERS[type].setUrl (url)
@@ -24,10 +32,14 @@ Notifications = {
24
32
25
33
26
34
acknowledge : (notice ) ->
27
- POLLERS[notice .type ].acknowledge (notice)
35
+ if notice .type is CLIENT_ID
36
+ NOTICES = _ .without (NOTICES, _ .findWhere (NOTICES, id : notice .id ))
37
+ @ emit (' change' )
38
+ else
39
+ POLLERS[notice .type ].acknowledge (notice)
28
40
29
41
getActive : ->
30
- notices = []
42
+ notices = _ . clone NOTICES
31
43
for type, poller of POLLERS
32
44
notices = notices .concat ( poller .getActiveNotifications () )
33
45
notices
Original file line number Diff line number Diff line change @@ -20,3 +20,13 @@ describe 'System Notifications', ->
20
20
Testing .renderComponent ( SystemNotifications, props : @props ).then ({dom}) =>
21
21
Testing .actions .click (dom .querySelector (' .dismiss' ))
22
22
expect (Notifications .acknowledge ).to .have .been .calledWith (@props .notice )
23
+
24
+ it ' displays icon based on level' , ->
25
+ @props .notice .level = ' alert'
26
+ Testing .renderComponent ( SystemNotifications, props : @props ).then ({dom}) ->
27
+ expect (dom .querySelector (' .fa-exclamation-triangle' )).to .exist
28
+
29
+ it ' displays icon provided' , ->
30
+ @props .notice .icon = ' beer'
31
+ Testing .renderComponent ( SystemNotifications, props : @props ).then ({dom}) ->
32
+ expect (dom .querySelector (' .fa-beer' )).to .exist
Original file line number Diff line number Diff line change @@ -25,3 +25,21 @@ describe 'Notifications', ->
25
25
URLs .update (tutor_notices_url : ' http://localhost:3001/api/notifications' )
26
26
Notifications .startPolling (@windowImpl )
27
27
expect (Poller :: poll ).to .have .callCount (2 )
28
+
29
+
30
+ it ' can display and confirm manual notifications' , ->
31
+ changeListener = sinon .stub ()
32
+ notice = {message : ' hello world' , icon : ' globe' }
33
+ Notifications .on (' change' , changeListener)
34
+ Notifications .display (notice)
35
+ expect (changeListener).to .have .been .called
36
+
37
+ active = Notifications .getActive ()
38
+ expect (active).to .have .length (1 )
39
+ # should have copied the object vs mutating it
40
+ expect (active[0 ]).not .to .not .equal (notice)
41
+ expect (active[0 ].type ).to .exist
42
+
43
+ Notifications .acknowledge (active[0 ])
44
+ expect (changeListener).to .have .callCount (2 )
45
+ expect (Notifications .getActive ()).to .be .empty
You can’t perform that action at this time.
0 commit comments