@@ -2,29 +2,47 @@ import alertsData from '../lib/alerts/index.jsx';
22import { AlertTypes , AlertLevels } from '../lib/alerts/index.jsx' ;
33import extensionData from '../lib/libraries/extensions/index.jsx' ;
44
5- const SHOW_STANDARD_ALERT = 'scratch-gui/alerts/SHOW_STANDARD_ALERT ' ;
5+ const SHOW_ALERT = 'scratch-gui/alerts/SHOW_ALERT ' ;
66const SHOW_EXTENSION_ALERT = 'scratch-gui/alerts/SHOW_EXTENSION_ALERT' ;
77const CLOSE_ALERT = 'scratch-gui/alerts/CLOSE_ALERT' ;
88const CLOSE_ALERTS_WITH_ID = 'scratch-gui/alerts/CLOSE_ALERTS_WITH_ID' ;
99
10+ /**
11+ * Initial state of alerts reducer
12+ *
13+ * {bool} visible - whether the alerts are visible
14+ * {array} alertsList - list of alerts, each with properties:
15+ * * alertType (required): one of AlertTypes
16+ * * closeButton (optional): bool indicating that we should show close button
17+ * * content (optional): react element (a <FormattedMessage />)
18+ * * extentionId (optional): id string that identifies the extension
19+ * * iconURL (optional): string
20+ * * level (required): string, one of AlertLevels
21+ * * message (optional): string
22+ * * showReconnect (optional): bool
23+ */
1024const initialState = {
1125 visible : true ,
12- // list of alerts, each with properties:
13- // * alert type (required): one of AlertTypes
14- // * closeButton (optional): bool indicating that we should show close button
15- // * content (optional): react element (a <FormattedMessage />)
16- // * extentionId (optional): id string that identifies the extension
17- // * iconURL (optional): string
18- // * level (required): string, one of AlertLevels
19- // * message (optional): string
20- // * showReconnect (optional): bool
2126 alertsList : [ ]
2227} ;
2328
29+ const filterPopupAlerts = alertsList => (
30+ alertsList . filter ( curAlert => (
31+ curAlert . alertType === AlertTypes . STANDARD ||
32+ curAlert . alertType === AlertTypes . EXTENSION
33+ ) )
34+ ) ;
35+
36+ const filterInlineAlerts = alertsList => (
37+ alertsList . filter ( curAlert => (
38+ curAlert . alertType === AlertTypes . INLINE
39+ ) )
40+ ) ;
41+
2442const reducer = function ( state , action ) {
2543 if ( typeof state === 'undefined' ) state = initialState ;
2644 switch ( action . type ) {
27- case SHOW_STANDARD_ALERT : { // also will show inline alerts
45+ case SHOW_ALERT : { // intended to show standard and inline alerts, but not extensions
2846 const alertId = action . alertId ;
2947 if ( alertId ) {
3048 const newAlert = {
@@ -134,7 +152,7 @@ const closeAlertsWithId = function (alertId) {
134152 */
135153const showStandardAlert = function ( alertId ) {
136154 return {
137- type : SHOW_STANDARD_ALERT ,
155+ type : SHOW_ALERT ,
138156 alertId
139157 } ;
140158} ;
@@ -177,6 +195,8 @@ export {
177195 reducer as default ,
178196 initialState as alertsInitialState ,
179197 closeAlert ,
198+ filterInlineAlerts ,
199+ filterPopupAlerts ,
180200 showAlertWithTimeout ,
181201 showExtensionAlert ,
182202 showStandardAlert
0 commit comments