Skip to content

Commit

Permalink
Merge pull request #73 from SmartColumbusOS/cota_routes
Browse files Browse the repository at this point in the history
Cota routes
  • Loading branch information
ManApart authored Jul 26, 2019
2 parents 702d0a5 + 2c3bf0c commit 8b8cad8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 156 deletions.
47 changes: 14 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"apisauce": "^1.0.3",
"identity-obj-proxy": "^3.0.0",
"leaflet": "^1.5.1",
"lodash": "^4.17.15",
"node-sass": "^4.12.0",
"normalize.css": "^8.0.1",
"phoenix": "1.3.0",
Expand Down
9 changes: 6 additions & 3 deletions src/reducers/reducers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { combineReducers } from 'redux'
import { POSITION_UPDATE, ROUTE_FILTER, CEAV_UPDATE, ROUTE_UPDATE } from '../actions'
import { CEAV, COTA } from '../variables'
import _ from 'lodash'

const filter = (filter = [], action) => {
switch (action.type) {
Expand Down Expand Up @@ -60,9 +61,11 @@ const data = (data = {}, action) => {
const availableRoutes = (availableRoutes = [], action) => {
switch (action.type) {
case ROUTE_UPDATE:
let routesToUse = action.update.result.records.map((route) => {
const lineNumber = route.LINENUM.padStart(3, '0')
const lineName = `${route.LINENUM} - ${route.LINENAME}`
const sorted = _.sortBy(action.update, ({ linenum }) => linenum);
const uniqueRoutes = _.sortedUniqBy(sorted, ({ linenum }) => linenum)
let routesToUse = uniqueRoutes.map((route) => {
const lineNumber = new String(route.linenum).padStart(3, '0')
const lineName = `${route.linenum} - ${route.linename}`
return { value: lineNumber, label: lineName, provider: 'COTA' }
})
routesToUse.push({ value: CEAV, label: 'SMRT - Smart Circuit', provider: CEAV })
Expand Down
48 changes: 18 additions & 30 deletions src/reducers/reducers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,16 @@ describe('cotaApp reducers', () => {
})

it('will transform the data on a ROUTE_UPDATE action', () => {
let message = {
'help': 'not necessary',
'success': true,
'result': {
'records': [
{
'LINENUM': '1',
'LINENAME': 'Crazy Town'
},
{
'LINENUM': '101',
'LINENAME': 'Smallville'
}
]
let message = [
{
'linenum': 1,
'linename': 'Crazy Town'
},
{
'linenum': 101,
'linename': 'Smallville'
}
}
]

let state = [
{ value: '001', label: '1 - Crazy Town', provider: 'COTA' },
Expand All @@ -129,22 +123,16 @@ describe('cotaApp reducers', () => {
})

it('will append CEAV Smart Circuit on a ROUTE_UPDATE action', () => {
let message = {
'help': 'not necessary',
'success': true,
'result': {
'records': [
{
'LINENUM': '1',
'LINENAME': 'Crazy Town'
},
{
'LINENUM': '101',
'LINENAME': 'Smallville'
}
]
let message = [
{
'linenum': 1,
'linename': 'Crazy Town'
},
{
'linenum': 101,
'linename': 'Smallville'
}
}
]

let newState = reducer(undefined, { type: ROUTE_UPDATE, update: message })
expect(newState.availableRoutes[2]).toEqual({ value: 'CEAV', label: 'SMRT - Smart Circuit', provider: 'CEAV' })
Expand Down
8 changes: 3 additions & 5 deletions src/sagas/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ const COTA_LINE_DATA_SET_ID = `"2a329570-33d7-4cde-818d-6ef323e68875"`

const fetchRoutes = function* (action) {
const api = create({
baseURL: 'https://ckan.smartcolumbusos.com'
baseURL: 'https://data.smartcolumbusos.com/api/v1',
headers: { 'Accept': 'application/json' }
})

const { data } = yield call(
api.get,
'/api/action/datastore_search_sql',
{
sql: `select distinct "LINENAME", "LINENUM" from ${COTA_LINE_DATA_SET_ID} order by "LINENUM"`
}
'organization/central_ohio_transit_authority/dataset/2a329570_33d7_4cde_818d_6ef323e68875/query'
)

yield put(routeUpdate(data))
Expand Down
85 changes: 0 additions & 85 deletions src/sagas/route.test.js

This file was deleted.

0 comments on commit 8b8cad8

Please sign in to comment.