From e0d5f02789fd2f4f19850e392dca8601ba69d7bb Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Mon, 14 Aug 2017 17:15:07 +0530 Subject: [PATCH 1/2] =?UTF-8?q?Github=20issue#1037,=20Project=20spec=20inf?= =?UTF-8?q?ormation=20is=20not=20saved=20when=20changing=20project=20types?= =?UTF-8?q?=20=E2=80=94=20copying=20goal=20and=20users=20fields=20as=20wel?= =?UTF-8?q?l=20when=20user=20changes=20the=20product=20type.=20=E2=80=94?= =?UTF-8?q?=20it=20now=20validates,=20before=20copying,=20if=20the=20targe?= =?UTF-8?q?t=20product=20template=20contains=20the=20fields=20being=20copi?= =?UTF-8?q?ed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/projectWizard/index.js | 32 +++++++++++++++++++ .../create/components/ProjectWizard.jsx | 32 +++++++++++++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/config/projectWizard/index.js b/src/config/projectWizard/index.js index 8e1341b27..d0256528b 100644 --- a/src/config/projectWizard/index.js +++ b/src/config/projectWizard/index.js @@ -1,3 +1,6 @@ +import _ from 'lodash' +import typeToSpecification from '../projectSpecification/typeToSpecification' + const products = { Design: { icon: 'product-app-visual-design', @@ -107,3 +110,32 @@ export function findProductCategory(product) { } } } + +/** + * Finds field from the project creation template + * + * @param {string} product id of the product. It should resolve to a template where search is to be made. + * @param {string} sectionId id of the section in the product template + * @param {string} subSectionId id of the sub section under the section identified by sectionId + * @param {string} fieldName name of the field to be fetched + * + * @return {object} field from the template, if found, null otherwise + */ +export function getProjectCreationTemplateField(product, sectionId, subSectionId, fieldName) { + let specification = 'topcoder.v1' + if (product) + specification = typeToSpecification[product] + let sections = require(`../projectQuestions/${specification}`).basicSections + const section = _.find(sections, {id: sectionId}) + let subSection = null + if (subSectionId && section) { + subSection = _.find(section.subSections, {id : subSectionId }) + } + if (subSection) { + if (subSectionId === 'questions') { + return _.find(subSection.questions, { fieldName }) + } + return subSection.fieldName === fieldName ? subSection : null + } + return null + } \ No newline at end of file diff --git a/src/projects/create/components/ProjectWizard.jsx b/src/projects/create/components/ProjectWizard.jsx index e56cf4700..e8f3fdc90 100644 --- a/src/projects/create/components/ProjectWizard.jsx +++ b/src/projects/create/components/ProjectWizard.jsx @@ -2,7 +2,7 @@ import _ from 'lodash' import { unflatten } from 'flat' import React, { Component, PropTypes } from 'react' -import config, { findProductCategory } from '../../../config/projectWizard' +import config, { findProductCategory, getProjectCreationTemplateField } from '../../../config/projectWizard' import Wizard from '../../../components/Wizard' import SelectProduct from './SelectProduct' import IncompleteProjectConfirmation from './IncompleteProjectConfirmation' @@ -155,7 +155,7 @@ class ProjectWizard extends Component { const updateQuery = { } const detailsQuery = { products : [product] } // restore common fields from dirty project - this.restoreCommonDetails(updateQuery, detailsQuery) + this.restoreCommonDetails(product, updateQuery, detailsQuery) updateQuery.details = { $set : detailsQuery} if (projectType) { updateQuery.type = {$set : projectType } @@ -175,7 +175,7 @@ class ProjectWizard extends Component { * * Added for Github issue#1037 */ - restoreCommonDetails(updateQuery, detailsQuery) { + restoreCommonDetails(updatedProduct, updateQuery, detailsQuery) { const name = _.get(this.state.dirtyProject, 'name') // if name was already entered, restore it if (name) { @@ -191,6 +191,32 @@ class ProjectWizard extends Component { if (utm) { detailsQuery.utm = { code : utm.code } } + const appDefinitionQuery = {} + const goal = _.get(this.state.dirtyProject, 'details.appDefinition.goal') + // finds the goal field from the updated product template + const goalField = getProjectCreationTemplateField( + updatedProduct, + 'appDefinition', + 'questions', + 'details.appDefinition.goal.value' + ) + // if goal was already entered and updated product template has the field, restore it + if (goalField && goal) { + appDefinitionQuery.goal = goal + } + const users = _.get(this.state.dirtyProject, 'details.appDefinition.users') + // finds the users field from the target product template + const usersField = getProjectCreationTemplateField( + updatedProduct, + 'appDefinition', + 'questions', + 'details.appDefinition.users.value' + ) + // if users was already entered and updated product template has the field, restore it + if (usersField && users) { + appDefinitionQuery.users = users + } + detailsQuery.appDefinition = appDefinitionQuery } handleProjectChange(change) { From 2d42d357c4205b8eb304e9c59c07c60a5e663ee3 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Mon, 14 Aug 2017 17:43:21 +0530 Subject: [PATCH 2/2] Fixed lint error --- src/config/projectWizard/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/projectWizard/index.js b/src/config/projectWizard/index.js index d0256528b..4570ff18d 100644 --- a/src/config/projectWizard/index.js +++ b/src/config/projectWizard/index.js @@ -125,7 +125,7 @@ export function getProjectCreationTemplateField(product, sectionId, subSectionId let specification = 'topcoder.v1' if (product) specification = typeToSpecification[product] - let sections = require(`../projectQuestions/${specification}`).basicSections + const sections = require(`../projectQuestions/${specification}`).basicSections const section = _.find(sections, {id: sectionId}) let subSection = null if (subSectionId && section) {