@@ -8,6 +8,36 @@ import FeaturePicker from './FeatureSelector/FeaturePicker'
88import { Formsy , Icons } from 'appirio-tech-react-components'
99
1010import SpecSection from './SpecSection'
11+ import { HOC as hoc } from 'formsy-react'
12+
13+ const FeaturePickerModal = ( { project, isEdittable, showFeaturesDialog, hideFeaturesDialog, saveFeatures, setValue } ) => {
14+ const setFormValue = ( features , featureSeeAttached = false ) => {
15+ const featureObj = {
16+ value : features ,
17+ seeAttached : featureSeeAttached
18+ }
19+ setValue ( featureObj )
20+ saveFeatures ( features , featureSeeAttached )
21+ }
22+ return (
23+ < Modal
24+ isOpen = { showFeaturesDialog }
25+ className = "feature-selection-dialog"
26+ overlayClassName = "feature-selection-dialog-overlay"
27+ onRequestClose = { hideFeaturesDialog }
28+ >
29+ < FeaturePicker
30+ features = { _ . get ( project , 'details.appDefinition.features.value' , [ ] ) }
31+ isEdittable = { isEdittable } onSave = { setFormValue }
32+ />
33+ < div onClick = { hideFeaturesDialog } className = "feature-selection-dialog-close" >
34+ Save and close < Icons . XMarkIcon />
35+ </ div >
36+ </ Modal >
37+ )
38+ }
39+
40+ const FeaturePickerFormField = hoc ( FeaturePickerModal )
1141
1242class EditProjectForm extends Component {
1343
@@ -135,10 +165,9 @@ class EditProjectForm extends Component {
135165 }
136166
137167 submit ( model ) {
138- console . log ( 'submit' , this . isChanged ( ) )
139- if ( this . state . isFeaturesDirty ) {
140- model . details . appDefinition . features = this . state . project . details . appDefinition . features
141- }
168+ // if (this.state.isFeaturesDirty) {
169+ // model.details.appDefinition.features = this.state.project.details.appDefinition.features
170+ // }
142171 this . setState ( { isSaving : true } )
143172 this . props . submitHandler ( model )
144173 }
@@ -192,21 +221,17 @@ class EditProjectForm extends Component {
192221 onChange = { this . handleChange }
193222 >
194223 { sections . map ( renderSection ) }
195- </ Formsy . Form >
196- < Modal
197- isOpen = { this . state . showFeaturesDialog }
198- className = "feature-selection-dialog"
199- overlayClassName = "feature-selection-dialog-overlay"
200- onRequestClose = { this . hideFeaturesDialog }
201- >
202- < FeaturePicker
203- features = { _ . get ( project , 'details.appDefinition.features.value' , [ ] ) }
204- isEdittable = { isEdittable } onSave = { this . saveFeatures }
224+ < FeaturePickerFormField
225+ name = 'details.appDefinition.features'
226+ project = { project }
227+ isEdittable = { isEdittable }
228+ showFeaturesDialog = { this . state . showFeaturesDialog }
229+ hideFeaturesDialog = { this . hideFeaturesDialog }
230+ saveFeatures = { this . saveFeatures }
231+ value = { _ . get ( project , 'details.appDefinition.features' , { } ) }
205232 />
206- < div onClick = { this . hideFeaturesDialog } className = "feature-selection-dialog-close" >
207- Save and close < Icons . XMarkIcon />
208- </ div >
209- </ Modal >
233+ </ Formsy . Form >
234+
210235 </ div >
211236 )
212237 }
0 commit comments