Skip to content

Commit 4759d70

Browse files
author
vikasrohit
authored
Merge pull request #1115 from appirio-tech/feature/retain-common-info-changing-product
Github issue#1037, Project spec information is not saved when changing project types
2 parents c5f95c9 + 2d42d35 commit 4759d70

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

src/config/projectWizard/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import _ from 'lodash'
2+
import typeToSpecification from '../projectSpecification/typeToSpecification'
3+
14
const products = {
25
Design: {
36
icon: 'product-app-visual-design',
@@ -107,3 +110,32 @@ export function findProductCategory(product) {
107110
}
108111
}
109112
}
113+
114+
/**
115+
* Finds field from the project creation template
116+
*
117+
* @param {string} product id of the product. It should resolve to a template where search is to be made.
118+
* @param {string} sectionId id of the section in the product template
119+
* @param {string} subSectionId id of the sub section under the section identified by sectionId
120+
* @param {string} fieldName name of the field to be fetched
121+
*
122+
* @return {object} field from the template, if found, null otherwise
123+
*/
124+
export function getProjectCreationTemplateField(product, sectionId, subSectionId, fieldName) {
125+
let specification = 'topcoder.v1'
126+
if (product)
127+
specification = typeToSpecification[product]
128+
const sections = require(`../projectQuestions/${specification}`).basicSections
129+
const section = _.find(sections, {id: sectionId})
130+
let subSection = null
131+
if (subSectionId && section) {
132+
subSection = _.find(section.subSections, {id : subSectionId })
133+
}
134+
if (subSection) {
135+
if (subSectionId === 'questions') {
136+
return _.find(subSection.questions, { fieldName })
137+
}
138+
return subSection.fieldName === fieldName ? subSection : null
139+
}
140+
return null
141+
}

src/projects/create/components/ProjectWizard.jsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash'
22
import { unflatten } from 'flat'
33
import React, { Component, PropTypes } from 'react'
44

5-
import config, { findProductCategory } from '../../../config/projectWizard'
5+
import config, { findProductCategory, getProjectCreationTemplateField } from '../../../config/projectWizard'
66
import Wizard from '../../../components/Wizard'
77
import SelectProduct from './SelectProduct'
88
import IncompleteProjectConfirmation from './IncompleteProjectConfirmation'
@@ -155,7 +155,7 @@ class ProjectWizard extends Component {
155155
const updateQuery = { }
156156
const detailsQuery = { products : [product] }
157157
// restore common fields from dirty project
158-
this.restoreCommonDetails(updateQuery, detailsQuery)
158+
this.restoreCommonDetails(product, updateQuery, detailsQuery)
159159
updateQuery.details = { $set : detailsQuery}
160160
if (projectType) {
161161
updateQuery.type = {$set : projectType }
@@ -175,7 +175,7 @@ class ProjectWizard extends Component {
175175
*
176176
* Added for Github issue#1037
177177
*/
178-
restoreCommonDetails(updateQuery, detailsQuery) {
178+
restoreCommonDetails(updatedProduct, updateQuery, detailsQuery) {
179179
const name = _.get(this.state.dirtyProject, 'name')
180180
// if name was already entered, restore it
181181
if (name) {
@@ -191,6 +191,32 @@ class ProjectWizard extends Component {
191191
if (utm) {
192192
detailsQuery.utm = { code : utm.code }
193193
}
194+
const appDefinitionQuery = {}
195+
const goal = _.get(this.state.dirtyProject, 'details.appDefinition.goal')
196+
// finds the goal field from the updated product template
197+
const goalField = getProjectCreationTemplateField(
198+
updatedProduct,
199+
'appDefinition',
200+
'questions',
201+
'details.appDefinition.goal.value'
202+
)
203+
// if goal was already entered and updated product template has the field, restore it
204+
if (goalField && goal) {
205+
appDefinitionQuery.goal = goal
206+
}
207+
const users = _.get(this.state.dirtyProject, 'details.appDefinition.users')
208+
// finds the users field from the target product template
209+
const usersField = getProjectCreationTemplateField(
210+
updatedProduct,
211+
'appDefinition',
212+
'questions',
213+
'details.appDefinition.users.value'
214+
)
215+
// if users was already entered and updated product template has the field, restore it
216+
if (usersField && users) {
217+
appDefinitionQuery.users = users
218+
}
219+
detailsQuery.appDefinition = appDefinitionQuery
194220
}
195221

196222
handleProjectChange(change) {

0 commit comments

Comments
 (0)