Skip to content

Commit 91ff274

Browse files
committed
fix(editor): fix start from scratch
1 parent 7ac8bef commit 91ff274

File tree

10 files changed

+148
-115
lines changed

10 files changed

+148
-115
lines changed

lib/editor/actions/editor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export function uploadBrandingAsset (feedId, entityId, component, file) {
241241

242242
const fetchingBaseGtfs = createAction('FETCHING_BASE_GTFS')
243243
const receiveBaseGtfs = createAction('RECEIVE_BASE_GTFS')
244+
const showEditorModal = createAction('SHOW_EDITOR_MODAL')
244245

245246
// FIXME: add additional params
246247
// TODO: fetch nested elements
@@ -304,6 +305,7 @@ export function fetchBaseGtfs ({namespace, component, newId, activeEntityId, fee
304305
dispatch(fetchingBaseGtfs({namespace}))
305306
if (!namespace) {
306307
console.error('Cannot fetch GTFS for undefined or null namespace')
308+
dispatch(showEditorModal())
307309
return
308310
}
309311
return dispatch(fetchGraphQL({query, variables: {namespace}}))

lib/editor/actions/snapshots.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function downloadSnapshot (feedSource, snapshot) {
6666
export function downloadSnapshotViaCredentials (snapshot, isPublic, prefix) {
6767
return function (dispatch, getState) {
6868
const route = isPublic ? 'public' : 'secure'
69-
const url = `/api/editor/${route}/snapshot/${snapshot.id}/downloadtoken?feedId=${snapshot.feedSourceId}`
69+
const url = `/api/editor/${route}/snapshot/${snapshot.id}/downloadtoken?feedId=${snapshot.feedId}`
7070
dispatch(secureFetch(url))
7171
.then(response => response.json())
7272
.then(credentials => {
@@ -95,11 +95,11 @@ export function createSnapshot (feedSource, name, comment) {
9595
}
9696
dispatch(creatingSnapshot({feedSource, snapshot}))
9797
return dispatch(secureFetch(url, 'post', snapshot))
98-
.then((response) => response.json())
99-
.then(() => {
100-
dispatch(createdSnapshot(name))
101-
return dispatch(fetchSnapshots(feedSource))
102-
})
98+
.then(res => dispatch(handleJobResponse(res, 'Error creating snapshot')))
99+
// .then(() => {
100+
// dispatch(createdSnapshot(name))
101+
// return dispatch(fetchSnapshots(feedSource))
102+
// })
103103
}
104104
}
105105

@@ -121,10 +121,10 @@ export function deleteSnapshot (feedSource, snapshot) {
121121
* triggers a snapshot of the feed version's tables and sets the editor namespace
122122
* for the version's parent feed source.
123123
*/
124-
export function loadFeedVersionForEditing (feedVersion) {
124+
export function loadFeedVersionForEditing ({feedSourceId, feedVersionId}) {
125125
return function (dispatch, getState) {
126-
dispatch(loadingFeedVersionForEditing(feedVersion))
127-
const url = `/api/editor/secure/snapshot/import?feedId=${feedVersion.feedSource.id}&feedVersionId=${feedVersion.id}`
126+
dispatch(loadingFeedVersionForEditing({feedSourceId, feedVersionId}))
127+
const url = `/api/editor/secure/snapshot/import?feedId=${feedSourceId}&feedVersionId=${feedVersionId}`
128128
return dispatch(secureFetch(url, 'post'))
129129
.then(res => dispatch(handleJobResponse(res)))
130130
}

lib/editor/components/EditorFeedSourcePanel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ export default class EditorFeedSourcePanel extends Component {
3535
_openModal = () => this.refs.snapshotModal.open()
3636

3737
_onLoadVersion = () => {
38-
const {feedSource} = this.props
38+
const {feedSource, loadFeedVersionForEditing} = this.props
3939
const version = feedSource.feedVersions[feedSource.feedVersions.length - 1]
40+
const {id: feedVersionId, feedSourceId} = version
4041
this.refs.confirmModal.open({
4142
title: getMessage(this.messages, 'load'),
4243
body: getMessage(this.messages, 'confirmLoad'),
43-
onConfirm: () => this.props.loadFeedVersionForEditing(version)
44+
onConfirm: () => loadFeedVersionForEditing({feedSourceId, feedVersionId})
4445
})
4546
}
4647

lib/editor/components/EditorHelpModal.js

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import React, { Component, PropTypes } from 'react'
2-
import { Modal, Button, Checkbox, Carousel } from 'react-bootstrap'
1+
import Icon from '@conveyal/woonerf/components/icon'
2+
import React, {Component, PropTypes} from 'react'
3+
import {Modal, Button, ButtonToolbar, Checkbox} from 'react-bootstrap'
4+
import {LinkContainer} from 'react-router-bootstrap'
5+
6+
import {getConfigProperty} from '../../common/util/config'
37

48
export default class EditorHelpModal extends Component {
59
static propTypes = {
@@ -13,6 +17,22 @@ export default class EditorHelpModal extends Component {
1317

1418
_onToggleTutorial = () => this.setState({hideTutorial: !this.state.hideTutorial})
1519

20+
_buildFromScratch = () => {
21+
const {createSnapshot, feedSource} = this.props
22+
createSnapshot(feedSource, 'Blank')
23+
}
24+
25+
_onClickLoad = () => {
26+
const {feedSource, loadFeedVersionForEditing} = this.props
27+
const {latestVersionId: feedVersionId, id: feedSourceId} = feedSource
28+
loadFeedVersionForEditing({feedSourceId, feedVersionId})
29+
}
30+
31+
_onClickReload = () => {
32+
this.props.onComponentMount({})
33+
this.close()
34+
}
35+
1636
close = () => {
1737
if (this.state.hideTutorial !== this.props.hideTutorial) {
1838
this.props.setTutorialHidden(!this.props.hideTutorial)
@@ -25,21 +45,61 @@ export default class EditorHelpModal extends Component {
2545
}
2646

2747
render () {
28-
if (!this.props.show) {
48+
const {feedSource, isNewFeed, show, status} = this.props
49+
if (!show) {
2950
return null
3051
}
3152
const {Body, Footer, Header, Title} = Modal
32-
const {Caption, Item} = Carousel
3353
return (
3454
<Modal
3555
show={this.state.showModal}
3656
onHide={this.close}
37-
bsSize='large'>
38-
<Header closeButton>
57+
// Prevent closure of modal if there is no snapshot yet
58+
backdrop={isNewFeed ? 'static' : undefined}
59+
>
60+
<Header closeButton={!isNewFeed}>
3961
<Title>Welcome to the GTFS Editor</Title>
4062
</Header>
4163
<Body>
42-
<Carousel>
64+
{isNewFeed
65+
? <div>
66+
<p>There is no feed loaded in the editor. To begin editing you can either
67+
start from scratch or import an existing version (if a version exists).</p>
68+
{status.snapshotFinished
69+
? <Button
70+
bsStyle='primary'
71+
bsSize='large'
72+
block
73+
onClick={this._onClickReload} >
74+
<Icon type='check' /> Begin editing
75+
</Button>
76+
: <ButtonToolbar>
77+
<Button
78+
bsSize='large'
79+
block
80+
onClick={this._buildFromScratch}
81+
disabled={status.creatingSnapshot} >
82+
<Icon type='file' /> Start from scratch
83+
</Button>
84+
<Button
85+
bsSize='large'
86+
block
87+
onClick={this._onClickLoad}
88+
disabled={!feedSource.latestVersionId || status.creatingSnapshot} >
89+
<Icon type='upload' /> Import latest version
90+
</Button>
91+
</ButtonToolbar>
92+
}
93+
</div>
94+
: <p>For instructions on using the editor, view the{' '}
95+
<a
96+
target='_blank'
97+
href={`${getConfigProperty('application.docs_url')}/en/latest/user/editor/introduction/`} >
98+
documentation
99+
</a>.
100+
</p>
101+
}
102+
{/* <Carousel>
43103
<Item>
44104
<img width={900} height={500} alt='900x500' src='https://react-bootstrap.github.io/assets/carousel.png' />
45105
<Caption>
@@ -61,17 +121,22 @@ export default class EditorHelpModal extends Component {
61121
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
62122
</Caption>
63123
</Item>
64-
</Carousel>
124+
</Carousel> */}
65125
</Body>
66126
<Footer>
67-
<small className='pull-left'>
127+
{!isNewFeed && <small className='pull-left'>
68128
<Checkbox
69129
checked={this.state.hideTutorial}
70130
onChange={this._onToggleTutorial}>
71131
Do not show when editor opens
72132
</Checkbox>
73-
</small>
74-
<Button onClick={this.close}>Close</Button>
133+
</small>}
134+
{isNewFeed
135+
? <LinkContainer to={feedSource ? `/feed/${feedSource.id}` : `/home`}>
136+
<Button><Icon type='chevron-left' /> Back to feed source</Button>
137+
</LinkContainer>
138+
: <Button onClick={this.close}>Close</Button>
139+
}
75140
</Footer>
76141
</Modal>
77142
)

lib/editor/components/GtfsEditor.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ export default class GtfsEditor extends Component {
154154
const {
155155
feedSource,
156156
user,
157+
createSnapshot,
158+
loadFeedVersionForEditing,
157159
activeEntityId,
158160
tableData,
159161
entities,
@@ -176,6 +178,7 @@ export default class GtfsEditor extends Component {
176178
newGtfsEntity,
177179
mapState,
178180
hideTutorial,
181+
status,
179182
setTutorialHidden,
180183
project
181184
} = this.props
@@ -210,6 +213,18 @@ export default class GtfsEditor extends Component {
210213
expanded={sidebarExpanded}
211214
feedSource={feedSource}
212215
setActiveEntity={setActiveEntity} />
216+
{status.showEditorModal
217+
? <EditorHelpModal
218+
show
219+
isNewFeed
220+
feedSource={feedSource}
221+
status={status}
222+
loadFeedVersionForEditing={loadFeedVersionForEditing}
223+
onComponentMount={this.props.onComponentMount}
224+
createSnapshot={createSnapshot}
225+
setTutorialHidden={setTutorialHidden} />
226+
: null
227+
}
213228
<div style={{
214229
position: 'fixed',
215230
left: sidebarExpanded ? 130 : 50,

lib/editor/containers/ActiveGtfsEditor.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
removeEditorLock,
4141
uploadBrandingAsset
4242
} from '../actions/editor'
43+
import {createSnapshot, loadFeedVersionForEditing} from '../actions/snapshots'
4344
import {updateUserMetadata} from '../../manager/actions/user'
4445
import {findProjectByFeedSource} from '../../manager/util'
4546
import {setTutorialHidden} from '../../manager/actions/ui'
@@ -63,7 +64,7 @@ const mapStateToProps = (state, ownProps) => {
6364
const subEntityId = typeof ownProps.routeParams.subEntityId !== 'undefined' ? +ownProps.routeParams.subEntityId : undefined
6465
const {data, editSettings: editSettingsState, mapState} = state.editor
6566
const {present: editSettings} = editSettingsState
66-
const {active, tables, tripPatterns} = data
67+
const {active, tables, tripPatterns, status} = data
6768
// FIXME: entityId is now a non-string line number and somewhere the number is
6869
// being cast to a string.
6970
const activeEntity =
@@ -121,6 +122,7 @@ const mapStateToProps = (state, ownProps) => {
121122
mapState,
122123
controlPoints,
123124
patternCoordinates,
125+
status,
124126
validationErrors,
125127
sidebarExpanded: state.ui.sidebarExpanded
126128
}
@@ -228,6 +230,10 @@ const mapDispatchToProps = (dispatch, ownProps) => {
228230
handleControlPointDragStart: (controlPoint) => dispatch(handleControlPointDragStart(controlPoint)),
229231
handleControlPointDrag: (controlPoints, index, latlng, pattern, patternCoordinates) => dispatch(handleControlPointDrag(controlPoints, index, latlng, pattern, patternCoordinates)),
230232

233+
// SNAPHOTS
234+
createSnapshot: (feedSource, name, comment) => dispatch(createSnapshot(feedSource, name, comment)),
235+
loadFeedVersionForEditing: (payload) => dispatch(loadFeedVersionForEditing(payload)),
236+
231237
// EDITOR UI
232238
setTutorialHidden: (value) => dispatch(setTutorialHidden(value))
233239
}

0 commit comments

Comments
 (0)