Convert ValidationsActions to named exports

* avoid using 'this' in thunks

Change-Id: Ia3c07b43984e1b7a01c07c524fe9c49d291facc1
This commit is contained in:
Jiri Tomasek 2018-09-10 15:50:33 -06:00
parent f34edf9c62
commit a3dab0a523
8 changed files with 71 additions and 86 deletions

View File

@ -20,7 +20,7 @@ import { InitialPlanState, Plan } from '../../js/immutableRecords/plans';
import { mockStore } from './utils'; import { mockStore } from './utils';
import * as NodesActions from '../../js/actions/NodesActions'; import * as NodesActions from '../../js/actions/NodesActions';
import NotificationActions from '../../js/actions/NotificationActions'; import NotificationActions from '../../js/actions/NotificationActions';
import ValidationsActions from '../../js/actions/ValidationsActions'; import * as ValidationsActions from '../../js/actions/ValidationsActions';
import RegisterNodesActions from '../../js/actions/RegisterNodesActions'; import RegisterNodesActions from '../../js/actions/RegisterNodesActions';
describe('startNodesRegistration Action', () => { describe('startNodesRegistration Action', () => {

View File

@ -15,7 +15,7 @@
*/ */
import MistralApiService from '../../js/services/MistralApiService'; import MistralApiService from '../../js/services/MistralApiService';
import ValidationsActions from '../../js/actions/ValidationsActions'; import * as ValidationsActions from '../../js/actions/ValidationsActions';
import ValidationsConstants from '../../js/constants/ValidationsConstants'; import ValidationsConstants from '../../js/constants/ValidationsConstants';
import * as WorkflowActions from '../../js/actions/WorkflowActions'; import * as WorkflowActions from '../../js/actions/WorkflowActions';
import MistralConstants from '../../js/constants/MistralConstants'; import MistralConstants from '../../js/constants/MistralConstants';

View File

@ -15,7 +15,7 @@
*/ */
import PlansConstants from '../constants/PlansConstants'; import PlansConstants from '../constants/PlansConstants';
import ValidationsActions from '../actions/ValidationsActions'; import { runValidationGroups } from '../actions/ValidationsActions';
import { getPlans, getCurrentPlanName } from '../selectors/plans'; import { getPlans, getCurrentPlanName } from '../selectors/plans';
export default { export default {
@ -29,10 +29,7 @@ export default {
storePlan(newPlanName); storePlan(newPlanName);
dispatch(this.planChosen(newPlanName)); dispatch(this.planChosen(newPlanName));
dispatch( dispatch(
ValidationsActions.runValidationGroups( runValidationGroups(['prep', 'pre-deployment'], newPlanName)
['prep', 'pre-deployment'],
newPlanName
)
); );
} }
} else { } else {

View File

@ -23,7 +23,7 @@ import RegisterNodesConstants from '../constants/RegisterNodesConstants';
import NotificationActions from './NotificationActions'; import NotificationActions from './NotificationActions';
import { addNodes, fetchNodes } from './NodesActions'; import { addNodes, fetchNodes } from './NodesActions';
import { nodeSchema } from '../normalizrSchemas/nodes'; import { nodeSchema } from '../normalizrSchemas/nodes';
import ValidationsActions from './ValidationsActions'; import { runValidationGroups } from './ValidationsActions';
const messages = defineMessages({ const messages = defineMessages({
registrationNotificationTitle: { registrationNotificationTitle: {
@ -68,7 +68,7 @@ export default {
// run pre-introspection validations // run pre-introspection validations
dispatch( dispatch(
ValidationsActions.runValidationGroups( runValidationGroups(
['pre-introspection'], ['pre-introspection'],
getCurrentPlanName(getState()) getCurrentPlanName(getState())
) )

View File

@ -23,72 +23,59 @@ import { validationSchema } from '../normalizrSchemas/validations';
import MistralConstants from '../constants/MistralConstants'; import MistralConstants from '../constants/MistralConstants';
import { startWorkflow } from './WorkflowActions'; import { startWorkflow } from './WorkflowActions';
export default { export const fetchValidations = () => (dispatch, getState) => {
fetchValidations() { dispatch(fetchValidationsPending());
return (dispatch, getState) => { return dispatch(
dispatch(this.fetchValidationsPending()); MistralApiService.runAction(MistralConstants.VALIDATIONS_LIST)
return dispatch( )
MistralApiService.runAction(MistralConstants.VALIDATIONS_LIST) .then(response => {
) const validations =
.then(response => { normalize(response, [validationSchema]).entities.validations || {};
const validations = dispatch(fetchValidationsSuccess(validations));
normalize(response, [validationSchema]).entities.validations || {}; })
dispatch(this.fetchValidationsSuccess(validations)); .catch(error => {
}) dispatch(handleErrors(error, 'Validations could not be loaded'));
.catch(error => { dispatch(fetchValidationsFailed());
dispatch(handleErrors(error, 'Validations could not be loaded')); });
dispatch(this.fetchValidationsFailed());
});
};
},
fetchValidationsPending() {
return {
type: ValidationsConstants.FETCH_VALIDATIONS_PENDING
};
},
fetchValidationsSuccess(validations) {
return {
type: ValidationsConstants.FETCH_VALIDATIONS_SUCCESS,
payload: validations
};
},
fetchValidationsFailed() {
return {
type: ValidationsConstants.FETCH_VALIDATIONS_FAILED
};
},
runValidation(id, currentPlanName) {
return (dispatch, getState) =>
dispatch(
startWorkflow(MistralConstants.VALIDATIONS_RUN, {
validation_name: id,
plan: currentPlanName
})
).catch(error => {
dispatch(handleErrors(error, 'Error running validation'));
});
},
runValidationGroups(groups, currentPlanName) {
return (dispatch, getState) => {
dispatch(
MistralApiService.runWorkflow(MistralConstants.VALIDATIONS_RUN_GROUPS, {
group_names: groups,
plan: currentPlanName
})
).catch(error => {
dispatch(handleErrors(error, 'Validation Group could not be started'));
});
};
},
toggleValidations() {
return {
type: ValidationsConstants.TOGGLE_VALIDATIONS
};
}
}; };
export const fetchValidationsPending = () => ({
type: ValidationsConstants.FETCH_VALIDATIONS_PENDING
});
export const fetchValidationsSuccess = validations => ({
type: ValidationsConstants.FETCH_VALIDATIONS_SUCCESS,
payload: validations
});
export const fetchValidationsFailed = () => ({
type: ValidationsConstants.FETCH_VALIDATIONS_FAILED
});
export const runValidation = (id, currentPlanName) => (dispatch, getState) =>
dispatch(
startWorkflow(MistralConstants.VALIDATIONS_RUN, {
validation_name: id,
plan: currentPlanName
})
).catch(error => {
dispatch(handleErrors(error, 'Error running validation'));
});
export const runValidationGroups = (groups, currentPlanName) => (
dispatch,
getState
) => {
dispatch(
MistralApiService.runWorkflow(MistralConstants.VALIDATIONS_RUN_GROUPS, {
group_names: groups,
plan: currentPlanName
})
).catch(error => {
dispatch(handleErrors(error, 'Validation Group could not be started'));
});
};
export const toggleValidations = () => ({
type: ValidationsConstants.TOGGLE_VALIDATIONS
});

View File

@ -28,7 +28,7 @@ import NavTab from './ui/NavTab';
import I18nDropdown from './i18n/I18nDropdown'; import I18nDropdown from './i18n/I18nDropdown';
import StatusDropdown from './StatusDropdown'; import StatusDropdown from './StatusDropdown';
import UserDropdown from './UserDropdown'; import UserDropdown from './UserDropdown';
import ValidationsActions from '../actions/ValidationsActions'; import { toggleValidations } from '../actions/ValidationsActions';
import ValidationsList from './validations/ValidationsList'; import ValidationsList from './validations/ValidationsList';
import ValidationsToggle from './validations/ValidationsToggle'; import ValidationsToggle from './validations/ValidationsToggle';
@ -165,7 +165,7 @@ const mapStateToProps = state => ({
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
logoutUser: () => dispatch(LoginActions.logoutUser()), logoutUser: () => dispatch(LoginActions.logoutUser()),
toggleValidations: () => dispatch(ValidationsActions.toggleValidations()) toggleValidations: () => dispatch(toggleValidations())
}); });
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(NavBar)); export default withRouter(connect(mapStateToProps, mapDispatchToProps)(NavBar));

View File

@ -36,7 +36,7 @@ import { getEnvironmentConfigurationSummary } from '../../selectors/environmentC
import InlineNotification from '../ui/InlineNotification'; import InlineNotification from '../ui/InlineNotification';
import { InlineLoader } from '../ui/Loader'; import { InlineLoader } from '../ui/Loader';
import { startDeployment } from '../../actions/DeploymentActions'; import { startDeployment } from '../../actions/DeploymentActions';
import ValidationsActions from '../../actions/ValidationsActions'; import { runValidationGroups } from '../../actions/ValidationsActions';
const messages = defineMessages({ const messages = defineMessages({
close: { close: {
@ -168,9 +168,7 @@ const mapStateToProps = (state, props) => ({
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
startDeployment: planName => dispatch(startDeployment(planName)), startDeployment: planName => dispatch(startDeployment(planName)),
runPreDeploymentValidations: planName => runPreDeploymentValidations: planName =>
dispatch( dispatch(runValidationGroups(['pre-deployment'], planName))
ValidationsActions.runValidationGroups(['pre-deployment'], planName)
)
}); });
export default injectIntl( export default injectIntl(

View File

@ -25,7 +25,10 @@ import { addActiveFilter } from '../../actions/FiltersActions';
import BlankSlate from '../ui/BlankSlate'; import BlankSlate from '../ui/BlankSlate';
import { getCurrentPlanName } from '../../selectors/plans'; import { getCurrentPlanName } from '../../selectors/plans';
import { InlineLoader, Loader } from '../ui/Loader'; import { InlineLoader, Loader } from '../ui/Loader';
import ValidationsActions from '../../actions/ValidationsActions'; import {
fetchValidations,
runValidation
} from '../../actions/ValidationsActions';
import ValidationsToolbar from './ValidationsToolbar'; import ValidationsToolbar from './ValidationsToolbar';
import Validation from './Validation'; import Validation from './Validation';
import ValidationDetail from './ValidationDetail'; import ValidationDetail from './ValidationDetail';
@ -229,11 +232,11 @@ ValidationsList.propTypes = {
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
addActiveFilter: data => addActiveFilter: data =>
dispatch(addActiveFilter('validationsToolbar', data)), dispatch(addActiveFilter('validationsToolbar', data)),
fetchValidations: () => dispatch(ValidationsActions.fetchValidations()), fetchValidations: () => dispatch(fetchValidations()),
fetchWorkflowExecutions: () => fetchWorkflowExecutions: () =>
dispatch(WorkflowExecutionsActions.fetchWorkflowExecutions()), dispatch(WorkflowExecutionsActions.fetchWorkflowExecutions()),
runValidation: (id, currentPlanName) => { runValidation: (id, currentPlanName) => {
dispatch(ValidationsActions.runValidation(id, currentPlanName)); dispatch(runValidation(id, currentPlanName));
}, },
stopValidation: executionId => { stopValidation: executionId => {
dispatch( dispatch(