From dc9057638bbbf2d62adc732487f7a9aff77378b9 Mon Sep 17 00:00:00 2001 From: Vigneshkumar Chinnachamy M Date: Fri, 2 Aug 2019 00:40:13 +0530 Subject: [PATCH 1/4] Fix #3228 - show value labels instead of values in scope change request. --- .../ScopeChangeRequest/ScopeChangeRequest.jsx | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/projects/detail/components/ScopeChangeRequest/ScopeChangeRequest.jsx b/src/projects/detail/components/ScopeChangeRequest/ScopeChangeRequest.jsx index c0b4fcfd9..580d396a0 100644 --- a/src/projects/detail/components/ScopeChangeRequest/ScopeChangeRequest.jsx +++ b/src/projects/detail/components/ScopeChangeRequest/ScopeChangeRequest.jsx @@ -57,6 +57,41 @@ class ScopeChangeRequest extends React.Component { return fieldDescriptionObject.summaryTitle || fieldDescriptionObject.title } + /* + Gets the readable labels (E.g. "Banking or Financial Services") for the values (E.g. finserv) + using the field key (E.g. details.appDefinition.mobilityTestingType) + */ + deduceValueLabel(template, invertedScopeFieldPaths, fieldkey, value) { + const key = invertedScopeFieldPaths[`details.${fieldkey}`].replace(/\.fieldName$/, '') + const fieldDescriptionObject = _.get(template, key) + const fieldType = fieldDescriptionObject.type + + const questionTypesWithOptions = [ + 'radio-group', + 'tiled-radio-group', + 'see-attached-tiled-radio-group', + 'checkbox-group', + 'tiled-checkbox-group', + 'select-dropdown', + 'slide-radiogroup' + ] + + // We can deduce the label only for predefined values. Otherwise, fall back to actual value entered. + if (_.includes(questionTypesWithOptions, fieldType) && fieldDescriptionObject.options) { + const valueLabelMap = _.keyBy(fieldDescriptionObject.options, o => o.value) + const getLabel = option => option.label || option.title + + // Checkbox like questions result in an array. Radio button like questions result in premitive value + if (value instanceof Array) { + return value.map(v => getLabel(valueLabelMap[v])) + } else { + return getLabel(valueLabelMap[value]) + } + } else { + return value + } + } + /* Fieldnames from the template holds the full property path for values in the form e.g. "details.appDefinition.numberScreens" could be the full property path for the value of "number of screens" @@ -98,7 +133,8 @@ class ScopeChangeRequest extends React.Component { const oldVal = _.get(oldScope, diffKey) const label = this.deduceFieldLabel(template, invertedScopeFieldPaths, diffKey) - const formatValue = value => (_.isEmpty(value) ? '(empty)' : JSON.stringify(value, null, ' ')) + const valueToLabel = value => this.deduceValueLabel(template, invertedScopeFieldPaths, diffKey, value) + const formatValue = value => (_.isEmpty(value) ? '(empty)' : JSON.stringify(valueToLabel(value), null, ' ')) return { label, From 4a78959ecff745f139535f60128cd3e620719fcd Mon Sep 17 00:00:00 2001 From: Vigneshkumar Chinnachamy M Date: Fri, 2 Aug 2019 00:44:47 +0530 Subject: [PATCH 2/4] Fix #3229 - after scope form reset, reset summary labels --- .../detail/components/Accordion/Accordion.jsx | 22 +++++++++++++++---- .../detail/components/SpecQuestions.jsx | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/projects/detail/components/Accordion/Accordion.jsx b/src/projects/detail/components/Accordion/Accordion.jsx index ab3b55764..995c0d0b5 100644 --- a/src/projects/detail/components/Accordion/Accordion.jsx +++ b/src/projects/detail/components/Accordion/Accordion.jsx @@ -75,14 +75,28 @@ class Accordion extends React.Component { } componentDidMount() { - const { children } = this.props + const { name, value } = this.getFormControlValue(this.props) + this.updateValue(name, value) + } + + componentDidUpdate(oldProps) { + if (this.props.isFormReset && !oldProps.isFormReset) { + const { name, value } = this.getFormControlValue(this.props) + this.updateValue(name, value) + } + } + + getFormControlValue(props) { + let name + let value - // find formzy controls which have `value` property and get initial value for `value` - React.Children.forEach(children, (listItem) => { + // find formzy controls which have `value` property and get initial value + React.Children.forEach(props.children, (listItem) => { React.Children.forEach(listItem.props.children, (control) => { - this.updateValue(control.props.name, control.props.value) + ({ name, value } = control.props) }) }) + return { name, value } } toggle(evt) { diff --git a/src/projects/detail/components/SpecQuestions.jsx b/src/projects/detail/components/SpecQuestions.jsx index 964b91d0b..e7c18f717 100644 --- a/src/projects/detail/components/SpecQuestions.jsx +++ b/src/projects/detail/components/SpecQuestions.jsx @@ -380,6 +380,7 @@ class SpecQuestions extends React.Component { productTemplates, productCategories, isCreation, + isProjectDirty } = this.props const { skillOptions } = this.state @@ -406,6 +407,7 @@ class SpecQuestions extends React.Component { title={q.summaryTitle || q.title} type={q.type} question={q} + isFormReset={!isProjectDirty} options={q.options || skillOptions || buildAddonsOptions(q, productTemplates, productCategories)} > {this.renderQ(q, index)} From d41e0052e06bc37c848c0a1a751e4df9a45f405d Mon Sep 17 00:00:00 2001 From: Vigneshkumar Chinnachamy M Date: Fri, 2 Aug 2019 00:48:09 +0530 Subject: [PATCH 3/4] Fix #3230 - merge array fields properly after activating scope change request --- src/projects/reducers/project.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/projects/reducers/project.js b/src/projects/reducers/project.js index 8a227dc8f..6abe03f07 100644 --- a/src/projects/reducers/project.js +++ b/src/projects/reducers/project.js @@ -379,7 +379,16 @@ export const projectState = function (state=initialState, action) { state.project.scopeChangeRequests, action.payload ) - const updatedDetails = _.merge({}, state.project.details, _.cloneDeep(action.payload.newScope)) + const updatedDetails = _.mergeWith( + {}, + state.project.details, + _.cloneDeep(action.payload.newScope), + (_objValue, srcValue) => { + if (_.isArray(srcValue)) { + return srcValue + } + } + ) const project = update(state.project, { scopeChangeRequests: { $set: updatedScopeChangeRequests From b746e86f1d03eeeb2193e17c7c9aa93936a14a0b Mon Sep 17 00:00:00 2001 From: Vigneshkumar Chinnachamy M Date: Fri, 2 Aug 2019 13:24:19 +0530 Subject: [PATCH 4/4] update logic for deducing value label in scope change request --- .../ScopeChangeRequest/ScopeChangeRequest.jsx | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/projects/detail/components/ScopeChangeRequest/ScopeChangeRequest.jsx b/src/projects/detail/components/ScopeChangeRequest/ScopeChangeRequest.jsx index 580d396a0..f795d8ef3 100644 --- a/src/projects/detail/components/ScopeChangeRequest/ScopeChangeRequest.jsx +++ b/src/projects/detail/components/ScopeChangeRequest/ScopeChangeRequest.jsx @@ -64,20 +64,9 @@ class ScopeChangeRequest extends React.Component { deduceValueLabel(template, invertedScopeFieldPaths, fieldkey, value) { const key = invertedScopeFieldPaths[`details.${fieldkey}`].replace(/\.fieldName$/, '') const fieldDescriptionObject = _.get(template, key) - const fieldType = fieldDescriptionObject.type - - const questionTypesWithOptions = [ - 'radio-group', - 'tiled-radio-group', - 'see-attached-tiled-radio-group', - 'checkbox-group', - 'tiled-checkbox-group', - 'select-dropdown', - 'slide-radiogroup' - ] // We can deduce the label only for predefined values. Otherwise, fall back to actual value entered. - if (_.includes(questionTypesWithOptions, fieldType) && fieldDescriptionObject.options) { + if (fieldDescriptionObject.options) { const valueLabelMap = _.keyBy(fieldDescriptionObject.options, o => o.value) const getLabel = option => option.label || option.title