mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Merge pull request #169 from Unleash/fix/toggle_on_off
fix: Use toggle/on/off endoints to ensure correct state
This commit is contained in:
commit
6e4bb8772b
@ -48,7 +48,7 @@ const Feature = ({
|
||||
disabled={toggleFeature === undefined}
|
||||
title={`Toggle ${name}`}
|
||||
key="left-actions"
|
||||
onChange={() => toggleFeature(name)}
|
||||
onChange={() => toggleFeature(!enabled, name)}
|
||||
checked={enabled}
|
||||
/>
|
||||
) : (
|
||||
|
@ -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'}
|
||||
</Switch>
|
||||
|
@ -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',
|
||||
|
@ -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));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user