1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

fix: Use toggle/on/off endoints to ensure correct state

This commit is contained in:
ivaosthu 2019-03-07 22:30:45 +01:00
parent 9b3fb06268
commit 2d8b287848
4 changed files with 9 additions and 8 deletions

View File

@ -48,7 +48,7 @@ const Feature = ({
disabled={toggleFeature === undefined} disabled={toggleFeature === undefined}
title={`Toggle ${name}`} title={`Toggle ${name}`}
key="left-actions" key="left-actions"
onChange={() => toggleFeature(name)} onChange={() => toggleFeature(!enabled, name)}
checked={enabled} checked={enabled}
/> />
) : ( ) : (

View File

@ -211,7 +211,7 @@ export default class ViewFeatureToggleComponent extends React.Component {
disabled={!this.isFeatureView} disabled={!this.isFeatureView}
ripple ripple
checked={featureToggle.enabled} checked={featureToggle.enabled}
onChange={() => toggleFeature(featureToggle.name)} onChange={() => toggleFeature(!featureToggle.enabled, featureToggle.name)}
> >
{featureToggle.enabled ? 'Enabled' : 'Disabled'} {featureToggle.enabled ? 'Enabled' : 'Disabled'}
</Switch> </Switch>

View File

@ -53,8 +53,9 @@ function update(featureToggle) {
.then(throwIfNotSuccess); .then(throwIfNotSuccess);
} }
function toggle(name) { function toggle(enable, name) {
return fetch(`${URI}/${name}/toggle`, { const action = enable ? 'on' : 'off';
return fetch(`${URI}/${name}/toggle/${action}`, {
method: 'POST', method: 'POST',
headers, headers,
credentials: 'include', credentials: 'include',

View File

@ -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 ERROR_REMOVE_FEATURE_TOGGLE = 'ERROR_REMOVE_FEATURE_TOGGLE';
export const UPDATE_FEATURE_TOGGLE_STRATEGIES = 'UPDATE_FEATURE_TOGGLE_STRATEGIES'; export const UPDATE_FEATURE_TOGGLE_STRATEGIES = 'UPDATE_FEATURE_TOGGLE_STRATEGIES';
export function toggleFeature(name) { export function toggleFeature(enable, name) {
debug('Toggle feature toggle ', name); debug('Toggle feature toggle ', name);
return dispatch => { 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 => { return dispatch => {
dispatch({ type: START_UPDATE_FEATURE_TOGGLE }); dispatch({ type: START_UPDATE_FEATURE_TOGGLE });
return api return api
.toggle(name) .toggle(enable, name)
.then(() => dispatch({ type: TOGGLE_FEATURE_TOGGLE, name })) .then(() => dispatch({ type: TOGGLE_FEATURE_TOGGLE, name }))
.catch(dispatchAndThrow(dispatch, ERROR_UPDATE_FEATURE_TOGGLE)); .catch(dispatchAndThrow(dispatch, ERROR_UPDATE_FEATURE_TOGGLE));
}; };