Skip to content

Commit e6ac6dc

Browse files
author
vikasrohit
committed
Github issue #448 Dashboard/Feature picker: Deselecting feature moves user out of feature view
-- Fixed with restructuring the addFeature method
1 parent 28e182b commit e6ac6dc

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/projects/detail/components/FeatureSelector/CustomFeatureForm.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class CustomFeatureForm extends Component {
3535
}
3636

3737
toggleFeature() {
38-
const { addFeature, isEdittable } = this.props
38+
const { toggleFeature, isEdittable } = this.props
3939
if (isEdittable) {
40-
addFeature({ ...this.state.data, disabled: !!this.state.isActive })
40+
toggleFeature(this.state.data.id, !!this.state.isActive)
4141
}
4242
}
4343

src/projects/detail/components/FeatureSelector/DefaultFeatureForm.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class DefaultFeatureForm extends Component {
3232
}
3333

3434
toggleFeature() {
35-
const { removeFeature, addFeature, featureDesc, isEdittable } = this.props
35+
const { toggleFeature, addFeature, featureDesc, isEdittable } = this.props
3636
if (isEdittable) {
3737
if (this.state.isActive) {
3838
// remove feature
39-
removeFeature(featureDesc.id)
39+
toggleFeature(featureDesc.id, true)
4040
} else {
4141
// add feature
4242
addFeature({

src/projects/detail/components/FeatureSelector/FeaturePicker.jsx

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)