Convert RegisterNodesActions to named exports
* avoid using 'this' in thunks Change-Id: Ibbcaeba29c81e66c6c1d2b0173560b8feb29b71b
This commit is contained in:
parent
0876f351ce
commit
7859c63bde
|
@ -21,7 +21,7 @@ import { mockStore } from './utils';
|
|||
import * as NodesActions from '../../js/actions/NodesActions';
|
||||
import * as NotificationActions from '../../js/actions/NotificationActions';
|
||||
import * as ValidationsActions from '../../js/actions/ValidationsActions';
|
||||
import RegisterNodesActions from '../../js/actions/RegisterNodesActions';
|
||||
import * as RegisterNodesActions from '../../js/actions/RegisterNodesActions';
|
||||
|
||||
describe('startNodesRegistration Action', () => {
|
||||
const store = mockStore({});
|
||||
|
|
|
@ -36,86 +36,74 @@ const messages = defineMessages({
|
|||
}
|
||||
});
|
||||
|
||||
export default {
|
||||
startNodesRegistration(nodes) {
|
||||
return (dispatch, getState) => {
|
||||
// TODO(jtomasek): Once we are able to generate UUIDs for nodes,
|
||||
// add nodes to the list and add operation using startNodesOperation action.
|
||||
// Remove registerNodesReducer and track the progress on each node.
|
||||
// Introduce separate reducer for tracking operations: nodeOperationsById
|
||||
// dispatch(addNodes(nodes.map(node => new Node(node))));
|
||||
// dispatch(startOperation(nodes.map(node => node.uuid), 'register'))
|
||||
// addNodes(nodesToRegister.map(node => new Node))
|
||||
dispatch(this.nodesRegistrationPending());
|
||||
};
|
||||
},
|
||||
// TODO(jtomasek): Once we are able to generate UUIDs for nodes,
|
||||
// add nodes to the list and add operation using startNodesOperation action.
|
||||
// Remove registerNodesReducer and track the progress on each node.
|
||||
// Introduce separate reducer for tracking operations: nodeOperationsById
|
||||
// dispatch(addNodes(nodes.map(node => new Node(node))));
|
||||
// dispatch(startOperation(nodes.map(node => node.uuid), 'register'))
|
||||
// addNodes(nodesToRegister.map(node => new Node))
|
||||
export const startNodesRegistration = nodes => dispatch =>
|
||||
dispatch(nodesRegistrationPending());
|
||||
|
||||
nodesRegistrationPending() {
|
||||
return {
|
||||
type: RegisterNodesConstants.NODES_REGISTRATION_PENDING
|
||||
};
|
||||
},
|
||||
export const nodesRegistrationPending = () => ({
|
||||
type: RegisterNodesConstants.NODES_REGISTRATION_PENDING
|
||||
});
|
||||
|
||||
nodesRegistrationFinished(execution) {
|
||||
return (dispatch, getState, { getIntl }) => {
|
||||
const { formatMessage } = getIntl(getState());
|
||||
const { output: { message, registered_nodes }, state } = execution;
|
||||
const registeredNodes =
|
||||
normalize(registered_nodes, [nodeSchema]).entities.nodes || Map();
|
||||
dispatch(addNodes(registeredNodes));
|
||||
// TODO(jtomasek): This should not be needed when workflow returns up to date nodes
|
||||
dispatch(fetchNodes());
|
||||
export const nodesRegistrationFinished = execution => (
|
||||
dispatch,
|
||||
getState,
|
||||
{ getIntl }
|
||||
) => {
|
||||
const { formatMessage } = getIntl(getState());
|
||||
const { output: { message, registered_nodes }, state } = execution;
|
||||
const registeredNodes =
|
||||
normalize(registered_nodes, [nodeSchema]).entities.nodes || Map();
|
||||
dispatch(addNodes(registeredNodes));
|
||||
// TODO(jtomasek): This should not be needed when workflow returns up to date nodes
|
||||
dispatch(fetchNodes());
|
||||
|
||||
// run pre-introspection validations
|
||||
// run pre-introspection validations
|
||||
dispatch(
|
||||
runValidationGroups(['pre-introspection'], getCurrentPlanName(getState()))
|
||||
);
|
||||
|
||||
switch (state) {
|
||||
case 'SUCCESS': {
|
||||
dispatch(
|
||||
runValidationGroups(
|
||||
['pre-introspection'],
|
||||
getCurrentPlanName(getState())
|
||||
)
|
||||
notify({
|
||||
type: 'success',
|
||||
title: formatMessage(messages.registrationNotificationTitle),
|
||||
message: formatMessage(messages.registrationNotificationMessage)
|
||||
})
|
||||
);
|
||||
|
||||
switch (state) {
|
||||
case 'SUCCESS': {
|
||||
dispatch(
|
||||
notify({
|
||||
type: 'success',
|
||||
title: formatMessage(messages.registrationNotificationTitle),
|
||||
message: formatMessage(messages.registrationNotificationMessage)
|
||||
})
|
||||
);
|
||||
dispatch(this.nodesRegistrationSuccess());
|
||||
break;
|
||||
dispatch(nodesRegistrationSuccess());
|
||||
break;
|
||||
}
|
||||
case 'ERROR': {
|
||||
const errors = [
|
||||
{
|
||||
title: 'Nodes Registration Failed',
|
||||
message: message.message.filter(m => m.result).map(m => m.result)
|
||||
}
|
||||
case 'ERROR': {
|
||||
const errors = [
|
||||
{
|
||||
title: 'Nodes Registration Failed',
|
||||
message: message.message.filter(m => m.result).map(m => m.result)
|
||||
}
|
||||
];
|
||||
// TODO(jtomasek): repopulate nodes registration form with failed nodes provided by message
|
||||
dispatch(this.nodesRegistrationFailed(errors));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
nodesRegistrationSuccess() {
|
||||
return {
|
||||
type: RegisterNodesConstants.NODES_REGISTRATION_SUCCESS
|
||||
};
|
||||
},
|
||||
|
||||
nodesRegistrationFailed(errors, failedNodes) {
|
||||
return {
|
||||
type: RegisterNodesConstants.NODES_REGISTRATION_FAILED,
|
||||
payload: {
|
||||
errors: errors,
|
||||
failedNodes: failedNodes
|
||||
}
|
||||
};
|
||||
];
|
||||
// TODO(jtomasek): repopulate nodes registration form with failed nodes provided by message
|
||||
dispatch(nodesRegistrationFailed(errors));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
export const nodesRegistrationSuccess = () => ({
|
||||
type: RegisterNodesConstants.NODES_REGISTRATION_SUCCESS
|
||||
});
|
||||
|
||||
export const nodesRegistrationFailed = (errors, failedNodes) => ({
|
||||
type: RegisterNodesConstants.NODES_REGISTRATION_FAILED,
|
||||
payload: {
|
||||
errors: errors,
|
||||
failedNodes: failedNodes
|
||||
}
|
||||
});
|
||||
|
|
|
@ -36,7 +36,7 @@ import {
|
|||
updatePlanFinished,
|
||||
exportPlanFinished
|
||||
} from './PlansActions';
|
||||
import RegisterNodesActions from './RegisterNodesActions';
|
||||
import { nodesRegistrationFinished } from './RegisterNodesActions';
|
||||
import RolesActions from './RolesActions';
|
||||
import StacksActions from './StacksActions';
|
||||
import { stackSchema } from '../normalizrSchemas/stacks';
|
||||
|
@ -72,7 +72,7 @@ export default {
|
|||
dispatch(
|
||||
handleWorkflowMessage(
|
||||
payload.execution.id,
|
||||
RegisterNodesActions.nodesRegistrationFinished
|
||||
nodesRegistrationFinished
|
||||
)
|
||||
);
|
||||
break;
|
||||
|
|
|
@ -44,7 +44,10 @@ import {
|
|||
import { handleErrors } from '../../../actions/ErrorActions';
|
||||
import { OverlayLoader } from '../../ui/Loader';
|
||||
import { notify } from '../../../actions/NotificationActions';
|
||||
import RegisterNodesActions from '../../../actions/RegisterNodesActions';
|
||||
import {
|
||||
nodesRegistrationFinished,
|
||||
startNodesRegistration
|
||||
} from '../../../actions/RegisterNodesActions';
|
||||
import RegisterNodesForm from './RegisterNodesForm';
|
||||
import MistralApiService from '../../../services/MistralApiService';
|
||||
import MistralConstants from '../../../constants/MistralConstants';
|
||||
|
@ -162,7 +165,7 @@ class RegisterNodesDialog extends React.Component {
|
|||
kernel_name: 'bm-deploy-kernel',
|
||||
ramdisk_name: 'bm-deploy-ramdisk'
|
||||
},
|
||||
RegisterNodesActions.nodesRegistrationFinished
|
||||
nodesRegistrationFinished
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -282,8 +285,7 @@ function mapDispatchToProps(dispatch) {
|
|||
removeNode: nodeIndex =>
|
||||
dispatch(arrayRemove('registerNodesForm', 'nodes', nodeIndex)),
|
||||
resetForm: () => dispatch(reset('registerNodesForm')),
|
||||
startNodesRegistration: nodes =>
|
||||
dispatch(RegisterNodesActions.startNodesRegistration(nodes)),
|
||||
startNodesRegistration: nodes => dispatch(startNodesRegistration(nodes)),
|
||||
submitForm: () => dispatch(submit('registerNodesForm')),
|
||||
notify: notification => dispatch(notify(notification))
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue