Skip to content

Commit 4b45037

Browse files
author
Vikas Agarwal
committed
Fixed bug around handling incomplete project screen and its after steps after changes for GitHub issues#1235,1104,1035
1 parent 60a7a0a commit 4b45037

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

src/components/TopBar/ProjectsToolBar.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ import _ from 'lodash'
88
import { SearchBar } from 'appirio-tech-react-components'
99
import Filters from './Filters'
1010

11-
import SVGIconImage from '../SVGIconImage'
12-
import CoderBot from '../CoderBot/CoderBot'
13-
1411
import { projectSuggestions, loadProjects } from '../../projects/actions/loadProjects'
1512
import {
1613
ROLE_CONNECT_COPILOT,
1714
ROLE_CONNECT_MANAGER,
18-
ROLE_ADMINISTRATOR,
19-
PROJECT_STATUS_IN_REVIEW
15+
ROLE_ADMINISTRATOR
2016
} from '../../config/constants'
2117

2218

@@ -141,7 +137,7 @@ class ProjectsToolBar extends Component {
141137

142138
render() {
143139
const { logo, userMenu, userRoles, criteria, isPowerUser } = this.props
144-
const { errorCreatingProject, isFilterVisible } = this.state
140+
const { isFilterVisible } = this.state
145141
const isLoggedIn = userRoles && userRoles.length
146142

147143
const noOfFilters = _.keys(criteria).length - 1 // -1 for default sort criteria

src/projects/create/components/ProjectWizard.jsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ProjectWizard extends Component {
5151
const incompleteProject = JSON.parse(incompleteProjectStr)
5252
const incompleteProduct = _.get(incompleteProject, 'details.products[0]')
5353
let wizardStep = WZ_STEP_INCOMP_PROJ_CONF
54+
let updateQuery = {}
5455
if (incompleteProduct && params && params.product) {
5556
// assumes the params.product to be id of a product because incomplete project is set only
5657
// after user selects a particular product
@@ -59,20 +60,21 @@ class ProjectWizard extends Component {
5960
// load project detais page directly if product of save project and deep link are the same
6061
if (product.id === incompleteProduct) {
6162
wizardStep = WZ_STEP_FILL_PROJ_DETAILS
62-
} else { // for different product type, update local state with URL params
63-
const projectType = findProductCategory(params.product)
64-
_.set(incompleteProject, 'type', projectType.id)
65-
_.set(incompleteProject, 'details.products[0]', product.id)
63+
updateQuery = {$merge : incompleteProject}
64+
} else {
65+
// explicitly ignores the wizardStep returned by the method
66+
// we need to call this method just to get updateQuery updated with correct project type and product
67+
this.loadProjectAndProductFromURL(params, updateQuery)
6668
}
6769
}
6870
}
6971
this.setState({
70-
project: update(this.state.project, {$merge : incompleteProject}),
71-
dirtyProject: update(this.state.dirtyProject, {$merge : incompleteProject}),
72-
wizardStep: wizardStep,
72+
project: update(this.state.project, updateQuery),
73+
dirtyProject: update(this.state.dirtyProject, updateQuery),
74+
wizardStep,
7375
isProjectDirty: false
7476
}, () => {
75-
typeof onStepChange === 'function' && onStepChange(this.state.wizardStep)
77+
typeof onStepChange === 'function' && onStepChange(this.state.wizardStep, this.state.project)
7678
})
7779
} else {
7880
// if there is no incomplete project in the local storage, load the wizard with appropriate step
@@ -111,7 +113,7 @@ class ProjectWizard extends Component {
111113
let wizardStep = type && product ? WZ_STEP_FILL_PROJ_DETAILS : null
112114
const updateQuery = {}
113115
if (params && params.product) { // if there exists product path param
114-
wizardStep = this.loadProjectAndProductFromURL(params.product, updateQuery)
116+
wizardStep = this.loadProjectAndProductFromURL(params, updateQuery)
115117
} else { // if there is not product path param, it should be first step of the wizard
116118
updateQuery['type'] = { $set : null }
117119
updateQuery['details'] = { products : { $set: [] } }
@@ -132,22 +134,28 @@ class ProjectWizard extends Component {
132134
/**
133135
* Loads project type and product from the given URL parameter.
134136
*
135-
* @param {string} urlParam URL parameter value which represents either project type or product
137+
* @param {object} urlParams URL parameters map
136138
* @param {object} updateQuery query object which would be updated according to parsed project type and product
137139
*
138140
* @return {number} step where wizard should move after parsing the URL param
139141
*/
140-
loadProjectAndProductFromURL(urlParam, updateQuery) {
142+
loadProjectAndProductFromURL(urlParams, updateQuery) {
143+
const productParam = urlParams && urlParams.product
144+
const statusParam = urlParams && urlParams.status
145+
if ('incomplete' === statusParam) {
146+
return WZ_STEP_INCOMP_PROJ_CONF
147+
}
148+
if (!productParam) return
141149
// first try the path param to be a project category
142-
let projectType = findCategory(urlParam, true)
150+
let projectType = findCategory(productParam, true)
143151
if (projectType) {// if its a category
144152
updateQuery['type'] = { $set : projectType.id }
145153
return WZ_STEP_SELECT_PROD_TYPE
146154
} else {
147155
// if it is not a category, it should be a product and we should be able to find a category for it
148-
projectType = findProductCategory(urlParam, true)
156+
projectType = findProductCategory(productParam, true)
149157
// finds product object from product alias
150-
const product = findProduct(urlParam, true)
158+
const product = findProduct(productParam, true)
151159
if (projectType) {// we can have `incomplete` as params.product
152160
updateQuery['type'] = { $set : projectType.id }
153161
updateQuery['details'] = { products : { $set: [product.id] } }
@@ -180,21 +188,25 @@ class ProjectWizard extends Component {
180188
* Removed incomplete project from the local storage and resets the state. Also, moves wizard to the first step.
181189
*/
182190
removeIncompleteProject() {
183-
const { onStepChange, onProjectUpdate } = this.props
191+
const { onStepChange } = this.props
184192
// remove incomplete project from local storage
185193
window.localStorage.removeItem(LS_INCOMPLETE_PROJECT)
186194
const projectType = _.get(this.state.project, 'type')
187195
const product = _.get(this.state.project, 'details.products[0]')
188196
let wizardStep = WZ_STEP_SELECT_PROJ_TYPE
197+
let project = null
189198
if (product) {
199+
project = { type: projectType, details: { products: [product] } }
190200
wizardStep = WZ_STEP_FILL_PROJ_DETAILS
191201
} else if (projectType) {
202+
project = { type: projectType, details: { products: [] } }
192203
wizardStep = WZ_STEP_SELECT_PROD_TYPE
193204
}
194205
this.setState({
195-
wizardStep: wizardStep
206+
project: _.merge({}, project),
207+
dirtyProject: _.merge({}, project),
208+
wizardStep
196209
}, () => {
197-
typeof onProjectUpdate === 'function' && onProjectUpdate(this.state.dirtyProject, true)
198210
typeof onStepChange === 'function' && onStepChange(this.state.wizardStep, this.state.project)
199211
})
200212
}

src/projects/create/containers/CreateContainer.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ class CreateConainer extends React.Component {
144144
const { userRoles } = this.props
145145
const isLoggedIn = userRoles && userRoles.length > 0
146146
if (isLoggedIn) {
147-
this.props.router.push("/projects")
147+
this.props.router.push('/projects')
148148
} else {
149-
this.props.router.push("/")
149+
this.props.router.push('/')
150150
}
151151
}
152152

@@ -156,7 +156,7 @@ class CreateConainer extends React.Component {
156156
{...this.props}
157157
createProject={ this.createProject }
158158
processing={ this.state.creatingProject }
159-
showModal={true}
159+
showModal
160160
closeModal={ this.closeWizard }
161161
onStepChange={ (wizardStep, updatedProject) => {
162162
// type of the project
@@ -172,7 +172,9 @@ class CreateConainer extends React.Component {
172172
// updates the productType variable to use first alias to create SEO friendly URL
173173
productType = _.get(product, 'aliases[0]', productType)
174174
if (wizardStep === ProjectWizard.Steps.WZ_STEP_INCOMP_PROJ_CONF) {
175-
browserHistory.push(NEW_PROJECT_PATH + '/incomplete')
175+
let productUrl = productType ? ('/' + productType) : ''
176+
productUrl = !productType && projectType ? ('/' + projectType) : productUrl
177+
browserHistory.push(NEW_PROJECT_PATH + productUrl + '/incomplete')
176178
}
177179
if (wizardStep === ProjectWizard.Steps.WZ_STEP_SELECT_PROJ_TYPE) {
178180
browserHistory.push(NEW_PROJECT_PATH + '/' + window.location.search)

src/routes.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const renderTopBarWithProjectsToolBar = (props) => <TopBarContainer toolbar={ Pr
104104
export default (
105105
<Route path="/" onUpdate={() => window.scrollTo(0, 0)} component={ App } onEnter={ redirectToConnect }>
106106
<IndexRoute components={{ topbar: renderTopBarWithProjectsToolBar, content: Home }} />
107-
<Route path="/new-project(/:product)" components={{ topbar: null, content: CreateContainer }} onEnter={ validateCreateProjectParams } />
107+
<Route path="/new-project(/:product)(/:status)" components={{ topbar: null, content: CreateContainer }} onEnter={ validateCreateProjectParams } />
108108
<Route path="/new-project-callback" components={{ topbar: null, content: CreateContainer }} />
109109
<Route path="/terms" components={{ topbar: renderTopBarWithProjectsToolBar, content: ConnectTerms }} />
110110
<Route path="/login" components={{ topbar: renderTopBarWithProjectsToolBar, content: LoginRedirect }} />

0 commit comments

Comments
 (0)