Skip to content

Commit

Permalink
feat(alerts-reducer): filter out TRAMS alerts for MTC
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Jul 10, 2017
1 parent 729a05c commit 19c60cc
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions lib/alerts/reducers/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,55 +91,55 @@ const alerts = (state = defaultState, action) => {
}
}
}
const allAlerts = action.rtdAlerts ? action.rtdAlerts.map((rtdAlert) => {
// let activeIndex = action.projects.findIndex(p => p.id == config.activeProjectId)
const project = action.activeProject // action.projects[activeIndex]
const allAlerts = action.rtdAlerts ? action.rtdAlerts
.filter(rtdAlert => rtdAlert.EditedBy !== 'TRAMS')
.map(rtdAlert => {
// let activeIndex = action.projects.findIndex(p => p.id == config.activeProjectId)
const {activeProject: project} = action

const alert = {
id: rtdAlert.Id,
title: rtdAlert.HeaderText,
description: rtdAlert.DescriptionText.replace(/(\r\n)/g, '\n'), // RTD server sends back two-char new lines, which can mess up character limit counts
cause: rtdAlert.Cause,
effect: rtdAlert.Effect,
editedBy: rtdAlert.EditedBy,
editedDate: rtdAlert.EditedDate,
url: rtdAlert.Url,
start: rtdAlert.StartDateTime * 1000,
end: rtdAlert.EndDateTime * 1000,
published: rtdAlert.Published === 'Yes',
affectedEntities: rtdAlert.ServiceAlertEntities.map((ent) => {
const entity = {
id: ent.Id
}

if (ent.AgencyId !== null) {
const feed = project.feedSources.find(f => getFeedId(f) === ent.AgencyId)
entity.agency = feed
entity.type = 'AGENCY'
}

// stop goes ahead of route type and route because it's an optional field in the below
if (ent.StopId !== null) {
entity.stop_id = ent.StopId
entity.type = 'STOP'
}
if (ent.RouteId !== null) {
entity.route_id = ent.RouteId
entity.type = 'ROUTE'
}

if (ent.RouteType !== null) {
const mode = modes.find(m => m.gtfsType === ent.RouteType)

// catch any integers outside of 0 -7 range
entity.mode = typeof mode !== 'undefined' ? mode : modes.find(m => m.gtfsType === 0)
entity.type = 'MODE'
}
return entity
})
}
return alert
})
const alert = {
id: rtdAlert.Id,
title: rtdAlert.HeaderText,
description: rtdAlert.DescriptionText.replace(/(\r\n)/g, '\n'), // RTD server sends back two-char new lines, which can mess up character limit counts
cause: rtdAlert.Cause,
effect: rtdAlert.Effect,
editedBy: rtdAlert.EditedBy,
editedDate: rtdAlert.EditedDate,
url: rtdAlert.Url,
start: rtdAlert.StartDateTime * 1000,
end: rtdAlert.EndDateTime * 1000,
published: rtdAlert.Published === 'Yes',
affectedEntities: rtdAlert.ServiceAlertEntities.map(ent => {
const entity = {
id: ent.Id
}
if (ent.AgencyId !== null) {
const feed = project.feedSources.find(f => getFeedId(f) === ent.AgencyId)
entity.agency = feed
entity.type = 'AGENCY'
}
// stop goes ahead of route type and route because it's an optional field in the below
if (ent.StopId !== null) {
entity.stop_id = ent.StopId
entity.type = 'STOP'
}
if (ent.RouteId !== null) {
entity.route_id = ent.RouteId
entity.type = 'ROUTE'
}
if (ent.RouteType !== null) {
const mode = modes.find(m => m.gtfsType === ent.RouteType)
// catch any integers outside of 0 -7 range
entity.mode = typeof mode !== 'undefined'
? mode
: modes.find(m => m.gtfsType === 0)
entity.type = 'MODE'
}
return entity
})
}
return alert
})
: []
const filterCounts = {}
FILTERS.map(f => {
Expand Down

0 comments on commit 19c60cc

Please sign in to comment.