Merge "Convert FlavorsActions to named exports"
This commit is contained in:
@@ -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';
|
||||
|
||||
|
||||
@@ -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());
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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())
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user