Skip to content

Commit

Permalink
fix(alerts): fix issue with alert ID type mismatch
Browse files Browse the repository at this point in the history
fix #459
  • Loading branch information
landonreed committed Jul 29, 2019
1 parent 2edad94 commit e034d4e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/alerts/actions/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function deleteAlert (alert: Alert) {
}
}

export function setActiveAlert (alertId: number) {
function setActiveAlert (alertId: string) {
return function (dispatch: dispatchFn, getState: getStateFn) {
const alert = getState().alerts.all.find(a => a.id === alertId)
if (alert) {
Expand Down Expand Up @@ -202,7 +202,7 @@ export function onAlertEditorMount (
if (!alertId) {
dispatch(createAlert())
} else {
dispatch(setActiveAlert(+alertId))
dispatch(setActiveAlert(alertId))
}
if (permissionFilter !== 'edit-alert') {
dispatch(updatePermissionFilter('edit-alert'))
Expand Down
1 change: 0 additions & 1 deletion lib/alerts/components/AlertEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Props = ContainerProps & {
project: Project,
publishableFeeds: Array<Feed>,
saveAlert: typeof alertActions.saveAlert,
setActiveAlert: typeof alertActions.setActiveAlert,
setActiveProperty: typeof activeAlertActions.setActiveProperty,
setActivePublished: typeof activeAlertActions.setActivePublished,
updateActiveEntity: typeof activeAlertActions.updateActiveEntity,
Expand Down
4 changes: 1 addition & 3 deletions lib/alerts/containers/ActiveAlertEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
createAlert,
deleteAlert,
onAlertEditorMount,
saveAlert,
setActiveAlert
saveAlert
} from '../actions/alerts'
import {
setActiveProperty,
Expand Down Expand Up @@ -44,7 +43,6 @@ const mapDispatchToProps = {
deleteAlert,
onAlertEditorMount,
saveAlert,
setActiveAlert,
setActiveProperty,
setActivePublished,
updateActiveEntity
Expand Down
5 changes: 4 additions & 1 deletion lib/alerts/reducers/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ const alerts = (
case 'RECEIVED_RTD_ALERTS': {
const entityList = []
const {project, rtdAlerts} = action.payload
// console.log(rtdAlerts)
const filteredAlerts = rtdAlerts
? rtdAlerts
// For MTC, filter out all alerts that were created with the TRAMS tool,
Expand All @@ -107,6 +106,10 @@ const alerts = (
if (alert && alert.ServiceAlertEntities && alert.ServiceAlertEntities.length > 0) {
for (var j = 0; j < alert.ServiceAlertEntities.length; j++) {
const entity = alert.ServiceAlertEntities[j]
// FIXME: Cast IDs to strings until RTD updates its types.
// See https://github.com/ibi-group/datatools-ui/issues/459
entity.Id = `${entity.Id}`
entity.AlertId = `${entity.AlertId}`
if (entity.StopId) {
entityList.push({type: 'stop', entity, gtfs: {}})
}
Expand Down
4 changes: 3 additions & 1 deletion lib/alerts/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ function mapRtdEntity (rtdEntity: RtdEntity, project: Project): AlertEntity {
type = 'MODE'
}
return {
id,
// FIXME: For now RTD incorrectly returns id as an int.
// See https://github.com/ibi-group/datatools-ui/issues/459
id: `${id}`,
agency,
type,
mode,
Expand Down
4 changes: 4 additions & 0 deletions lib/gtfs/components/gtfs-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class GtfsSearch extends Component<Props, State> {
// FIXME: Need to filter on selected feeds?
.filter(feed => feed.publishedVersionId)
.map(feed => searchEntitiesWithString(input, feed.publishedVersionId, entities, filterByRoute, filterByStop, user))
if (queries.length === 0) {
console.warn('No queries to process (there are likely no published feeds).')
return
}
}
return Promise
.all(queries)
Expand Down
4 changes: 2 additions & 2 deletions lib/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ export type ZoneInfo = {

export type AlertEntity = {
agency: ?Feed,
id: number,
id: string,
mode?: ?any,
route?: GtfsRoute & {feed_id: string},
route_id?: ?string,
Expand All @@ -772,7 +772,7 @@ export type Alert = {
description: string,
effect: string,
end: number,
id: number,
id: string,
published: boolean,
start: number,
title: string,
Expand Down

0 comments on commit e034d4e

Please sign in to comment.