mirror of
https://github.com/Unleash/unleash.git
synced 2025-03-18 00:19:49 +01:00
Merge pull request #142 from Unleash/update∕not_change_route
feat(update-toggle): Do not change route after feature toggle update
This commit is contained in:
commit
d8f7d2097d
frontend/src
component
store
@ -7,7 +7,10 @@ const mapDispatchToProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
errors: state.error.get('list').toArray(),
|
errors: state.error
|
||||||
|
.get('list')
|
||||||
|
.toArray()
|
||||||
|
.reverse(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(ErrorComponent);
|
export default connect(mapStateToProps, mapDispatchToProps)(ErrorComponent);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { requestUpdateFeatureToggle } from '../../../store/feature-actions';
|
import { requestUpdateFeatureToggleStrategies } from '../../../store/feature-actions';
|
||||||
import { createMapper, createActions } from '../../input-helpers';
|
import { createMapper, createActions } from '../../input-helpers';
|
||||||
import UpdateFeatureToggleComponent from './form-update-feature-component';
|
import UpdateFeatureToggleComponent from './form-update-feature-component';
|
||||||
|
|
||||||
@ -28,20 +28,14 @@ const prepare = (methods, dispatch, ownProps) => {
|
|||||||
methods.onSubmit = (input, features) => e => {
|
methods.onSubmit = (input, features) => e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (Array.isArray(input.strategies)) {
|
// This view will only update strategies!
|
||||||
input.strategies.forEach(s => {
|
const featureToggle = features.find(f => f.name === input.name);
|
||||||
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;
|
|
||||||
|
|
||||||
// TODO: should add error handling
|
const updatedStrategies = JSON.parse(
|
||||||
requestUpdateFeatureToggle(input)(dispatch)
|
JSON.stringify(input.strategies, (key, value) => (key === 'id' ? undefined : value))
|
||||||
.then(() => methods.clear())
|
);
|
||||||
.then(() => ownProps.history.push(`/features`));
|
|
||||||
|
requestUpdateFeatureToggleStrategies(featureToggle, updatedStrategies)(dispatch);
|
||||||
};
|
};
|
||||||
|
|
||||||
methods.onCancel = evt => {
|
methods.onCancel = evt => {
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
ERROR_CREATING_FEATURE_TOGGLE,
|
ERROR_CREATING_FEATURE_TOGGLE,
|
||||||
ERROR_REMOVE_FEATURE_TOGGLE,
|
ERROR_REMOVE_FEATURE_TOGGLE,
|
||||||
ERROR_UPDATE_FEATURE_TOGGLE,
|
ERROR_UPDATE_FEATURE_TOGGLE,
|
||||||
|
UPDATE_FEATURE_TOGGLE_STRATEGIES,
|
||||||
} from './feature-actions';
|
} from './feature-actions';
|
||||||
|
|
||||||
import { ERROR_UPDATING_STRATEGY, ERROR_CREATING_STRATEGY, ERROR_RECEIVE_STRATEGIES } from './strategy/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');
|
return addErrorIfNotAlreadyInList(state, action.error.message || '403 Forbidden');
|
||||||
case MUTE_ERROR:
|
case MUTE_ERROR:
|
||||||
return state.update('list', list => list.remove(list.indexOf(action.error)));
|
return state.update('list', list => list.remove(list.indexOf(action.error)));
|
||||||
|
case UPDATE_FEATURE_TOGGLE_STRATEGIES:
|
||||||
|
return addErrorIfNotAlreadyInList(state, action.info);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import api from '../data/feature-api';
|
import api from '../data/feature-api';
|
||||||
const debug = require('debug')('unleash:feature-actions');
|
const debug = require('debug')('unleash:feature-actions');
|
||||||
import { dispatchAndThrow } from './util';
|
import { dispatchAndThrow } from './util';
|
||||||
|
import { MUTE_ERROR } from './error-actions';
|
||||||
|
|
||||||
export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE';
|
export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE';
|
||||||
export const REMOVE_FEATURE_TOGGLE = 'REMOVE_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_CREATING_FEATURE_TOGGLE = 'ERROR_CREATING_FEATURE_TOGGLE';
|
||||||
export const ERROR_UPDATE_FEATURE_TOGGLE = 'ERROR_UPDATE_FEATURE_TOGGLE';
|
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 function toggleFeature(name) {
|
export function toggleFeature(name) {
|
||||||
debug('Toggle feature toggle ', 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) {
|
export function removeFeatureToggle(featureToggleName) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({ type: START_REMOVE_FEATURE_TOGGLE });
|
dispatch({ type: START_REMOVE_FEATURE_TOGGLE });
|
||||||
|
Loading…
Reference in New Issue
Block a user