Skip to content

Commit 017a634

Browse files
authored
Merge pull request #543 from ibi-group/fix-show-all-routes
Fix show all routes; add limit for perf
2 parents f8e921d + e386b9c commit 017a634

File tree

6 files changed

+40
-28
lines changed

6 files changed

+40
-28
lines changed

i18n/english.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,10 @@ components:
651651
title: Deployment Server Management
652652
save: Save
653653
title: Settings
654+
ShowAllRoutesOnMapFilter:
655+
fetching: Fetching
656+
showAllRoutesOnMap: Show all routes
657+
tooManyShapeRecords: Too many shapes to display
654658
Sidebar:
655659
unknown: Unknown
656660
SnapshotItem:

lib/gtfs/actions/shapes.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import {createAction, type ActionType} from 'redux-actions'
44

5-
import {createVoidPayloadAction, secureFetch} from '../../common/actions'
6-
import {compose, shapes} from '../../gtfs/util/graphql'
5+
import {createVoidPayloadAction, fetchGraphQL} from '../../common/actions'
6+
import {shapes} from '../../gtfs/util/graphql'
77
import {updateRoutesOnMapDisplay} from './filter'
88

99
import type {dispatchFn, getStateFn} from '../../types/reducers'
@@ -32,10 +32,9 @@ export function toggleShowAllRoutesOnMap (namespace: string) {
3232
!state.gtfs.shapes.fetchStatus.fetching
3333
) {
3434
dispatch(fetchingShapes())
35-
return dispatch(secureFetch(compose(shapes, {namespace})))
36-
.then(response => response.json())
37-
.then(json => {
38-
const {patterns} = json.data.feed
35+
return dispatch(fetchGraphQL({query: shapes, variables: {namespace}}))
36+
.then(data => {
37+
const {patterns} = data.feed
3938
const shapes = patterns.map(pattern => {
4039
return pattern.shape.map(point => [
4140
point.shape_pt_lat,

lib/gtfs/components/ShowAllRoutesOnMapFilter.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
11
// @flow
22

3+
import Icon from '@conveyal/woonerf/components/icon'
34
import React, {Component} from 'react'
45
import {Checkbox} from 'react-bootstrap'
56

67
import * as shapesActions from '../actions/shapes'
8+
import {getComponentMessages} from '../../common/util/config'
79

10+
import type {FetchStatus} from '../../types'
811
import type {Props as ContainerProps} from '../containers/ShowAllRoutesOnMapFilter'
912

1013
type Props = ContainerProps & {
14+
fetchStatus: FetchStatus,
1115
showAllRoutesOnMap: boolean,
1216
toggleShowAllRoutesOnMap: typeof shapesActions.toggleShowAllRoutesOnMap
1317
}
1418

1519
export default class ShowAllRoutesOnMapFilter extends Component<Props> {
20+
messages = getComponentMessages('ShowAllRoutesOnMapFilter')
21+
22+
onChange = () => {
23+
const {toggleShowAllRoutesOnMap, version} = this.props
24+
toggleShowAllRoutesOnMap(version.namespace)
25+
}
26+
1627
render () {
1728
const {
29+
fetchStatus,
1830
showAllRoutesOnMap,
19-
toggleShowAllRoutesOnMap
31+
version
2032
} = this.props
21-
33+
// Disable if greater than one million records. We don't want to break
34+
// Data Tools because of this shapes GraphQL fetch. This is a somewhat
35+
// arbitrary limit. It may need to be adjusted...
36+
const tooManyShapeRecords = version.feedLoadResult.shapes.rowCount > 1000000
2237
return (
2338
<Checkbox
2439
checked={showAllRoutesOnMap}
25-
onChange={toggleShowAllRoutesOnMap}
40+
disabled={tooManyShapeRecords || fetchStatus.fetching}
41+
onChange={this.onChange}
2642
>
27-
Show all routes
43+
{fetchStatus.fetching
44+
? <span className='text-muted'>
45+
{this.messages('fetching')} <Icon className='fa-spin' type='refresh' />
46+
</span>
47+
: tooManyShapeRecords
48+
? this.messages('tooManyShapeRecords')
49+
: this.messages('showAllRoutesOnMap')}
2850
</Checkbox>
2951
)
3052
}

lib/gtfs/containers/ShowAllRoutesOnMapFilter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import {connect} from 'react-redux'
55
import {toggleShowAllRoutesOnMap} from '../actions/shapes'
66
import ShowAllRoutesOnMapFilter from '../components/ShowAllRoutesOnMapFilter'
77

8+
import type {FeedVersion} from '../../types'
89
import type {AppState} from '../../types/reducers'
910

10-
export type Props = {}
11+
export type Props = {version: FeedVersion}
1112

1213
const mapStateToProps = (state: AppState, ownProps: Props) => {
1314
return {
15+
fetchStatus: state.gtfs.shapes.fetchStatus,
1416
showAllRoutesOnMap: state.gtfs.filter.showAllRoutesOnMap
1517
}
1618
}

lib/gtfs/util/graphql.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
// @flow
22

3-
import {GTFS_GRAPHQL_PREFIX} from '../../common/constants'
4-
5-
/**
6-
* Construct GET GraphQL request URL. NOTE: variable names/keys must match those
7-
* specified in GraphQL schema.
8-
*
9-
* @deprecated Request can become too large and generate a 413 'request entity
10-
* too large' server error. Use lib/common/actions#fetchGraphQL instead.
11-
*/
12-
export function compose (query: string, variables: Object) {
13-
return `${GTFS_GRAPHQL_PREFIX}?query=${encodeURIComponent(query)}&variables=${encodeURIComponent(JSON.stringify(variables))}`
14-
}
15-
163
export const feed = `
174
query feedQuery($namespace: String) {
185
feeds (namespace: $namespace) {
@@ -207,9 +194,7 @@ query timetablesQuery(
207194
}`
208195

209196
export const shapes = `
210-
query shapesQuery(
211-
$namespace: String
212-
) {
197+
query shapesQuery($namespace: String) {
213198
feed (namespace: $namespace) {
214199
patterns(limit: -1) {
215200
shape(limit: -1) {

lib/manager/components/version/FeedVersionMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class FeedVersionMap extends Component<Props, State> {
6767
position: 'absolute',
6868
zIndex: 20000
6969
}}>
70-
<ShowAllRoutesOnMapFilter />
70+
<ShowAllRoutesOnMapFilter version={version} />
7171
</div>
7272
{/* Primary map component */}
7373
<ActiveGtfsMap

0 commit comments

Comments
 (0)