|
1 | 1 | // @flow |
2 | 2 |
|
| 3 | +import Icon from '@conveyal/woonerf/components/icon' |
3 | 4 | import React, {Component} from 'react' |
4 | 5 | import {Checkbox} from 'react-bootstrap' |
5 | 6 |
|
6 | 7 | import * as shapesActions from '../actions/shapes' |
| 8 | +import {getComponentMessages} from '../../common/util/config' |
7 | 9 |
|
| 10 | +import type {FetchStatus} from '../../types' |
8 | 11 | import type {Props as ContainerProps} from '../containers/ShowAllRoutesOnMapFilter' |
9 | 12 |
|
10 | 13 | type Props = ContainerProps & { |
| 14 | + fetchStatus: FetchStatus, |
11 | 15 | showAllRoutesOnMap: boolean, |
12 | 16 | toggleShowAllRoutesOnMap: typeof shapesActions.toggleShowAllRoutesOnMap |
13 | 17 | } |
14 | 18 |
|
15 | 19 | 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 | + |
16 | 27 | render () { |
17 | 28 | const { |
| 29 | + fetchStatus, |
18 | 30 | showAllRoutesOnMap, |
19 | | - toggleShowAllRoutesOnMap |
| 31 | + version |
20 | 32 | } = 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 |
22 | 37 | return ( |
23 | 38 | <Checkbox |
24 | 39 | checked={showAllRoutesOnMap} |
25 | | - onChange={toggleShowAllRoutesOnMap} |
| 40 | + disabled={tooManyShapeRecords || fetchStatus.fetching} |
| 41 | + onChange={this.onChange} |
26 | 42 | > |
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')} |
28 | 50 | </Checkbox> |
29 | 51 | ) |
30 | 52 | } |
|
0 commit comments