forked from ibi-group/datatools-ui
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from catalogueglobal/dev
Version release
- Loading branch information
Showing
7 changed files
with
375 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import update from 'react-addons-update' | ||
|
||
import {getEntityGraphQLRoot, getEntityIdField} from '../../gtfs/util' | ||
|
||
const defaultState = { | ||
fetchStatus: { | ||
fetched: false, | ||
fetching: false, | ||
error: false | ||
}, | ||
data: [] | ||
} | ||
|
||
export default function reducer (state = defaultState, action) { | ||
switch (action.type) { | ||
case 'SET_ACTIVE_FEEDVERSION': | ||
return defaultState | ||
case 'FETCH_GRAPHQL_ROUTES': | ||
return { | ||
fetchStatus: { | ||
fetched: false, | ||
fetching: true, | ||
error: false | ||
}, | ||
data: [] | ||
} | ||
case 'FETCH_GRAPHQL_ROUTES_REJECTED': | ||
return update(state, { | ||
fetchStatus: { | ||
$set: { | ||
fetched: false, | ||
fetching: false, | ||
error: true | ||
} | ||
} | ||
}) | ||
case 'RECEIVE_GTFS_ENTITIES': | ||
const type = action.payload.type | ||
const entities = action.payload.data.feed[getEntityGraphQLRoot(type)] | ||
entities.forEach(entity => { | ||
const id = entity[getEntityIdField(type)] | ||
entity._id = `${type}:${id}` | ||
}) | ||
return update(state, { | ||
data: {$push: entities} | ||
}) | ||
default: | ||
return state | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// @flow | ||
|
||
export function getEntityIdField (type: string): string { | ||
if (!type) return '' | ||
switch (type.toLowerCase()) { | ||
case 'stop': | ||
return 'stop_id' | ||
case 'route': | ||
return 'route_id' | ||
case 'trip': | ||
return 'trip_id' | ||
case 'stoptime': | ||
return 'trip_id' | ||
case 'service': | ||
return 'service_id' | ||
case 'pattern': | ||
return 'pattern_id' | ||
default: | ||
return '' | ||
} | ||
} | ||
|
||
export function getEntityGraphQLRoot (type: string): string { | ||
if (!type) return '' | ||
switch (type.toLowerCase()) { | ||
case 'stop': | ||
return 'stops' | ||
case 'route': | ||
return 'routes' | ||
case 'trip': | ||
return 'trips' | ||
case 'stoptime': | ||
return 'trips' | ||
case 'service': | ||
return 'services' | ||
case 'pattern': | ||
return 'patterns' | ||
default: | ||
return '' | ||
} | ||
} | ||
|
||
export function getEntityTableString (type: string): string { | ||
if (!type) return '' | ||
switch (type.toLowerCase()) { | ||
case 'stop': | ||
return 'stop' | ||
case 'route': | ||
return 'route' | ||
case 'trip': | ||
return 'trip' | ||
case 'stoptime': | ||
return 'stop_time' | ||
case 'service': | ||
return 'services' | ||
case 'pattern': | ||
return 'patterns' | ||
default: | ||
return '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.