Skip to content

Commit 2b52855

Browse files
author
Vikas Agarwal
committed
Github issue#1035, URL does not change when selecting project from "New Project" page
— Implemented required behaviour on ad hoc basis instead of enabling the Wizard or ProjectWizard component for being URL aware.
1 parent d57aa62 commit 2b52855

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

src/projects/create/components/ProjectWizard.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ProjectWizard extends Component {
105105
* It also moves the wizard to the project details step if there exists an incomplete project.
106106
*/
107107
loadIncompleteProject() {
108-
const { onStepChange } = this.props
108+
const { onStepChange, onProjectUpdate } = this.props
109109
const incompleteProjectStr = window.localStorage.getItem(LS_INCOMPLETE_PROJECT)
110110
if(incompleteProjectStr) {
111111
const incompleteProject = JSON.parse(incompleteProjectStr)
@@ -114,6 +114,7 @@ class ProjectWizard extends Component {
114114
dirtyProject: update(this.state.dirtyProject, { $merge : incompleteProject }),
115115
wizardStep: WZ_STEP_FILL_PROJ_DETAILS
116116
}, () => {
117+
typeof onProjectUpdate === 'function' && onProjectUpdate(this.state.dirtyProject, false)
117118
typeof onStepChange === 'function' && onStepChange(this.state.wizardStep)
118119
})
119120
}
@@ -148,7 +149,7 @@ class ProjectWizard extends Component {
148149

149150
updateProducts(projectType, product) {
150151
window.scrollTo(0, 0)
151-
const { onStepChange } = this.props
152+
const { onStepChange, onProjectUpdate } = this.props
152153
// const products = _.get(this.state.project, 'details.products')
153154
const updateQuery = { }
154155
const detailsQuery = { products : [product] }
@@ -163,6 +164,7 @@ class ProjectWizard extends Component {
163164
dirtyProject: update(this.state.project, updateQuery),
164165
wizardStep: WZ_STEP_FILL_PROJ_DETAILS
165166
}, () => {
167+
typeof onProjectUpdate === 'function' && onProjectUpdate(this.state.dirtyProject, false)
166168
typeof onStepChange === 'function' && onStepChange(this.state.wizardStep)
167169
})
168170
}

src/projects/create/containers/CreateContainer.jsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash'
22
import React, { PropTypes } from 'react'
3-
import { withRouter } from 'react-router'
3+
import { withRouter, browserHistory } from 'react-router'
44
import { connect } from 'react-redux'
55
import { renderComponent, branch, compose, withProps } from 'recompose'
66
import { createProjectWithStatus as createProjectAction, fireProjectDirty, fireProjectDirtyUndo } from '../../actions/project'
@@ -139,13 +139,33 @@ class CreateConainer extends React.Component {
139139
{...this.props}
140140
createProject={ this.createProject }
141141
processing={ this.state.creatingProject }
142-
onStepChange={ (wizardStep) => this.setState({
143-
wizardStep
144-
})}
145-
onProjectUpdate={ (updatedProject) => this.setState({
146-
isProjectDirty: true,
147-
updatedProject
148-
})}
142+
onStepChange={ (wizardStep) => {
143+
if (wizardStep === ProjectWizard.Steps.WZ_STEP_INCOMP_PROJ_CONF) {
144+
browserHistory.push('/new-project/incomplete')
145+
}
146+
if (wizardStep === ProjectWizard.Steps.WZ_STEP_SELECT_PROD_TYPE) {
147+
browserHistory.push('/new-project/')
148+
}
149+
this.setState({
150+
wizardStep
151+
})
152+
}
153+
}
154+
onProjectUpdate={ (updatedProject, dirty=true) => {
155+
const prevProduct = _.get(this.state.updatedProject, 'details.products[0]', null)
156+
const product = _.get(updatedProject, 'details.products[0]', null)
157+
// compares updated product with previous product to know if user has updated the product
158+
if (prevProduct !== product) {
159+
if (product) {
160+
browserHistory.push('/new-project/' + product)
161+
}
162+
}
163+
this.setState({
164+
isProjectDirty: dirty,
165+
updatedProject
166+
})
167+
}
168+
}
149169
/>
150170
)
151171
}

src/routes.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ browserHistory.listen(location => {
3030
window.analytics.page('Project Specification')
3131
} else if (/^\/$/.test(location.pathname)) {
3232
window.analytics.page('Connect Home')
33+
} else if (/^new-project\/$/.test(location.pathname)) {
34+
window.analytics.page('New Project : Select Product')
35+
} else if (/^new-project\/incomplete$/.test(location.pathname)) {
36+
window.analytics.page('New Project : Incomplete Project')
37+
} else if (/^new-project\/[a-zA-Z0-9\_]+$/.test(location.pathname)) {
38+
window.analytics.page('New Project : Project Details')
3339
}
3440
}
3541
})
@@ -81,9 +87,13 @@ const validateCreateProjectParams = (nextState, replace, callback) => {
8187
const product = nextState.params.product
8288
const productCategory = findProductCategory(product)
8389
if (product && product.trim().length > 0 && !productCategory) {
84-
replace('/404')
90+
// workaround to add URL for incomplete project confirmation step
91+
// ideally we should have better URL naming which resolves each route with distinct patterns
92+
if (product !== 'incomplete') {
93+
replace('/404')
94+
}
8595
}
86-
callback()
96+
callback()
8797
}
8898

8999
const renderTopBarWithProjectsToolBar = () => <TopBarContainer toolbar={ ProjectsToolBar } />

0 commit comments

Comments
 (0)