1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

feat(update-toggle): Do not change route after feature toggle update

This commit is contained in:
ivaosthu 2018-08-15 18:51:34 +02:00
parent 9338635337
commit d904690473
4 changed files with 33 additions and 15 deletions

View File

@ -7,7 +7,10 @@ const mapDispatchToProps = {
};
const mapStateToProps = state => ({
errors: state.error.get('list').toArray(),
errors: state.error
.get('list')
.toArray()
.reverse(),
});
export default connect(mapStateToProps, mapDispatchToProps)(ErrorComponent);

View File

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import { requestUpdateFeatureToggle } from '../../../store/feature-actions';
import { requestUpdateFeatureToggleStrategies } from '../../../store/feature-actions';
import { createMapper, createActions } from '../../input-helpers';
import UpdateFeatureToggleComponent from './form-update-feature-component';
@ -28,20 +28,14 @@ const prepare = (methods, dispatch, ownProps) => {
methods.onSubmit = (input, features) => e => {
e.preventDefault();
if (Array.isArray(input.strategies)) {
input.strategies.forEach(s => {
delete s.id;
});
}
delete input.description;
// take the status of the feature toggles from the central store in case `toggleFeature` function was called
const feat = features.find(f => f.name === input.name);
input.enabled = feat.enabled;
// This view will only update strategies!
const featureToggle = features.find(f => f.name === input.name);
// TODO: should add error handling
requestUpdateFeatureToggle(input)(dispatch)
.then(() => methods.clear())
.then(() => ownProps.history.push(`/features`));
const updatedStrategies = JSON.parse(
JSON.stringify(input.strategies, (key, value) => (key === 'id' ? undefined : value))
);
requestUpdateFeatureToggleStrategies(featureToggle, updatedStrategies)(dispatch);
};
methods.onCancel = evt => {

View File

@ -5,6 +5,7 @@ import {
ERROR_CREATING_FEATURE_TOGGLE,
ERROR_REMOVE_FEATURE_TOGGLE,
ERROR_UPDATE_FEATURE_TOGGLE,
UPDATE_FEATURE_TOGGLE_STRATEGIES,
} from './feature-actions';
import { ERROR_UPDATING_STRATEGY, ERROR_CREATING_STRATEGY, ERROR_RECEIVE_STRATEGIES } from './strategy/actions';
@ -41,6 +42,8 @@ const strategies = (state = getInitState(), action) => {
return addErrorIfNotAlreadyInList(state, action.error.message || '403 Forbidden');
case MUTE_ERROR:
return state.update('list', list => list.remove(list.indexOf(action.error)));
case UPDATE_FEATURE_TOGGLE_STRATEGIES:
return addErrorIfNotAlreadyInList(state, action.info);
default:
return state;
}

View File

@ -1,6 +1,7 @@
import api from '../data/feature-api';
const debug = require('debug')('unleash:feature-actions');
import { dispatchAndThrow } from './util';
import { MUTE_ERROR } from './error-actions';
export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE';
export const REMOVE_FEATURE_TOGGLE = 'REMOVE_FEATURE_TOGGLE';
@ -15,6 +16,7 @@ export const ERROR_FETCH_FEATURE_TOGGLES = 'ERROR_FETCH_FEATURE_TOGGLES';
export const ERROR_CREATING_FEATURE_TOGGLE = 'ERROR_CREATING_FEATURE_TOGGLE';
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) {
debug('Toggle feature toggle ', name);
@ -84,6 +86,22 @@ export function requestUpdateFeatureToggle(featureToggle) {
};
}
export function requestUpdateFeatureToggleStrategies(featureToggle, newStrategies) {
return dispatch => {
featureToggle.strategies = newStrategies;
dispatch({ type: START_UPDATE_FEATURE_TOGGLE });
return api
.update(featureToggle)
.then(() => {
const info = `${featureToggle.name} successfully updated!`;
setTimeout(() => dispatch({ type: MUTE_ERROR, error: info }), 1000);
return dispatch({ type: UPDATE_FEATURE_TOGGLE_STRATEGIES, featureToggle, info });
})
.catch(dispatchAndThrow(dispatch, ERROR_UPDATE_FEATURE_TOGGLE));
};
}
export function removeFeatureToggle(featureToggleName) {
return dispatch => {
dispatch({ type: START_REMOVE_FEATURE_TOGGLE });