@@ -212,8 +212,8 @@ class FeaturePicker extends Component {
212212 }
213213 this . addFeature = this . addFeature . bind ( this )
214214 this . removeFeature = this . removeFeature . bind ( this )
215- this . selectFeature = this . selectFeature . bind ( this )
216215 this . toggleFeature = this . toggleFeature . bind ( this )
216+ this . selectFeature = this . selectFeature . bind ( this )
217217 this . updateSelectedFeature = this . updateSelectedFeature . bind ( this )
218218 this . renderCustomFeatureForm = this . renderCustomFeatureForm . bind ( this )
219219 this . renderDefaultFeatureForm = this . renderDefaultFeatureForm . bind ( this )
@@ -232,11 +232,6 @@ class FeaturePicker extends Component {
232232 } )
233233 }
234234
235- toggleFeature ( featureId ) {
236- const idx = _ . findIndex ( this . state . activeFeatureList , f => f . id === featureId )
237- idx > - 1 ? this . removeFeature ( featureId ) : this . addFeature ( featureId )
238- }
239-
240235 renderCustomFeatureForm ( ) {
241236 this . setState ( {
242237 selectedFeatureId : null ,
@@ -262,27 +257,40 @@ class FeaturePicker extends Component {
262257 this . props . onSave ( newState . activeFeatureList )
263258 }
264259
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 , {
260+ toggleFeature ( featureId , disable ) {
261+ const featureIndex = _ . findIndex ( this . state . activeFeatureList , ( f ) => f . id === featureId )
262+ if ( featureIndex >= 0 ) {
263+ const feature = this . state . activeFeatureList [ featureIndex ]
264+ let featureListQuery
265+ // separate update query for custom and standard features
266+ // when disabling, we remove standard feature from the list while update custom feature with disabled flag
267+ if ( feature . categoryId === 'custom' ) {
268+ feature . disabled = disable
269+ featureListQuery = { $splice : [ [ featureIndex , 1 , feature ] ] }
270+ } else {
271+ featureListQuery = { $splice : [ [ featureIndex , 1 ] ] }
272+ }
273+ const newState = update ( this . state , {
271274 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 ] } ,
275+ activeFeatureList : featureListQuery ,
279276 selectedFeatureId : { $set : feature . id }
280277 } )
278+ this . setState ( newState )
279+ this . props . onSave ( newState . activeFeatureList )
281280 }
281+ }
282+
283+ addFeature ( feature ) {
284+ const newState = update ( this . state , {
285+ activeFeatureCount : { $set : this . state . activeFeatureCount + 1 } ,
286+ activeFeatureList : { $push : [ feature ] } ,
287+ selectedFeatureId : { $set : feature . id }
288+ } )
282289 this . setState ( newState )
283290 this . props . onSave ( newState . activeFeatureList )
284291 }
285292
293+ // removeFeature is only called for custom feature
286294 removeFeature ( featureId ) {
287295 // lookup index
288296 const idx = _ . findIndex ( this . state . activeFeatureList , f => f . id === featureId )
@@ -328,6 +336,7 @@ class FeaturePicker extends Component {
328336 featureDesc = { selectedFeature }
329337 featureData = { selectedFeatureData }
330338 updateFeature = { this . updateSelectedFeature }
339+ toggleFeature = { this . toggleFeature }
331340 addFeature = { this . addFeature }
332341 removeFeature = { this . removeFeature }
333342 /> )
@@ -360,6 +369,7 @@ class FeaturePicker extends Component {
360369 isEdittable = { isEdittable }
361370 featureData = { selectedFeatureData }
362371 updateFeature = { this . updateSelectedFeature }
372+ toggleFeature = { this . toggleFeature }
363373 addFeature = { this . addFeature }
364374 removeFeature = { this . removeFeature }
365375 onCancel = { this . renderDefaultFeatureForm }
0 commit comments