Skip to content

Commit

Permalink
feat(auto-publish): Add auto-publish support (MTC ext. req'd)
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Nov 30, 2021
1 parent a65c863 commit d188125
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 22 deletions.
13 changes: 10 additions & 3 deletions lib/manager/actions/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {ENTITY} from '../../editor/constants'
import {getKeyForId} from '../../editor/util/gtfs'
import {getEntityGraphQLRoot, getEntityIdField, getGraphQLFieldsForEntity} from '../../gtfs/util'
import {validateGtfsPlusFeed} from '../../gtfsplus/actions/gtfsplus'
import {handleJobResponse, setErrorMessage, startJobMonitor} from './status'
import {fetchFeedSource} from './feeds'

import type {Feed, FeedVersion, ShapefileExportType} from '../../types'
import type {dispatchFn, getStateFn, ValidationIssueCount} from '../../types/reducers'

import {handleJobResponse, setErrorMessage, startJobMonitor} from './status'
import {fetchFeedSource} from './feeds'

const deletingFeedVersion = createVoidPayloadAction('DELETING_FEEDVERSION')
const publishedFeedVersion = createAction(
'PUBLISHED_FEEDVERSION',
Expand Down Expand Up @@ -160,6 +160,13 @@ export function fetchFeedVersion (feedVersionId: string) {
*/
export function publishFeedVersion (feedVersion: FeedVersion) {
return function (dispatch: dispatchFn, getState: getStateFn) {
if (
feedVersion.feedSource.autoPublish &&
!window.confirm('Are you sure you want publish this feed version again?')
) {
// For feed set to auto-publish, if the user does not confirm, do nothing.
return
}
const url = `${SECURE_API_PREFIX}feedversion/${feedVersion.id}/publish`
return dispatch(secureFetch(url, 'post'))
.then(response => response.json())
Expand Down
25 changes: 23 additions & 2 deletions lib/manager/components/CreateFeedSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import validator from 'validator'
import {createFeedSource} from '../actions/feeds'
import Loading from '../../common/components/Loading'
import {FREQUENCY_INTERVALS} from '../../common/constants'
import FeedFetchFrequency from './FeedFetchFrequency'
import {isExtensionEnabled} from '../../common/util/config'
import {validationState} from '../util'

import type {FetchFrequency, NewFeed} from '../../types'

import FeedFetchFrequency from './FeedFetchFrequency'

type Props = {
createFeedSource: typeof createFeedSource,
onCancel: () => void,
Expand Down Expand Up @@ -235,6 +236,26 @@ export default class CreateFeedSource extends Component<Props, State> {
</ListGroupItem>
</ListGroup>
</Panel>
{isExtensionEnabled('mtc') && (
<Panel header={<h3>Automatic publishing</h3>}>
<ListGroup fill>
<ListGroupItem>
<FormGroup>
<Checkbox
checked={model.autoPublish}
onChange={this._toggleCheckBox('autoPublish')}
>
<strong>Auto-publish this feed</strong>
</Checkbox>
<small>
Set this feed source to be automatically published
when a new version is created.
</small>
</FormGroup>
</ListGroupItem>
</ListGroup>
</Panel>
)}
</Col>
<Col xs={12}>
<Button
Expand Down
31 changes: 30 additions & 1 deletion lib/manager/components/GeneralSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import {

import * as feedsActions from '../actions/feeds'
import { FREQUENCY_INTERVALS } from '../../common/constants'
import { isExtensionEnabled } from '../../common/util/config'
import LabelAssigner from '../components/LabelAssigner'
import type { Feed, FetchFrequency, Project } from '../../types'
import type { ManagerUserState } from '../../types/reducers'
import LabelAssigner from '../components/LabelAssigner'

import FeedFetchFrequency from './FeedFetchFrequency'

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

// FIXME_QBD: refactor similar code (See CreateFeedSource).
_onToggleAutoPublish = () => {
const {feedSource, updateFeedSource} = this.props
updateFeedSource(feedSource, {autoPublish: !feedSource.autoPublish})
}

_onSelectFetchInterval = (fetchInterval: number) => {
const {feedSource, updateFeedSource} = this.props
updateFeedSource(feedSource, {fetchInterval})
Expand Down Expand Up @@ -201,6 +208,28 @@ export default class GeneralSettings extends Component<Props, State> {
</ListGroupItem>
</ListGroup>
</Panel>
{isExtensionEnabled('mtc') && (
<Panel header={<h3>Automatic publishing</h3>}>
<ListGroup fill>
<ListGroupItem>
<FormGroup>
<Checkbox
checked={feedSource.autoPublish}
disabled={disabled}
onChange={this._onToggleAutoPublish}
bsStyle='danger'
>
<strong>Auto-publish this feed</strong>
</Checkbox>
<small>
Set this feed source to be automatically published
when a new version is created.
</small>
</FormGroup>
</ListGroupItem>
</ListGroup>
</Panel>
)}
<Panel header={<h3>Labels</h3>}>
<LabelAssigner feedSource={feedSource} project={project} />
</Panel>
Expand Down
47 changes: 31 additions & 16 deletions lib/manager/components/version/FeedVersionDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import bboxPoly from 'turf-bbox-polygon'
import * as versionsActions from '../../actions/versions'
import {getConfigProperty, isExtensionEnabled} from '../../../common/util/config'
import {BLOCKING_ERROR_TYPES} from '../../util/version'
import type {FeedVersion, GtfsPlusValidation, Bounds, Feed} from '../../../types'
import type {ManagerUserState} from '../../../types/reducers'

import FeedVersionSpanChart from './FeedVersionSpanChart'
import VersionRetrievalBadge from './VersionRetrievalBadge'
import VersionSelectorDropdown from './VersionSelectorDropdown'

import type {FeedVersion, GtfsPlusValidation, Bounds, Feed} from '../../../types'
import type {ManagerUserState} from '../../../types/reducers'

type Props = {
comparedVersion: ?FeedVersion,
feedSource: Feed,
Expand Down Expand Up @@ -111,6 +111,28 @@ export default class FeedVersionDetails extends Component<Props> {
const mergeButtonLabel = isMergedServicePeriods
? 'Cannot re-merge feed'
: 'Merge with version'

const hasMtcExtension = isExtensionEnabled('mtc')
let publishWarningMessage
if (hasMtcExtension) {
if (hasBlockingIssue || hasGtfsPlusBlockingIssue) {
publishWarningMessage = (
<span>
Cannot publish version because it has a{' '}
{hasGtfsPlusBlockingIssue ? 'GTFS+ ' : ''}
blocking issue.
(See{' '}
<Link
to={`/feed/${feedSource.id}/version/${version.version}/${hasGtfsPlusBlockingIssue ? 'gtfsplus' : 'issues'}`}>
{hasGtfsPlusBlockingIssue ? 'GTFS+' : 'validation'} issues
</Link>.)
</span>
)
} else if (feedSource.autoPublish) {
publishWarningMessage = 'Reminder: this feed is already set to be auto-published!'
}
}

return (
<ListGroupItem>
<h4 className='pull-left' style={{ marginBottom: '2px' }}>
Expand All @@ -119,7 +141,7 @@ export default class FeedVersionDetails extends Component<Props> {
Feed validity dates
</span>
</h4>
{isExtensionEnabled('mtc') &&
{hasMtcExtension &&
<ButtonToolbar className='pull-right' style={{ marginTop: '2px' }}>
<VersionSelectorDropdown
dropdownProps={{
Expand Down Expand Up @@ -155,8 +177,7 @@ export default class FeedVersionDetails extends Component<Props> {
</Button>
</ButtonToolbar>
}
{(hasBlockingIssue || hasGtfsPlusBlockingIssue) &&
isExtensionEnabled('mtc') &&
{hasMtcExtension && (
<div
className='pull-right text-danger'
style={{
Expand All @@ -165,17 +186,11 @@ export default class FeedVersionDetails extends Component<Props> {
marginLeft: '5px',
textAlign: 'right',
width: '180px'
}}>
Cannot publish version because it has a{' '}
{hasGtfsPlusBlockingIssue ? 'GTFS+ ' : ''}
blocking issue.
(See{' '}
<Link
to={`/feed/${feedSource.id}/version/${version.version}/${hasGtfsPlusBlockingIssue ? 'gtfsplus' : 'issues'}`}>
{hasGtfsPlusBlockingIssue ? 'GTFS+' : 'validation'} issues
</Link>.)
}}
>
{publishWarningMessage}
</div>
}
)}

<FeedVersionSpanChart
activeVersion={version}
Expand Down
2 changes: 2 additions & 0 deletions lib/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export type FeedTransformRules = {
}

export type Feed = {
autoPublish?: boolean,
dateCreated: number,
deployable: boolean,
deployments?: Array<Deployment>,
Expand Down Expand Up @@ -413,6 +414,7 @@ export type Feed = {

export type NewFeed = {
autoFetchFeed?: boolean,
autoPublish?: boolean,
deployable?: boolean,
fetchFrequency: FetchFrequency,
fetchInterval: number,
Expand Down

0 comments on commit d188125

Please sign in to comment.