Skip to content

Commit

Permalink
Merge branch 'dev' into version-display
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Sep 17, 2018
2 parents 0c2c463 + d9fb7d1 commit e60a53d
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 71 deletions.
4 changes: 2 additions & 2 deletions lib/admin/actions/admin.js
Expand Up @@ -22,11 +22,11 @@ export const receiveUsers = createAction(
export const requestingUsers = createVoidPayloadAction('REQUESTING_USERS')
export const setUserPage = createAction(
'SET_USER_PAGE',
(payload: number /* page */) => payload
(payload: number) => payload
)
export const setUserQueryString = createAction(
'SET_USER_QUERY_STRING',
(payload: string /* queryString */) => payload
(payload: string) => payload
)

export type AdminActions = ActionType<typeof createdUser> |
Expand Down
2 changes: 2 additions & 0 deletions lib/alerts/actions/alerts.js
Expand Up @@ -79,6 +79,8 @@ export function setActiveAlert (alertId: number) {
const alert = getState().alerts.all.find(a => a.id === alertId)
if (alert) {
dispatch(updateActiveAlert(alert))
} else {
console.warn(`Could not find alert with id: ${alertId}`)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/editor/actions/editor.js
Expand Up @@ -51,7 +51,10 @@ function getCloneProps (entityId: string, component: string, state: AppState) {
const activeTable = getTableById(tables, component)
switch (component) {
case 'trippattern':
if (!active.entity) return
if (!active.entity) {
console.warn('no entity is active, unable to get clone props')
return
}
const pattern = active.entity.tripPatterns.find(tp => tp.id === entityId)
const newPatternId = generateUID()
const newShapeId = generateUID()
Expand Down
2 changes: 1 addition & 1 deletion lib/gtfs/components/GtfsMap.js
Expand Up @@ -199,7 +199,7 @@ export default class GtfsMap extends Component<Props, State> {
const zoomLevel: number = this.refs.map.leafletElement.getZoom()
const feedsToSearch = feeds || this.props.feeds || []
const ents = entities || this.props.entities
if ((feedsToSearch && feedsToSearch.length === 0) || zoomLevel > 13) {
if (feedsToSearch.length === 0 || zoomLevel > 13) {
refreshGtfsElements(feedsToSearch, ents)
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/gtfs/components/PatternGeoJson.js
Expand Up @@ -26,9 +26,7 @@ export default class PatternGeoJson extends Component<Props> {
_onClickAction = () => {
const {onRouteClick, newEntityId, pattern} = this.props
const {feed, route} = pattern
if (onRouteClick) {
onRouteClick(route, feed, newEntityId)
}
onRouteClick && onRouteClick(route, feed, newEntityId)
}

render () {
Expand Down
4 changes: 1 addition & 3 deletions lib/gtfs/components/StopMarker.js
Expand Up @@ -23,9 +23,7 @@ export default class StopMarker extends Component<Props> {
_onClick = () => {
const {newEntityId, onStopClick, stop} = this.props
const {feed} = stop
if (onStopClick) {
onStopClick(stop, feed, newEntityId)
}
onStopClick && onStopClick(stop, feed, newEntityId)
}

render () {
Expand Down
2 changes: 1 addition & 1 deletion lib/index.css
@@ -1,6 +1,6 @@

@import url(node_modules/font-awesome/css/font-awesome.css);
@import url(https://unpkg.com/leaflet@1.0.3/dist/leaflet.css);
@import url(node_modules/leaflet/dist/leaflet.css);

@import url(node_modules/bootstrap/dist/css/bootstrap.min.css);
@import url(node_modules/react-bootstrap-table/dist/react-bootstrap-table.min.css);
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/actions/deployments.js
Expand Up @@ -16,7 +16,7 @@ const DEPLOYMENT_URL = `/api/manager/secure/deployments`
// Deployment Actions
export const createDeployment = createAction(
'CREATE_DEPLOYMENT',
(payload: string /* project id */) => payload
(payload: string) => payload
)
const receiveDeployment = createAction(
'RECEIVE_DEPLOYMENT',
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/actions/feeds.js
Expand Up @@ -35,7 +35,7 @@ export const receiveFeedSource = createAction(
)
export const createFeedSource = createAction(
'CREATE_FEEDSOURCE',
(payload: string /* project id */) => payload
(payload: string) => payload
)

export type FeedActions = ActionType<typeof requestingFeedSource> |
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/actions/languages.js
Expand Up @@ -4,7 +4,7 @@ import {createAction, type ActionType} from 'redux-actions'

export const setActiveLanguage = createAction(
'SET_ACTIVE_LANGUAGE',
(payload: string /* languageId */) => payload
(payload: string) => payload
)

export type LanguageActions = ActionType<typeof setActiveLanguage>
11 changes: 10 additions & 1 deletion lib/manager/components/validation/ServicePerModeChart.js
Expand Up @@ -14,6 +14,8 @@ type Props = {
validationResult: ValidationResult
}

const maxDaysToShow = 500

export default class ServicePerModeChart extends Component<Props> {
_getData = (validationResult: ValidationResult) => {
const {dailyBusSeconds, dailyTramSeconds, dailyMetroSeconds, dailyRailSeconds, dailyTotalSeconds, firstCalendarDate} = validationResult
Expand All @@ -24,7 +26,8 @@ export default class ServicePerModeChart extends Component<Props> {
const hasRail = dailyRailSeconds.filter(s => s > 0).length > 0
let hasOther = false
const data = []
for (let i = 0; i < dailyTotalSeconds.length; i++) {
const limit = Math.min(dailyTotalSeconds.length, maxDaysToShow)
for (let i = 0; i < limit; i++) {
const column = {}
column.date = firstDate.clone().add(i, 'days')
let other = dailyTotalSeconds[i]
Expand Down Expand Up @@ -84,6 +87,7 @@ export default class ServicePerModeChart extends Component<Props> {
for (let i = yAxisPeriod; i <= yAxisMax; i += yAxisPeriod) {
yAxisLabels.push(i)
}
const curtailed = maxDaysToShow < validationResult.dailyTotalSeconds.length
return (
<div
className='text-center'
Expand Down Expand Up @@ -174,6 +178,11 @@ export default class ServicePerModeChart extends Component<Props> {
</text>
</g>
))}
{curtailed &&
<text x={100 * modes.length} y={graphHeight + 43}>
* only first 500 days of service shown
</text>
}
</svg>
</div>
)
Expand Down
12 changes: 10 additions & 2 deletions lib/manager/components/validation/TripsChart.js
Expand Up @@ -18,6 +18,7 @@ const COLORS = {
SATURDAY: '#66c2a5',
SUNDAY: '#fc8d62'
}
const maxDaysToShow = 500

export default class TripsChart extends Component<Props> {
render () {
Expand All @@ -27,8 +28,9 @@ export default class TripsChart extends Component<Props> {
}
const {dailyTripCounts, firstCalendarDate} = validationResult
const firstDate = moment(firstCalendarDate)
const data = dailyTripCounts.map((count, index) =>
[firstDate.clone().add(index, 'days'), count])
const data = dailyTripCounts
.slice(0, maxDaysToShow)
.map((count, index) => [firstDate.clone().add(index, 'days'), count])
const graphHeight = 300
const spacing = 8
const leftMargin = 50
Expand All @@ -43,6 +45,7 @@ export default class TripsChart extends Component<Props> {
for (var i = yAxisPeriod; i <= yAxisMax; i += yAxisPeriod) {
yAxisLabels.push(i)
}
const curtailed = maxDaysToShow < dailyTripCounts.length
return (
<div
className='text-center'
Expand Down Expand Up @@ -123,6 +126,11 @@ export default class TripsChart extends Component<Props> {
</text>
</g>
))}
{curtailed &&
<text x={100 * Object.keys(COLORS).length} y={graphHeight + 43}>
* only first 500 days of service shown
</text>
}
</svg>
</div>
)
Expand Down
48 changes: 1 addition & 47 deletions lib/manager/reducers/projects.js
Expand Up @@ -3,8 +3,8 @@
import update from 'react-addons-update'
import {getConfigProperty} from '../../common/util/config'
import {defaultSorter} from '../../common/util/util'
import {getIndexesFromFeed} from '../util'

import type {FeedVersion} from '../../types'
import type {Action} from '../../types/actions'
import type {ProjectsState} from '../../types/reducers'

Expand Down Expand Up @@ -458,50 +458,4 @@ const projects = (state: ProjectsState = defaultState, action: Action): Projects
}
}

// helper function to get indexes
function getIndexesFromFeed ({
errorType,
feedSourceId,
feedVersionId,
projectId,
state
}: {
errorType?: string,
feedSourceId?: string,
feedVersionId?: FeedVersion,
projectId: string,
state: ProjectsState
}): {
errorIndex: number,
projectIndex: number,
sourceIndex: number,
versionIndex: number
} {
const projectIndex = state.all.findIndex(p => p.id === projectId)
if (!feedSourceId || projectIndex < 0) {
return { projectIndex, sourceIndex: -2, versionIndex: -2, errorIndex: -2 }
}
const project = state.all[projectIndex]
if (!project.feedSources) {
return { projectIndex, sourceIndex: -2, versionIndex: -2, errorIndex: -2 }
}
const sourceIndex = project.feedSources.findIndex(s => s.id === feedSourceId)
if (!feedVersionId || sourceIndex < 0 || !project.feedSources) {
return { projectIndex, sourceIndex, versionIndex: -2, errorIndex: -2 }
}
const feedSource = project.feedSources[sourceIndex]
if (!feedSource.feedVersions) {
return { projectIndex, sourceIndex, versionIndex: -2, errorIndex: -2 }
}
const versionIndex = feedSource.feedVersions.findIndex(v => v.id === feedVersionId)
if (!errorType || !feedSource.feedVersions || versionIndex < 0) {
return { projectIndex, sourceIndex, versionIndex, errorIndex: -2 }
}
const feedVersion = feedSource.feedVersions[versionIndex]
const errorIndex = feedVersion.validationResult.error_counts.findIndex(
e => e.type === errorType
)
return { errorIndex, projectIndex, sourceIndex, versionIndex }
}

export default projects
53 changes: 50 additions & 3 deletions lib/manager/util/index.js
@@ -1,7 +1,6 @@
// @flow

import type {Feed, Project} from '../../types'
import type {ManagerUserState} from '../../types/reducers'
import type {Feed, FeedVersion, Project} from '../../types'
import type {ManagerUserState, ProjectsState} from '../../types/reducers'

export function findProjectByFeedSource (
allProjects: ?Array<Project>,
Expand Down Expand Up @@ -55,3 +54,51 @@ export function isEditingDisabled (
)
)
}

/**
* Helper function to get the index of various things from the project state.
*/
export function getIndexesFromFeed ({
errorType,
feedSourceId,
feedVersionId,
projectId,
state
}: {
errorType?: string,
feedSourceId?: string,
feedVersionId?: FeedVersion,
projectId: string,
state: ProjectsState
}): {
errorIndex: number,
projectIndex: number,
sourceIndex: number,
versionIndex: number
} {
const projectIndex = state.all.findIndex(p => p.id === projectId)
if (!feedSourceId || projectIndex < 0) {
return { projectIndex, sourceIndex: -2, versionIndex: -2, errorIndex: -2 }
}
const project = state.all[projectIndex]
if (!project.feedSources) {
return { projectIndex, sourceIndex: -2, versionIndex: -2, errorIndex: -2 }
}
const sourceIndex = project.feedSources.findIndex(s => s.id === feedSourceId)
if (!feedVersionId || sourceIndex < 0 || !project.feedSources) {
return { projectIndex, sourceIndex, versionIndex: -2, errorIndex: -2 }
}
const feedSource = project.feedSources[sourceIndex]
if (!feedSource.feedVersions) {
return { projectIndex, sourceIndex, versionIndex: -2, errorIndex: -2 }
}
const versionIndex = feedSource.feedVersions.findIndex(v => v.id === feedVersionId)
if (!errorType || !feedSource.feedVersions || versionIndex < 0) {
return { projectIndex, sourceIndex, versionIndex, errorIndex: -2 }
}
const feedVersion = feedSource.feedVersions[versionIndex]
const errorIndex = feedVersion.validationResult.error_counts.findIndex(
e => e.type === errorType
)
return { errorIndex, projectIndex, sourceIndex, versionIndex }
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -49,7 +49,7 @@
"isomorphic-fetch": "^2.2.1",
"jszip": "^3.0.0",
"jwt-decode": "^2.1.0",
"leaflet": "1.0.3",
"leaflet": "^1.3.4",
"lodash": "^4.17.10",
"moment": "^2.11.2",
"numeral": "2.0.4",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -5400,9 +5400,9 @@ lcid@^1.0.0:
dependencies:
invert-kv "^1.0.0"

leaflet@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.0.3.tgz#1f401b98b45c8192134c6c8d69686253805007c8"
leaflet@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.3.4.tgz#7f006ea5832603b53d7269ef5c595fd773060a40"

left-pad@^1.2.0:
version "1.3.0"
Expand Down

0 comments on commit e60a53d

Please sign in to comment.