From 993222a74995382b95ccbed420831e232b4945db Mon Sep 17 00:00:00 2001 From: Ivar Date: Wed, 16 Nov 2016 21:20:41 +0100 Subject: [PATCH] Fix input-store list bug. Because we convert items from Immutable Object to js we can not just look up items in a list property via the object itself, as it is not the same. The easy fix is to just use the index of the item in the list, as we already know it anyway. closes #5 --- .../src/component/feature/form-add-container.jsx | 8 ++++---- .../src/component/feature/form-edit-container.jsx | 8 ++++---- .../src/component/feature/form/strategies-list.jsx | 4 ++-- .../component/feature/form/strategy-configure.jsx | 12 ++---------- frontend/src/component/feature/list-component.jsx | 2 +- frontend/src/component/input-helpers.js | 8 ++++---- frontend/src/page/features/create.js | 2 +- frontend/src/page/features/edit.js | 2 +- frontend/src/store/input-actions.js | 4 ++-- frontend/src/store/input-store.js | 8 ++++---- 10 files changed, 25 insertions(+), 33 deletions(-) diff --git a/frontend/src/component/feature/form-add-container.jsx b/frontend/src/component/feature/form-add-container.jsx index 8a2ab56105..0b06529079 100644 --- a/frontend/src/component/feature/form-add-container.jsx +++ b/frontend/src/component/feature/form-add-container.jsx @@ -25,12 +25,12 @@ const prepare = (methods, dispatch) => { methods.pushToList('strategies', v); }; - methods.updateStrategy = (v, n) => { - methods.updateInList('strategies', v, n); + methods.updateStrategy = (index, n) => { + methods.updateInList('strategies', index, n); }; - methods.removeStrategy = (v) => { - methods.removeFromList('strategies', v); + methods.removeStrategy = (index) => { + methods.removeFromList('strategies', index); }; methods.validateName = (v) => { diff --git a/frontend/src/component/feature/form-edit-container.jsx b/frontend/src/component/feature/form-edit-container.jsx index 0c0b71e7cf..e88aa4341d 100644 --- a/frontend/src/component/feature/form-edit-container.jsx +++ b/frontend/src/component/feature/form-edit-container.jsx @@ -40,12 +40,12 @@ const prepare = (methods, dispatch) => { methods.pushToList('strategies', v); }; - methods.removeStrategy = (v) => { - methods.removeFromList('strategies', v); + methods.removeStrategy = (index) => { + methods.removeFromList('strategies', index); }; - methods.updateStrategy = (v, n) => { - methods.updateInList('strategies', v, n); + methods.updateStrategy = (index, n) => { + methods.updateInList('strategies', index, n); }; methods.validateName = () => {}; diff --git a/frontend/src/component/feature/form/strategies-list.jsx b/frontend/src/component/feature/form/strategies-list.jsx index 10337c164d..5357f878f6 100644 --- a/frontend/src/component/feature/form/strategies-list.jsx +++ b/frontend/src/component/feature/form/strategies-list.jsx @@ -26,8 +26,8 @@ class StrategiesList extends React.Component { s.name === strat.name)} /> )); return ( diff --git a/frontend/src/component/feature/form/strategy-configure.jsx b/frontend/src/component/feature/form/strategy-configure.jsx index b2f09337a3..db9c670506 100644 --- a/frontend/src/component/feature/form/strategy-configure.jsx +++ b/frontend/src/component/feature/form/strategy-configure.jsx @@ -13,26 +13,18 @@ class StrategyConfigure extends React.Component { }; } - updateStrategy = (evt) => { - evt.preventDefault(); - this.props.updateStrategy({ - name: this.state.selectedStrategy.name, - parameters: this.state.parameters, - }); - }; - handleConfigChange = (key, value) => { const parameters = this.props.strategy.parameters || {}; parameters[key] = value; const updatedStrategy = Object.assign({}, this.props.strategy, { parameters }); - this.props.updateStrategy(this.props.strategy, updatedStrategy); + this.props.updateStrategy(updatedStrategy); }; handleRemove = (evt) => { evt.preventDefault(); - this.props.removeStrategy(this.props.strategy); + this.props.removeStrategy(); } renderInputFields (strategyDefinition) { diff --git a/frontend/src/component/feature/list-component.jsx b/frontend/src/component/feature/list-component.jsx index 34c065b273..2de43097cf 100644 --- a/frontend/src/component/feature/list-component.jsx +++ b/frontend/src/component/feature/list-component.jsx @@ -48,7 +48,7 @@ export default class FeatureListComponent extends React.Component { )} - + ); diff --git a/frontend/src/component/input-helpers.js b/frontend/src/component/input-helpers.js index afcb2e7c95..8afefcec4e 100644 --- a/frontend/src/component/input-helpers.js +++ b/frontend/src/component/input-helpers.js @@ -53,12 +53,12 @@ export function createActions ({ id, prepare = (v) => v }) { dispatch(createPush({ id: getId(id, ownProps), key, value })); }, - removeFromList (key, value) { - dispatch(createPop({ id: getId(id, ownProps), key, value })); + removeFromList (key, index) { + dispatch(createPop({ id: getId(id, ownProps), key, index })); }, - updateInList (key, value, newValue) { - dispatch(createUp({ id: getId(id, ownProps), key, value, newValue })); + updateInList (key, index, newValue) { + dispatch(createUp({ id: getId(id, ownProps), key, index, newValue })); }, incValue (key) { diff --git a/frontend/src/page/features/create.js b/frontend/src/page/features/create.js index ff9afd5e6f..784c9f6dbe 100644 --- a/frontend/src/page/features/create.js +++ b/frontend/src/page/features/create.js @@ -3,7 +3,7 @@ import AddFeatureToggleForm from '../../component/feature/form-add-container'; const render = () => (
-

