Skip to content

Commit 548508d

Browse files
committed
feat(feed-fetch): add feed fetch frequency form elements
re ibi-group/datatools-server#346
1 parent 44fc795 commit 548508d

File tree

5 files changed

+143
-10
lines changed

5 files changed

+143
-10
lines changed

lib/common/constants/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ export const DEFAULT_LOGO = 'https://d2tyb7byn1fef9.cloudfront.net/ibi_group_bla
1111
export const DEFAULT_LOGO_SMALL = 'https://d2tyb7byn1fef9.cloudfront.net/ibi_group-128x128.png'
1212
export const DEFAULT_TITLE = 'Data Tools'
1313

14+
export const FETCH_FREQUENCIES = Object.freeze({
15+
MINUTES: 'MINUTES',
16+
HOURS: 'HOURS',
17+
DAYS: 'DAYS'
18+
})
19+
20+
export const FREQUENCY_INTERVALS = Object.freeze({
21+
[FETCH_FREQUENCIES.MINUTES]: [5, 10, 15, 30],
22+
[FETCH_FREQUENCIES.HOURS]: [1, 6, 12],
23+
[FETCH_FREQUENCIES.DAYS]: [1, 2, 7, 14]
24+
})
25+
1426
export const RETRIEVAL_METHODS = Object.freeze({
1527
MANUALLY_UPLOADED: 'MANUALLY_UPLOADED',
1628
FETCHED_AUTOMATICALLY: 'FETCHED_AUTOMATICALLY',

lib/common/containers/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import ActiveProjectViewer from '../../manager/containers/ActiveProjectViewer'
2323
import ActivePublicLandingPage from '../../public/containers/ActivePublicLandingPage'
2424
import ActiveUserAccount from '../../public/containers/ActiveUserAccount'
2525
import ActiveUserHomePage from '../../manager/containers/ActiveUserHomePage'
26+
// import CreateFeedSource from '../../manager/containers/CreateFeedSource'
2627
import CreateProject from '../../manager/containers/CreateProject'
2728
import ActiveGtfsPlusEditor from '../../gtfsplus/containers/ActiveGtfsPlusEditor'
2829
import {logPageView} from '../util/analytics'

lib/manager/components/CreateFeedSource.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
22

3+
import Icon from '@conveyal/woonerf/components/icon'
34
import memoize from 'lodash.memoize'
45
import React, {Component} from 'react'
56
import update from 'react-addons-update'
@@ -8,21 +9,24 @@ import {
89
Checkbox,
910
Col,
1011
ControlLabel,
12+
DropdownButton,
1113
FormControl,
1214
FormGroup,
1315
HelpBlock,
1416
ListGroup,
1517
ListGroupItem,
18+
MenuItem,
1619
Panel,
1720
Row
1821
} from 'react-bootstrap'
1922
import validator from 'validator'
2023

2124
import {createFeedSource} from '../actions/feeds'
2225
import Loading from '../../common/components/Loading'
26+
import {FREQUENCY_INTERVALS} from '../../common/constants'
2327
import {validationState} from '../util'
2428

25-
import type {NewFeed} from '../../types'
29+
import type {FetchFrequency, NewFeed} from '../../types'
2630

2731
type Props = {
2832
createFeedSource: typeof createFeedSource,
@@ -71,6 +75,8 @@ export default class CreateFeedSource extends Component<Props, State> {
7175
model: {
7276
autoFetchFeed: false,
7377
deployable: false,
78+
fetchFrequency: 'DAYS',
79+
fetchInterval: 1,
7480
name: '',
7581
projectId: props.projectId,
7682
url: ''
@@ -93,6 +99,32 @@ export default class CreateFeedSource extends Component<Props, State> {
9399
}
94100
)
95101

102+
_intervalsForFreq = (fetchFrequency: FetchFrequency) => {
103+
return FREQUENCY_INTERVALS[fetchFrequency] || FREQUENCY_INTERVALS['DAYS']
104+
}
105+
106+
_onSelectFetchInterval = (fetchInterval: number) => {
107+
const updatedState: State = update(this.state, {
108+
model: {fetchInterval: {$set: fetchInterval}}
109+
})
110+
this.setState(updatedState)
111+
}
112+
113+
_onSelectFetchFrequency = (fetchFrequency: FetchFrequency) => {
114+
let {fetchInterval} = this.state.model
115+
const intervals = this._intervalsForFreq(fetchFrequency)
116+
if (intervals.indexOf(fetchInterval) === -1) {
117+
fetchInterval = intervals[0]
118+
}
119+
const updatedState: State = update(this.state, {
120+
model: {
121+
fetchFrequency: {$set: fetchFrequency},
122+
fetchInterval: {$set: fetchInterval}
123+
}
124+
})
125+
this.setState(updatedState)
126+
}
127+
96128
_onSave = () => {
97129
const {model, validation} = this.state
98130
// Prevent a save if the form has validation issues
@@ -127,6 +159,7 @@ export default class CreateFeedSource extends Component<Props, State> {
127159
render () {
128160
const {loading, model, validation} = this.state
129161
if (loading) return <Loading style={{marginTop: '30px'}} />
162+
const intervals = this._intervalsForFreq(model.fetchFrequency)
130163
return (
131164
<Row>
132165
<Col xs={12}>
@@ -196,6 +229,34 @@ export default class CreateFeedSource extends Component<Props, State> {
196229
source URL must be specified and project auto fetch must
197230
be enabled.)
198231
</small>
232+
{model.autoFetchFeed
233+
? <div>
234+
<span>Fetch feed every</span>
235+
{' '}
236+
<DropdownButton
237+
title={model.fetchInterval}
238+
id='add-transformation-dropdown'
239+
onSelect={this._onSelectFetchInterval}>
240+
{intervals.map(value =>
241+
<MenuItem key={value} eventKey={value}>
242+
{value} {model.fetchInterval === value && <Icon type='check' />}
243+
</MenuItem>)
244+
}
245+
</DropdownButton>
246+
{' '}
247+
<DropdownButton
248+
title={model.fetchFrequency}
249+
id='add-transformation-dropdown'
250+
onSelect={this._onSelectFetchFrequency}>
251+
{Object.keys(FREQUENCY_INTERVALS).map((value) =>
252+
<MenuItem key={value} eventKey={value}>
253+
{value} {model.fetchFrequency === value && <Icon type='check' />}
254+
</MenuItem>)
255+
}
256+
</DropdownButton>
257+
</div>
258+
: null
259+
}
199260
</FormGroup>
200261
</ListGroupItem>
201262
</ListGroup>

lib/manager/components/GeneralSettings.js

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33
import Icon from '@conveyal/woonerf/components/icon'
44
import React, {Component} from 'react'
55
import {
6-
Col,
7-
ListGroup,
8-
ListGroupItem,
96
Button,
10-
Panel,
11-
FormControl,
12-
InputGroup,
7+
Checkbox,
8+
Col,
139
ControlLabel,
10+
DropdownButton,
11+
FormControl,
1412
FormGroup,
15-
Checkbox
13+
InputGroup,
14+
ListGroup,
15+
ListGroupItem,
16+
MenuItem,
17+
Panel
1618
} from 'react-bootstrap'
1719

1820
import * as feedsActions from '../actions/feeds'
21+
import {FREQUENCY_INTERVALS} from '../../common/constants'
1922

20-
import type {Feed, Project} from '../../types'
23+
import type {Feed, FetchFrequency, Project} from '../../types'
2124
import type {ManagerUserState} from '../../types/reducers'
2225

2326
type Props = {
@@ -66,6 +69,25 @@ export default class GeneralSettings extends Component<Props, State> {
6669
updateFeedSource(feedSource, {retrievalMethod: value})
6770
}
6871

72+
_intervalsForFreq = (fetchFrequency: FetchFrequency) => {
73+
return FREQUENCY_INTERVALS[fetchFrequency] || FREQUENCY_INTERVALS['DAYS']
74+
}
75+
76+
_onSelectFetchInterval = (fetchInterval: number) => {
77+
const {feedSource, updateFeedSource} = this.props
78+
updateFeedSource(feedSource, {fetchInterval})
79+
}
80+
81+
_onSelectFetchFrequency = (fetchFrequency: FetchFrequency) => {
82+
const {feedSource, updateFeedSource} = this.props
83+
let {fetchInterval} = feedSource
84+
const intervals = this._intervalsForFreq(fetchFrequency)
85+
if (intervals.indexOf(fetchInterval) === -1) {
86+
fetchInterval = intervals[0]
87+
}
88+
updateFeedSource(feedSource, {fetchFrequency, fetchInterval})
89+
}
90+
6991
_onTogglePublic = () => {
7092
const {feedSource, updateFeedSource} = this.props
7193
updateFeedSource(feedSource, {isPublic: !feedSource.isPublic})
@@ -96,6 +118,9 @@ export default class GeneralSettings extends Component<Props, State> {
96118
url
97119
} = this.state
98120
const autoFetchFeed = feedSource.retrievalMethod === 'FETCHED_AUTOMATICALLY'
121+
const fetchFrequency = feedSource.fetchFrequency || 'DAYS'
122+
const intervals = this._intervalsForFreq(fetchFrequency)
123+
const fetchInterval = feedSource.fetchInterval || intervals[0]
99124
return (
100125
<Col xs={7}>
101126
{/* Settings */}
@@ -168,6 +193,34 @@ export default class GeneralSettings extends Component<Props, State> {
168193
</Checkbox>
169194
<small>Set this feed source to fetch automatically. (Feed source URL must be specified and project auto fetch must be enabled.)</small>
170195
</FormGroup>
196+
{autoFetchFeed
197+
? <div>
198+
<span>Fetch feed every</span>
199+
{' '}
200+
<DropdownButton
201+
title={fetchInterval}
202+
id='add-transformation-dropdown'
203+
onSelect={this._onSelectFetchInterval}>
204+
{intervals.map(value =>
205+
<MenuItem key={value} eventKey={value}>
206+
{value} {fetchInterval === value && <Icon type='check' />}
207+
</MenuItem>)
208+
}
209+
</DropdownButton>
210+
{' '}
211+
<DropdownButton
212+
title={fetchFrequency}
213+
id='add-transformation-dropdown'
214+
onSelect={this._onSelectFetchFrequency}>
215+
{Object.keys(FREQUENCY_INTERVALS).map((value) =>
216+
<MenuItem key={value} eventKey={value}>
217+
{value} {fetchFrequency === value && <Icon type='check' />}
218+
</MenuItem>)
219+
}
220+
</DropdownButton>
221+
</div>
222+
: null
223+
}
171224
</ListGroupItem>
172225
</ListGroup>
173226
</Panel>

lib/types/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

33
import {POINT_TYPE} from '../editor/constants'
4-
import {FEED_TRANSFORMATION_TYPES, RETRIEVAL_METHODS} from '../common/constants'
4+
import {FEED_TRANSFORMATION_TYPES, FETCH_FREQUENCIES, RETRIEVAL_METHODS} from '../common/constants'
55

66
import type UserPermissions from '../common/user/UserPermissions'
77

@@ -289,6 +289,8 @@ export type Snapshot = {
289289

290290
export type RetrievalMethod = $Values<typeof RETRIEVAL_METHODS>
291291

292+
export type FetchFrequency = $Values<typeof FETCH_FREQUENCIES>
293+
292294
export type FeedTransformation = {
293295
'@type': $Values<typeof FEED_TRANSFORMATION_TYPES>,
294296
active: boolean,
@@ -314,6 +316,8 @@ export type Feed = {
314316
editorSnapshots?: Array<Snapshot>,
315317
externalProperties?: any, // TODO: add more exact type
316318
feedVersions?: Array<FeedVersion>,
319+
fetchFrequency?: FetchFrequency,
320+
fetchInterval?: number,
317321
id: string,
318322
isCreating?: boolean,
319323
isPublic: boolean,
@@ -339,6 +343,8 @@ export type Feed = {
339343
export type NewFeed = {
340344
autoFetchFeed?: boolean,
341345
deployable?: boolean,
346+
fetchFrequency: FetchFrequency,
347+
fetchInterval: number,
342348
name?: string,
343349
projectId: string,
344350
retrievalMethod?: string,

0 commit comments

Comments
 (0)