Refactor RolesActions to use startWorkflow
Change-Id: I2e48649a0b8fec99d7f96e3215b99e07e7ea155b Partial-Bug: #1753474
This commit is contained in:
parent
06b40b3ca3
commit
b9dcdaea02
|
@ -19,10 +19,12 @@ import { normalize } from 'normalizr';
|
|||
import { startSubmit, stopSubmit } from 'redux-form';
|
||||
|
||||
import { handleErrors } from './ErrorActions';
|
||||
import history from '../utils/history';
|
||||
import RolesConstants from '../constants/RolesConstants';
|
||||
import { roleSchema } from '../normalizrSchemas/roles';
|
||||
import MistralApiService from '../services/MistralApiService';
|
||||
import MistralConstants from '../constants/MistralConstants';
|
||||
import { startWorkflow } from './WorkflowActions';
|
||||
|
||||
const messages = defineMessages({
|
||||
availableRolesNotLoaded: {
|
||||
|
@ -77,10 +79,16 @@ export default {
|
|||
const { formatMessage } = getIntl(getState());
|
||||
dispatch(this.fetchAvailableRolesPending());
|
||||
dispatch(
|
||||
MistralApiService.runWorkflow(MistralConstants.LIST_AVAILABLE_ROLES, {
|
||||
container: planName
|
||||
})
|
||||
startWorkflow(
|
||||
MistralConstants.LIST_AVAILABLE_ROLES,
|
||||
{
|
||||
container: planName
|
||||
},
|
||||
execution => dispatch(this.fetchAvailableRolesFinished(execution))
|
||||
)
|
||||
).catch(error => {
|
||||
history.push('/plans');
|
||||
dispatch(this.fetchAvailableRolesFailed());
|
||||
dispatch(
|
||||
handleErrors(error, formatMessage(messages.availableRolesNotLoaded))
|
||||
);
|
||||
|
@ -88,19 +96,19 @@ export default {
|
|||
};
|
||||
},
|
||||
|
||||
fetchAvailableRolesFinished({ available_roles, message, status }, history) {
|
||||
fetchAvailableRolesFinished({ output: { available_roles, message }, state }) {
|
||||
return (dispatch, getState, { getIntl }) => {
|
||||
const { formatMessage } = getIntl(getState());
|
||||
if (status === 'SUCCESS') {
|
||||
if (state === 'SUCCESS') {
|
||||
const roles =
|
||||
normalize(available_roles, [roleSchema]).entities.roles || {};
|
||||
dispatch(this.fetchAvailableRolesSuccess(roles));
|
||||
} else {
|
||||
history.push('/plans');
|
||||
dispatch(this.fetchAvailableRolesFailed());
|
||||
dispatch(
|
||||
handleErrors(message, formatMessage(messages.availableRolesNotLoaded))
|
||||
);
|
||||
history.push('/plans');
|
||||
dispatch(this.fetchAvailableRolesFailed());
|
||||
}
|
||||
};
|
||||
},
|
||||
|
@ -128,10 +136,14 @@ export default {
|
|||
return (dispatch, getState) => {
|
||||
dispatch(startSubmit('selectRoles'));
|
||||
dispatch(
|
||||
MistralApiService.runWorkflow(MistralConstants.SELECT_ROLES, {
|
||||
container: planName,
|
||||
role_names: roleNames
|
||||
})
|
||||
startWorkflow(
|
||||
MistralConstants.SELECT_ROLES,
|
||||
{
|
||||
container: planName,
|
||||
role_names: roleNames
|
||||
},
|
||||
execution => dispatch(this.selectRolesFinished(execution))
|
||||
)
|
||||
).catch(error => {
|
||||
const { name, message } = error;
|
||||
dispatch(
|
||||
|
@ -141,9 +153,9 @@ export default {
|
|||
};
|
||||
},
|
||||
|
||||
selectRolesFinished({ selected_roles, message, status, ...rest }, history) {
|
||||
selectRolesFinished({ output: { selected_roles, message }, state }) {
|
||||
return (dispatch, getState) => {
|
||||
if (status === 'SUCCESS') {
|
||||
if (state === 'SUCCESS') {
|
||||
const roles =
|
||||
normalize(selected_roles, [roleSchema]).entities.roles || {};
|
||||
dispatch(this.selectRolesSuccess(roles));
|
||||
|
|
|
@ -123,13 +123,21 @@ export default {
|
|||
}
|
||||
|
||||
case MistralConstants.LIST_AVAILABLE_ROLES: {
|
||||
dispatch(RolesActions.fetchAvailableRolesFinished(payload, history));
|
||||
dispatch(
|
||||
handleWorkflowMessage(payload.execution.id, execution =>
|
||||
dispatch(RolesActions.fetchAvailableRolesFinished(execution))
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
// TODO(jtomasek): change this back once underlining tripleo-common patch is fixed
|
||||
case MistralConstants.SELECT_ROLES: {
|
||||
// case 'tripleo.roles.v1.select_roles': {
|
||||
dispatch(RolesActions.selectRolesFinished(payload, history));
|
||||
dispatch(
|
||||
handleWorkflowMessage(payload.execution.id, execution =>
|
||||
dispatch(RolesActions.selectRolesFinished(execution))
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,10 @@ import 'babel-polyfill';
|
|||
import { Provider } from 'react-redux';
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { BrowserRouter as Router } from 'react-router-dom';
|
||||
import { Router } from 'react-router-dom';
|
||||
|
||||
import App from './components/App';
|
||||
import history from './utils/history';
|
||||
import I18nProvider from './components/i18n/I18nProvider';
|
||||
import initFormsy from './components/utils/Formsy';
|
||||
import { setupReduxFormValidators } from './utils/reduxFormValidators';
|
||||
|
@ -35,7 +36,7 @@ setupReduxFormValidators();
|
|||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
<I18nProvider>
|
||||
<Router>
|
||||
<Router history={history}>
|
||||
<App />
|
||||
</Router>
|
||||
</I18nProvider>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* Copyright 2018 Red Hat Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { createBrowserHistory } from 'history';
|
||||
export default createBrowserHistory();
|
Loading…
Reference in New Issue