Update app state when parameters get updated
This change updates the application state with new parameter values when they are successfully set in mistral environment Closes-Bug: 1642216 Change-Id: Iebd52ccb216835497da01eb3fd5a093dd02dc3c0
This commit is contained in:
parent
ada4af3c25
commit
efbdd2683b
|
@ -158,7 +158,7 @@ describe('ParametersActions', () => {
|
|||
});
|
||||
|
||||
it('does not dispatch updateParametersSuccess', () => {
|
||||
expect(ParametersActions.updateParametersSuccess).not.toHaveBeenCalled();
|
||||
expect(ParametersActions.updateParametersSuccess).not.toHaveBeenCalledWith({ foo: 'bar' });
|
||||
});
|
||||
|
||||
it('dispatches updateParametersFailed', () => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import matchers from 'jasmine-immutable-matchers';
|
||||
import { List, Map } from 'immutable';
|
||||
|
||||
import { ParametersDefaultState } from '../../js/immutableRecords/parameters';
|
||||
import { ParametersDefaultState, Parameter } from '../../js/immutableRecords/parameters';
|
||||
import ParametersConstants from '../../js/constants/ParametersConstants';
|
||||
import parametersReducer from '../../js/reducers/parametersReducer';
|
||||
|
||||
|
@ -162,13 +162,19 @@ describe('parametersReducer', () => {
|
|||
describe('UPDATE_PARAMETERS_SUCCESS', () => {
|
||||
let state;
|
||||
const action = {
|
||||
type: ParametersConstants.UPDATE_PARAMETERS_SUCCESS
|
||||
type: ParametersConstants.UPDATE_PARAMETERS_SUCCESS,
|
||||
payload: { foo: 'bar' }
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
state = parametersReducer(ParametersDefaultState({
|
||||
isFetching: true,
|
||||
form: Map({ some: 'value' })
|
||||
form: Map({ some: 'value' }),
|
||||
parameters: Map({
|
||||
foo: new Parameter({
|
||||
name: 'foo'
|
||||
})
|
||||
})
|
||||
}), action);
|
||||
});
|
||||
|
||||
|
@ -182,5 +188,9 @@ describe('parametersReducer', () => {
|
|||
formFieldErrors: Map()
|
||||
}));
|
||||
});
|
||||
|
||||
it('updates parameters in state with new values', () => {
|
||||
expect(state.parameters.get('foo').default).toEqual('bar');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -58,9 +58,10 @@ export default {
|
|||
};
|
||||
},
|
||||
|
||||
updateParametersSuccess() {
|
||||
updateParametersSuccess(updatedParameters) {
|
||||
return {
|
||||
type: ParametersConstants.UPDATE_PARAMETERS_SUCCESS
|
||||
type: ParametersConstants.UPDATE_PARAMETERS_SUCCESS,
|
||||
payload: updatedParameters
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -80,7 +81,7 @@ export default {
|
|||
MistralApiService.runAction(MistralConstants.PARAMETERS_UPDATE,
|
||||
{ container: planName, parameters: data })
|
||||
.then(response => {
|
||||
dispatch(this.updateParametersSuccess());
|
||||
dispatch(this.updateParametersSuccess(data));
|
||||
dispatch(NotificationActions.notify({
|
||||
title: 'Parameters updated',
|
||||
message: 'The Deployment parameters have been successfully updated',
|
||||
|
|
|
@ -41,13 +41,20 @@ export default function parametersReducer(state = initialState, action) {
|
|||
case ParametersConstants.UPDATE_PARAMETERS_PENDING:
|
||||
return state.set('isFetching', true);
|
||||
|
||||
case ParametersConstants.UPDATE_PARAMETERS_SUCCESS:
|
||||
case ParametersConstants.UPDATE_PARAMETERS_SUCCESS: {
|
||||
const updatedParameters = action.payload;
|
||||
return state
|
||||
.set('isFetching', false)
|
||||
.set('form', Map({
|
||||
formErrors: List(),
|
||||
formFieldErrors: Map()
|
||||
}));
|
||||
}))
|
||||
.update('parameters', parameters =>
|
||||
parameters.map(parameter =>
|
||||
Object.keys(updatedParameters).includes(parameter.name) ?
|
||||
parameter.set('default', updatedParameters[parameter.name]) :
|
||||
parameter ));
|
||||
}
|
||||
|
||||
case ParametersConstants.UPDATE_PARAMETERS_FAILED:
|
||||
return state
|
||||
|
|
Loading…
Reference in New Issue