Skip to content

Commit 1a02ffa

Browse files
committed
fix(alerts): ensure no alerts with TRAMS filter are ever encountered
1 parent 248b959 commit 1a02ffa

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

lib/alerts/actions/alerts.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,8 @@ export function fetchRtdAlerts () {
107107
}
108108
return res.json()
109109
})
110-
.then((alerts) => {
111-
return dispatch(receivedRtdAlerts(alerts, getActiveProject(getState())))
112-
})
113-
.then(() => {
114-
return dispatch(fetchStopsAndRoutes(getState().alerts.entities, 'ALERTS'))
115-
})
110+
.then((alerts) => dispatch(receivedRtdAlerts(alerts, getActiveProject(getState()))))
111+
.then(() => dispatch(fetchStopsAndRoutes(getState().alerts.entities, 'ALERTS')))
116112
}
117113
}
118114

lib/alerts/reducers/alerts.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,23 @@ const alerts = (state = defaultState, action) => {
7676

7777
case 'RECEIVED_RTD_ALERTS':
7878
const entityList = []
79-
alerts = action.rtdAlerts
80-
for (let i = 0; i < alerts.length; i++) {
81-
const action = alerts[i]
79+
// For MTC, filter out all alerts that were created with the TRAMS tool,
80+
// as indicated by EditedBy=TRAMS
81+
const alerts = action.rtdAlerts.filter(alert => alert.EditedBy !== 'TRAMS')
82+
alerts.forEach(action => {
8283
if (typeof action !== 'undefined' && action.ServiceAlertEntities && action.ServiceAlertEntities.length > 0) {
8384
for (var j = 0; j < action.ServiceAlertEntities.length; j++) {
84-
const ent = action.ServiceAlertEntities[j]
85-
if (ent.StopId !== null) {
86-
entityList.push({type: 'stop', entity: ent, gtfs: {}})
85+
const entity = action.ServiceAlertEntities[j]
86+
if (entity.StopId !== null) {
87+
entityList.push({type: 'stop', entity, gtfs: {}})
8788
}
88-
if (ent.RouteId !== null) {
89-
entityList.push({type: 'route', entity: ent, gtfs: {}})
89+
if (entity.RouteId !== null) {
90+
entityList.push({type: 'route', entity, gtfs: {}})
9091
}
9192
}
9293
}
93-
}
94-
const allAlerts = action.rtdAlerts ? action.rtdAlerts
95-
.filter(rtdAlert => rtdAlert.EditedBy !== 'TRAMS')
94+
})
95+
const allAlerts = alerts ? alerts
9696
.map(rtdAlert => {
9797
// let activeIndex = action.projects.findIndex(p => p.id == config.activeProjectId)
9898
const {activeProject: project} = action
@@ -105,7 +105,9 @@ const alerts = (state = defaultState, action) => {
105105
title: rtdAlert.HeaderText || '',
106106
// RTD server sends back two-char new lines, which can mess up character limit counts
107107
// Here, we replace any of those occurrences with a single new line char.
108-
description: rtdAlert.DescriptionText ? rtdAlert.DescriptionText.replace(/(\r\n)/g, '\n') : '',
108+
description: rtdAlert.DescriptionText
109+
? rtdAlert.DescriptionText.replace(/(\r\n)/g, '\n')
110+
: '',
109111
cause: rtdAlert.Cause,
110112
effect: rtdAlert.Effect,
111113
editedBy: rtdAlert.EditedBy,

0 commit comments

Comments
 (0)