Skip to content

Commit d188125

Browse files
feat(auto-publish): Add auto-publish support (MTC ext. req'd)
1 parent a65c863 commit d188125

File tree

5 files changed

+96
-22
lines changed

5 files changed

+96
-22
lines changed

lib/manager/actions/versions.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import {ENTITY} from '../../editor/constants'
1212
import {getKeyForId} from '../../editor/util/gtfs'
1313
import {getEntityGraphQLRoot, getEntityIdField, getGraphQLFieldsForEntity} from '../../gtfs/util'
1414
import {validateGtfsPlusFeed} from '../../gtfsplus/actions/gtfsplus'
15-
import {handleJobResponse, setErrorMessage, startJobMonitor} from './status'
16-
import {fetchFeedSource} from './feeds'
17-
1815
import type {Feed, FeedVersion, ShapefileExportType} from '../../types'
1916
import type {dispatchFn, getStateFn, ValidationIssueCount} from '../../types/reducers'
2017

18+
import {handleJobResponse, setErrorMessage, startJobMonitor} from './status'
19+
import {fetchFeedSource} from './feeds'
20+
2121
const deletingFeedVersion = createVoidPayloadAction('DELETING_FEEDVERSION')
2222
const publishedFeedVersion = createAction(
2323
'PUBLISHED_FEEDVERSION',
@@ -160,6 +160,13 @@ export function fetchFeedVersion (feedVersionId: string) {
160160
*/
161161
export function publishFeedVersion (feedVersion: FeedVersion) {
162162
return function (dispatch: dispatchFn, getState: getStateFn) {
163+
if (
164+
feedVersion.feedSource.autoPublish &&
165+
!window.confirm('Are you sure you want publish this feed version again?')
166+
) {
167+
// For feed set to auto-publish, if the user does not confirm, do nothing.
168+
return
169+
}
163170
const url = `${SECURE_API_PREFIX}feedversion/${feedVersion.id}/publish`
164171
return dispatch(secureFetch(url, 'post'))
165172
.then(response => response.json())

lib/manager/components/CreateFeedSource.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import validator from 'validator'
2121
import {createFeedSource} from '../actions/feeds'
2222
import Loading from '../../common/components/Loading'
2323
import {FREQUENCY_INTERVALS} from '../../common/constants'
24-
import FeedFetchFrequency from './FeedFetchFrequency'
24+
import {isExtensionEnabled} from '../../common/util/config'
2525
import {validationState} from '../util'
26-
2726
import type {FetchFrequency, NewFeed} from '../../types'
2827

28+
import FeedFetchFrequency from './FeedFetchFrequency'
29+
2930
type Props = {
3031
createFeedSource: typeof createFeedSource,
3132
onCancel: () => void,
@@ -235,6 +236,26 @@ export default class CreateFeedSource extends Component<Props, State> {
235236
</ListGroupItem>
236237
</ListGroup>
237238
</Panel>
239+
{isExtensionEnabled('mtc') && (
240+
<Panel header={<h3>Automatic publishing</h3>}>
241+
<ListGroup fill>
242+
<ListGroupItem>
243+
<FormGroup>
244+
<Checkbox
245+
checked={model.autoPublish}
246+
onChange={this._toggleCheckBox('autoPublish')}
247+
>
248+
<strong>Auto-publish this feed</strong>
249+
</Checkbox>
250+
<small>
251+
Set this feed source to be automatically published
252+
when a new version is created.
253+
</small>
254+
</FormGroup>
255+
</ListGroupItem>
256+
</ListGroup>
257+
</Panel>
258+
)}
238259
</Col>
239260
<Col xs={12}>
240261
<Button

lib/manager/components/GeneralSettings.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import {
1717

1818
import * as feedsActions from '../actions/feeds'
1919
import { FREQUENCY_INTERVALS } from '../../common/constants'
20+
import { isExtensionEnabled } from '../../common/util/config'
21+
import LabelAssigner from '../components/LabelAssigner'
2022
import type { Feed, FetchFrequency, Project } from '../../types'
2123
import type { ManagerUserState } from '../../types/reducers'
22-
import LabelAssigner from '../components/LabelAssigner'
2324

2425
import FeedFetchFrequency from './FeedFetchFrequency'
2526

@@ -69,6 +70,12 @@ export default class GeneralSettings extends Component<Props, State> {
6970
updateFeedSource(feedSource, {retrievalMethod: value})
7071
}
7172

73+
// FIXME_QBD: refactor similar code (See CreateFeedSource).
74+
_onToggleAutoPublish = () => {
75+
const {feedSource, updateFeedSource} = this.props
76+
updateFeedSource(feedSource, {autoPublish: !feedSource.autoPublish})
77+
}
78+
7279
_onSelectFetchInterval = (fetchInterval: number) => {
7380
const {feedSource, updateFeedSource} = this.props
7481
updateFeedSource(feedSource, {fetchInterval})
@@ -201,6 +208,28 @@ export default class GeneralSettings extends Component<Props, State> {
201208
</ListGroupItem>
202209
</ListGroup>
203210
</Panel>
211+
{isExtensionEnabled('mtc') && (
212+
<Panel header={<h3>Automatic publishing</h3>}>
213+
<ListGroup fill>
214+
<ListGroupItem>
215+
<FormGroup>
216+
<Checkbox
217+
checked={feedSource.autoPublish}
218+
disabled={disabled}
219+
onChange={this._onToggleAutoPublish}
220+
bsStyle='danger'
221+
>
222+
<strong>Auto-publish this feed</strong>
223+
</Checkbox>
224+
<small>
225+
Set this feed source to be automatically published
226+
when a new version is created.
227+
</small>
228+
</FormGroup>
229+
</ListGroupItem>
230+
</ListGroup>
231+
</Panel>
232+
)}
204233
<Panel header={<h3>Labels</h3>}>
205234
<LabelAssigner feedSource={feedSource} project={project} />
206235
</Panel>

lib/manager/components/version/FeedVersionDetails.js

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import bboxPoly from 'turf-bbox-polygon'
1515
import * as versionsActions from '../../actions/versions'
1616
import {getConfigProperty, isExtensionEnabled} from '../../../common/util/config'
1717
import {BLOCKING_ERROR_TYPES} from '../../util/version'
18+
import type {FeedVersion, GtfsPlusValidation, Bounds, Feed} from '../../../types'
19+
import type {ManagerUserState} from '../../../types/reducers'
20+
1821
import FeedVersionSpanChart from './FeedVersionSpanChart'
1922
import VersionRetrievalBadge from './VersionRetrievalBadge'
2023
import VersionSelectorDropdown from './VersionSelectorDropdown'
2124

22-
import type {FeedVersion, GtfsPlusValidation, Bounds, Feed} from '../../../types'
23-
import type {ManagerUserState} from '../../../types/reducers'
24-
2525
type Props = {
2626
comparedVersion: ?FeedVersion,
2727
feedSource: Feed,
@@ -111,6 +111,28 @@ export default class FeedVersionDetails extends Component<Props> {
111111
const mergeButtonLabel = isMergedServicePeriods
112112
? 'Cannot re-merge feed'
113113
: 'Merge with version'
114+
115+
const hasMtcExtension = isExtensionEnabled('mtc')
116+
let publishWarningMessage
117+
if (hasMtcExtension) {
118+
if (hasBlockingIssue || hasGtfsPlusBlockingIssue) {
119+
publishWarningMessage = (
120+
<span>
121+
Cannot publish version because it has a{' '}
122+
{hasGtfsPlusBlockingIssue ? 'GTFS+ ' : ''}
123+
blocking issue.
124+
(See{' '}
125+
<Link
126+
to={`/feed/${feedSource.id}/version/${version.version}/${hasGtfsPlusBlockingIssue ? 'gtfsplus' : 'issues'}`}>
127+
{hasGtfsPlusBlockingIssue ? 'GTFS+' : 'validation'} issues
128+
</Link>.)
129+
</span>
130+
)
131+
} else if (feedSource.autoPublish) {
132+
publishWarningMessage = 'Reminder: this feed is already set to be auto-published!'
133+
}
134+
}
135+
114136
return (
115137
<ListGroupItem>
116138
<h4 className='pull-left' style={{ marginBottom: '2px' }}>
@@ -119,7 +141,7 @@ export default class FeedVersionDetails extends Component<Props> {
119141
Feed validity dates
120142
</span>
121143
</h4>
122-
{isExtensionEnabled('mtc') &&
144+
{hasMtcExtension &&
123145
<ButtonToolbar className='pull-right' style={{ marginTop: '2px' }}>
124146
<VersionSelectorDropdown
125147
dropdownProps={{
@@ -155,8 +177,7 @@ export default class FeedVersionDetails extends Component<Props> {
155177
</Button>
156178
</ButtonToolbar>
157179
}
158-
{(hasBlockingIssue || hasGtfsPlusBlockingIssue) &&
159-
isExtensionEnabled('mtc') &&
180+
{hasMtcExtension && (
160181
<div
161182
className='pull-right text-danger'
162183
style={{
@@ -165,17 +186,11 @@ export default class FeedVersionDetails extends Component<Props> {
165186
marginLeft: '5px',
166187
textAlign: 'right',
167188
width: '180px'
168-
}}>
169-
Cannot publish version because it has a{' '}
170-
{hasGtfsPlusBlockingIssue ? 'GTFS+ ' : ''}
171-
blocking issue.
172-
(See{' '}
173-
<Link
174-
to={`/feed/${feedSource.id}/version/${version.version}/${hasGtfsPlusBlockingIssue ? 'gtfsplus' : 'issues'}`}>
175-
{hasGtfsPlusBlockingIssue ? 'GTFS+' : 'validation'} issues
176-
</Link>.)
189+
}}
190+
>
191+
{publishWarningMessage}
177192
</div>
178-
}
193+
)}
179194

180195
<FeedVersionSpanChart
181196
activeVersion={version}

lib/types/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ export type FeedTransformRules = {
378378
}
379379

380380
export type Feed = {
381+
autoPublish?: boolean,
381382
dateCreated: number,
382383
deployable: boolean,
383384
deployments?: Array<Deployment>,
@@ -413,6 +414,7 @@ export type Feed = {
413414

414415
export type NewFeed = {
415416
autoFetchFeed?: boolean,
417+
autoPublish?: boolean,
416418
deployable?: boolean,
417419
fetchFrequency: FetchFrequency,
418420
fetchInterval: number,

0 commit comments

Comments
 (0)