Create feature toggle

+
Create feature toggle
); diff --git a/frontend/src/page/features/edit.js b/frontend/src/page/features/edit.js index b1626986cd..8cba022d9b 100644 --- a/frontend/src/page/features/edit.js +++ b/frontend/src/page/features/edit.js @@ -11,7 +11,7 @@ export default class Features extends Component { render () { return (
-

Edit feature toggle

+
Edit feature toggle
); diff --git a/frontend/src/store/input-actions.js b/frontend/src/store/input-actions.js index f94fe5a09f..b664bb1b98 100644 --- a/frontend/src/store/input-actions.js +++ b/frontend/src/store/input-actions.js @@ -12,8 +12,8 @@ export const createInit = ({ id, value }) => ({ type: actions.INIT, id, value }) export const createInc = ({ id, key }) => ({ type: actions.INCREMENT_VALUE, id, key }); export const createSet = ({ id, key, value }) => ({ type: actions.SET_VALUE, id, key, value }); export const createPush = ({ id, key, value }) => ({ type: actions.LIST_PUSH, id, key, value }); -export const createPop = ({ id, key, value }) => ({ type: actions.LIST_POP, id, key, value }); -export const createUp = ({ id, key, value, newValue }) => ({ type: actions.LIST_UP, id, key, value, newValue }); +export const createPop = ({ id, key, index }) => ({ type: actions.LIST_POP, id, key, index }); +export const createUp = ({ id, key, index, newValue }) => ({ type: actions.LIST_UP, id, key, index, newValue }); export const createClear = ({ id }) => ({ type: actions.CLEAR, id }); export default actions; diff --git a/frontend/src/store/input-store.js b/frontend/src/store/input-store.js index 3379123398..70de30ccf4 100644 --- a/frontend/src/store/input-store.js +++ b/frontend/src/store/input-store.js @@ -48,18 +48,18 @@ function addToList (state, { id, key, value }) { return state.updateIn(id.concat([key]), (list) => list.push(value)); } -function updateInList (state, { id, key, value, newValue }) { +function updateInList (state, { id, key, index, newValue }) { state = assertId(state, id); state = assertList(state, id, key); - return state.updateIn(id.concat([key]), (list) => list.set(list.indexOf(value), newValue)); + return state.updateIn(id.concat([key]), (list) => list.set(index, newValue)); } -function removeFromList (state, { id, key, value }) { +function removeFromList (state, { id, key, index }) { state = assertId(state, id); state = assertList(state, id, key); - return state.updateIn(id.concat([key]), (list) => list.remove(list.indexOf(value))); + return state.updateIn(id.concat([key]), (list) => list.remove(index)); } const inputState = (state = getInitState(), action) => {