diff --git a/src/__tests__/actions/FlavorsActions.tests.js b/src/__tests__/actions/FlavorsActions.tests.js index c5ec8db1..e3dbfe64 100644 --- a/src/__tests__/actions/FlavorsActions.tests.js +++ b/src/__tests__/actions/FlavorsActions.tests.js @@ -14,7 +14,7 @@ * under the License. */ -import FlavorsActions from '../../js/actions/FlavorsActions'; +import * as FlavorsActions from '../../js/actions/FlavorsActions'; import NovaApiService from '../../js/services/NovaApiService'; import { mockStore } from './utils'; diff --git a/src/js/actions/FlavorsActions.js b/src/js/actions/FlavorsActions.js index 4215969a..3970e22d 100644 --- a/src/js/actions/FlavorsActions.js +++ b/src/js/actions/FlavorsActions.js @@ -21,50 +21,40 @@ import { handleErrors } from './ErrorActions'; import NovaApiService from '../services/NovaApiService'; import FlavorsConstants from '../constants/FlavorsConstants'; -export default { - fetchFlavorsPending() { - return { - type: FlavorsConstants.FETCH_FLAVORS_PENDING - }; - }, +export const fetchFlavorsPending = () => ({ + type: FlavorsConstants.FETCH_FLAVORS_PENDING +}); - fetchFlavorsSuccess(flavors) { - return { - type: FlavorsConstants.FETCH_FLAVORS_SUCCESS, - payload: flavors - }; - }, +export const fetchFlavorsSuccess = flavors => ({ + type: FlavorsConstants.FETCH_FLAVORS_SUCCESS, + payload: flavors +}); - fetchFlavorsFailed() { - return { - type: FlavorsConstants.FETCH_FLAVORS_FAILED - }; - }, +export const fetchFlavorsFailed = () => ({ + type: FlavorsConstants.FETCH_FLAVORS_FAILED +}); - // Fetch Nova flavors including os-extra_specs - // Unfortunately, we have to make a separate API call for each flavor. - fetchFlavors() { - return dispatch => { - dispatch(this.fetchFlavorsPending()); - return dispatch(NovaApiService.getFlavors()) - .then(response => { - const flavors = normalize(response.flavors, [flavorSchema]).entities - .flavors; - return Promise.all( - Object.keys(flavors).map(flavorId => - dispatch(NovaApiService.getFlavorExtraSpecs(flavorId)) - ) - ).then(flavorProfiles => { - flavorProfiles.map(profile => { - flavors[profile.id].extra_specs = profile.extra_specs; - }); - dispatch(this.fetchFlavorsSuccess(flavors)); - }); - }) - .catch(error => { - dispatch(handleErrors(error, 'Flavors could not be loaded.')); - dispatch(this.fetchFlavorsFailed()); +// Fetch Nova flavors including os-extra_specs +// Unfortunately, we have to make a separate API call for each flavor. +export const fetchFlavors = () => dispatch => { + dispatch(fetchFlavorsPending()); + return dispatch(NovaApiService.getFlavors()) + .then(response => { + const flavors = normalize(response.flavors, [flavorSchema]).entities + .flavors; + return Promise.all( + Object.keys(flavors).map(flavorId => + dispatch(NovaApiService.getFlavorExtraSpecs(flavorId)) + ) + ).then(flavorProfiles => { + flavorProfiles.map(profile => { + flavors[profile.id].extra_specs = profile.extra_specs; }); - }; - } + dispatch(fetchFlavorsSuccess(flavors)); + }); + }) + .catch(error => { + dispatch(handleErrors(error, 'Flavors could not be loaded.')); + dispatch(fetchFlavorsFailed()); + }); }; diff --git a/src/js/components/deployment_plan/RolesStep.js b/src/js/components/deployment_plan/RolesStep.js index 74d0ba34..7ab8b090 100644 --- a/src/js/components/deployment_plan/RolesStep.js +++ b/src/js/components/deployment_plan/RolesStep.js @@ -20,7 +20,7 @@ import PropTypes from 'prop-types'; import React from 'react'; import { withRouter } from 'react-router-dom'; -import FlavorsActions from '../../actions/FlavorsActions'; +import { fetchFlavors } from '../../actions/FlavorsActions'; import { getCurrentPlanName } from '../../selectors/plans'; import { getAccessibleNodes, @@ -142,7 +142,7 @@ const mapStateToProps = state => ({ totalAssignedNodesCount: getTotalAssignedNodesCount(state) }); const mapDispatchToProps = dispatch => ({ - fetchFlavors: () => dispatch(FlavorsActions.fetchFlavors()), + fetchFlavors: () => dispatch(fetchFlavors()), fetchRoles: planName => dispatch(RolesActions.fetchRoles(planName)), fetchNodes: () => dispatch(fetchNodes()) }); diff --git a/src/js/components/nodes/tag_nodes/TagNodesModal.js b/src/js/components/nodes/tag_nodes/TagNodesModal.js index a3f44873..f7016135 100644 --- a/src/js/components/nodes/tag_nodes/TagNodesModal.js +++ b/src/js/components/nodes/tag_nodes/TagNodesModal.js @@ -23,7 +23,7 @@ import React from 'react'; import { getFlavorProfiles } from '../../../selectors/flavors'; import { CloseModalXButton, Modal } from '../../ui/Modals'; -import FlavorsActions from '../../../actions/FlavorsActions'; +import { fetchFlavors } from '../../../actions/FlavorsActions'; import TagNodesForm from './TagNodesForm'; const messages = defineMessages({ @@ -70,8 +70,4 @@ const mapStateToProps = state => ({ profiles: getFlavorProfiles(state) }); -const mapDispatchToProps = dispatch => ({ - fetchFlavors: () => dispatch(FlavorsActions.fetchFlavors()) -}); - -export default connect(mapStateToProps, mapDispatchToProps)(TagNodesModal); +export default connect(mapStateToProps, { fetchFlavors })(TagNodesModal);