From 2d8b28784830bbb441aeceae20d0cce83d3a7d44 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Thu, 7 Mar 2019 22:30:45 +0100 Subject: [PATCH] fix: Use toggle/on/off endoints to ensure correct state --- .../src/component/feature/feature-list-item-component.jsx | 2 +- frontend/src/component/feature/view-component.jsx | 2 +- frontend/src/data/feature-api.js | 5 +++-- frontend/src/store/feature-actions.js | 8 ++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/frontend/src/component/feature/feature-list-item-component.jsx b/frontend/src/component/feature/feature-list-item-component.jsx index 41bb2cf11e..e19ab683b6 100644 --- a/frontend/src/component/feature/feature-list-item-component.jsx +++ b/frontend/src/component/feature/feature-list-item-component.jsx @@ -48,7 +48,7 @@ const Feature = ({ disabled={toggleFeature === undefined} title={`Toggle ${name}`} key="left-actions" - onChange={() => toggleFeature(name)} + onChange={() => toggleFeature(!enabled, name)} checked={enabled} /> ) : ( diff --git a/frontend/src/component/feature/view-component.jsx b/frontend/src/component/feature/view-component.jsx index d189f416df..22d4300e19 100644 --- a/frontend/src/component/feature/view-component.jsx +++ b/frontend/src/component/feature/view-component.jsx @@ -211,7 +211,7 @@ export default class ViewFeatureToggleComponent extends React.Component { disabled={!this.isFeatureView} ripple checked={featureToggle.enabled} - onChange={() => toggleFeature(featureToggle.name)} + onChange={() => toggleFeature(!featureToggle.enabled, featureToggle.name)} > {featureToggle.enabled ? 'Enabled' : 'Disabled'} diff --git a/frontend/src/data/feature-api.js b/frontend/src/data/feature-api.js index 0ceba9e50a..d1dd5e475a 100644 --- a/frontend/src/data/feature-api.js +++ b/frontend/src/data/feature-api.js @@ -53,8 +53,9 @@ function update(featureToggle) { .then(throwIfNotSuccess); } -function toggle(name) { - return fetch(`${URI}/${name}/toggle`, { +function toggle(enable, name) { + const action = enable ? 'on' : 'off'; + return fetch(`${URI}/${name}/toggle/${action}`, { method: 'POST', headers, credentials: 'include', diff --git a/frontend/src/store/feature-actions.js b/frontend/src/store/feature-actions.js index 69fc6b9b62..c1b49c1079 100644 --- a/frontend/src/store/feature-actions.js +++ b/frontend/src/store/feature-actions.js @@ -18,10 +18,10 @@ export const ERROR_UPDATE_FEATURE_TOGGLE = 'ERROR_UPDATE_FEATURE_TOGGLE'; export const ERROR_REMOVE_FEATURE_TOGGLE = 'ERROR_REMOVE_FEATURE_TOGGLE'; export const UPDATE_FEATURE_TOGGLE_STRATEGIES = 'UPDATE_FEATURE_TOGGLE_STRATEGIES'; -export function toggleFeature(name) { +export function toggleFeature(enable, name) { debug('Toggle feature toggle ', name); return dispatch => { - dispatch(requestToggleFeatureToggle(name)); + dispatch(requestToggleFeatureToggle(enable, name)); }; } @@ -64,12 +64,12 @@ export function createFeatureToggles(featureToggle) { }; } -export function requestToggleFeatureToggle(name) { +export function requestToggleFeatureToggle(enable, name) { return dispatch => { dispatch({ type: START_UPDATE_FEATURE_TOGGLE }); return api - .toggle(name) + .toggle(enable, name) .then(() => dispatch({ type: TOGGLE_FEATURE_TOGGLE, name })) .catch(dispatchAndThrow(dispatch, ERROR_UPDATE_FEATURE_TOGGLE)); };