@@ -212,6 +212,7 @@ class FeaturePicker extends Component {
212212 }
213213 this . addFeature = this . addFeature . bind ( this )
214214 this . removeFeature = this . removeFeature . bind ( this )
215+ this . toggleFeature = this . toggleFeature . bind ( this )
215216 this . selectFeature = this . selectFeature . bind ( this )
216217 this . toggleFeature = this . toggleFeature . bind ( this )
217218 this . updateSelectedFeature = this . updateSelectedFeature . bind ( this )
@@ -262,27 +263,40 @@ class FeaturePicker extends Component {
262263 this . props . onSave ( newState . activeFeatureList )
263264 }
264265
265- addFeature ( feature ) {
266- let newState
267- const featureIndex = _ . findIndex ( this . state . activeFeatureList , ( f ) => f . id === feature . id )
268- // if feature is already added and is custom feature, update feature
269- if ( feature . categoryId === 'custom' && featureIndex >= 0 ) {
270- newState = update ( this . state , {
266+ toggleFeature ( featureId , disable ) {
267+ const featureIndex = _ . findIndex ( this . state . activeFeatureList , ( f ) => f . id === featureId )
268+ if ( featureIndex >= 0 ) {
269+ const feature = this . state . activeFeatureList [ featureIndex ]
270+ let featureListQuery
271+ // separate update query for custom and standard features
272+ // when disabling, we remove standard feature from the list while update custom feature with disabled flag
273+ if ( feature . categoryId === 'custom' ) {
274+ feature . disabled = disable
275+ featureListQuery = { $splice : [ [ featureIndex , 1 , feature ] ] }
276+ } else {
277+ featureListQuery = { $splice : [ [ featureIndex , 1 ] ] }
278+ }
279+ const newState = update ( this . state , {
271280 activeFeatureCount : { $set : this . state . activeFeatureCount - 1 } ,
272- activeFeatureList : { $splice : [ [ featureIndex , 1 , feature ] ] } ,
273- selectedFeatureId : { $set : feature . id }
274- } )
275- } else { // add standard feature
276- newState = update ( this . state , {
277- activeFeatureCount : { $set : this . state . activeFeatureCount + 1 } ,
278- activeFeatureList : { $push : [ feature ] } ,
281+ activeFeatureList : featureListQuery ,
279282 selectedFeatureId : { $set : feature . id }
280283 } )
284+ this . setState ( newState )
285+ this . props . onSave ( newState . activeFeatureList )
281286 }
287+ }
288+
289+ addFeature ( feature ) {
290+ const newState = update ( this . state , {
291+ activeFeatureCount : { $set : this . state . activeFeatureCount + 1 } ,
292+ activeFeatureList : { $push : [ feature ] } ,
293+ selectedFeatureId : { $set : feature . id }
294+ } )
282295 this . setState ( newState )
283296 this . props . onSave ( newState . activeFeatureList )
284297 }
285298
299+ // removeFeature is only called for custom feature
286300 removeFeature ( featureId ) {
287301 // lookup index
288302 const idx = _ . findIndex ( this . state . activeFeatureList , f => f . id === featureId )
@@ -328,6 +342,7 @@ class FeaturePicker extends Component {
328342 featureDesc = { selectedFeature }
329343 featureData = { selectedFeatureData }
330344 updateFeature = { this . updateSelectedFeature }
345+ toggleFeature = { this . toggleFeature }
331346 addFeature = { this . addFeature }
332347 removeFeature = { this . removeFeature }
333348 /> )
@@ -360,6 +375,7 @@ class FeaturePicker extends Component {
360375 isEdittable = { isEdittable }
361376 featureData = { selectedFeatureData }
362377 updateFeature = { this . updateSelectedFeature }
378+ toggleFeature = { this . toggleFeature }
363379 addFeature = { this . addFeature }
364380 removeFeature = { this . removeFeature }
365381 onCancel = { this . renderDefaultFeatureForm }
0 commit comments