Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Conversion Host Configuration Wizard Step #1 (Location), and introducing common reducers #871

Merged
merged 16 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/javascript/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@ export const validation = {
maxLengthWarning: sprintf(youHaveReachedMax, MAX_LENGTH_DESCRIPTIONS)
}
};

export const OPENSTACK = 'openstack';
export const RHV = 'rhevm';

export const V2V_TARGET_PROVIDERS = [
{
name: __('Red Hat Virtualization'),
id: RHV,
type: 'ManageIQ::Providers::Redhat::InfraManager'
},
{
name: __('Red Hat OpenStack Platform'),
id: OPENSTACK,
type: 'ManageIQ::Providers::Openstack::CloudManager'
}
];
8 changes: 6 additions & 2 deletions app/javascript/react/screens/App/Mappings/Mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import componentRegistry from '../../../../components/componentRegistry';
import InfrastructureMappingsList from './components/InfrastructureMappingsList/InfrastructureMappingsList';
import { FETCH_TRANSFORMATION_PLANS_URL, FETCH_ARCHIVED_TRANSFORMATION_PLANS_URL } from '../Overview/OverviewConstants';
import { FETCH_TRANSFORMATION_MAPPINGS_URL, FETCH_CLOUD_TENANTS_URL } from './MappingsConstants';
import { FETCH_V2V_PROVIDERS_URL } from '../../../../redux/common/providers/providersConstants';
import ShowWizardEmptyState from '../common/ShowWizardEmptyState/ShowWizardEmptyState';

class Mappings extends Component {
Expand All @@ -33,6 +34,7 @@ class Mappings extends Component {
fetchNetworksAction,
fetchNetworksUrl,
fetchProvidersAction,
fetchProvidersUrl,
fetchTransformationMappingsAction,
fetchTransformationMappingsUrl,
fetchTransformationPlansAction,
Expand All @@ -53,7 +55,7 @@ class Mappings extends Component {
fetchClustersAction(fetchClustersUrl);
fetchDatastoresAction(fetchDatastoresUrl);
fetchNetworksAction(fetchNetworksUrl);
fetchProvidersAction();
fetchProvidersAction(fetchProvidersUrl);
fetchTransformationMappingsAction(fetchTransformationMappingsUrl);

Promise.all([
Expand Down Expand Up @@ -263,6 +265,7 @@ Mappings.propTypes = {
fetchNetworksAction: PropTypes.func,
fetchNetworksUrl: PropTypes.string,
fetchProvidersAction: PropTypes.func,
fetchProvidersUrl: PropTypes.string,
fetchTransformationMappingsAction: PropTypes.func,
fetchTransformationMappingsUrl: PropTypes.string,
fetchTransformationPlansAction: PropTypes.func,
Expand Down Expand Up @@ -312,7 +315,8 @@ Mappings.defaultProps = {
fetchNetworksUrl: '/api/lans/?expand=resources',
fetchTransformationMappingsUrl: FETCH_TRANSFORMATION_MAPPINGS_URL,
fetchArchivedTransformationPlansUrl: FETCH_ARCHIVED_TRANSFORMATION_PLANS_URL,
fetchTransformationPlansUrl: FETCH_TRANSFORMATION_PLANS_URL
fetchTransformationPlansUrl: FETCH_TRANSFORMATION_PLANS_URL,
fetchProvidersUrl: FETCH_V2V_PROVIDERS_URL
};

export default Mappings;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { V2V_SHOW_MAPPING_WIZARD } from '../Mappings/screens/MappingWizard/Mappi

import { SET_V2V_EDITING_MAPPING } from '../Mappings/screens/MappingWizard/components/MappingWizardGeneralStep/MappingWizardGeneralStepConstants';

export { fetchTransformationPlansAction, fetchProvidersAction } from '../Overview/OverviewActions';
export { fetchTransformationPlansAction } from '../Overview/OverviewActions';

// ****************************************************************************
// DELETE_V2V_INFRASTRUCTURE_MAPPING
Expand Down
15 changes: 4 additions & 11 deletions app/javascript/react/screens/App/Mappings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { connect } from 'react-redux';
import Mappings from './Mappings';
import * as MappingsActions from './MappingsActions';
import * as RouterActions from '../../../../redux/actions/routerActions';
import * as ProvidersActions from '../../../../redux/common/providers/providersActions';
import reducer from './MappingsReducer';

import {
Expand All @@ -16,15 +17,8 @@ export const reducers = { mappings: reducer, form: {} };
const mapStateToProps = (
{
mappings,
overview: {
archivedTransformationPlans,
transformationPlans,
planId,
hasSufficientProviders,
isRejectedProviders,
isFetchingProviders,
errorProviders
}
overview: { archivedTransformationPlans, transformationPlans, planId },
providers: { hasSufficientProviders, isRejectedProviders, isFetchingProviders }
},
ownProps
) => ({
Expand All @@ -35,7 +29,6 @@ const mapStateToProps = (
hasSufficientProviders,
isRejectedProviders,
isFetchingProviders,
errorProviders,
activeTransformationPlans: activeTransformationPlansFilter(transformationPlans, planId),
finishedWithErrorTransformationPlans: finishedWithErrorTransformationPlansFilter(transformationPlans),
notStartedTransformationPlans: notStartedTransformationPlansFilter(transformationPlans)
Expand All @@ -49,6 +42,6 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => ({

export default connect(
mapStateToProps,
{ ...MappingsActions, ...RouterActions },
{ ...MappingsActions, ...RouterActions, ...ProvidersActions },
mergeProps
)(Mappings);
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { OPENSTACK, RHV, V2V_TARGET_PROVIDERS } from '../../../../../../common/constants';

export const V2V_SET_TRANSFORMATIONS_BODY = 'V2V_SET_TRANSFORMATIONS_BODY';
export const V2V_SHOW_WARNING_MODAL = 'V2V_SHOW_WARNING_MODAL';
export const V2V_HIDE_WARNING_MODAL = 'V2V_HIDE_WARNING_MODAL';
Expand All @@ -6,14 +8,7 @@ export const V2V_HIDE_ALERT = 'V2V_HIDE_ALERT';
export const V2V_MAPPING_WIZARD_EXITED = 'V2V_MAPPING_WIZARD_EXITED';
export const V2V_SHOW_MAPPING_WIZARD = 'V2V_SHOW_MAPPING_WIZARD';
export const V2V_HIDE_MAPPING_WIZARD = 'V2V_HIDE_MAPPING_WIZARD';

export const OPENSTACK = 'openstack';
export const RHV = 'rhevm';

export const V2V_TARGET_PROVIDERS = [
{ name: __('Red Hat Virtualization'), id: RHV },
{ name: __('Red Hat OpenStack Platform'), id: OPENSTACK }
];
export { OPENSTACK, RHV, V2V_TARGET_PROVIDERS };

export const V2V_TARGET_PROVIDER_STORAGE_KEYS = {
[RHV]: 'storages',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createTransformationMappings } from '../helpers';
import { constructClusterMappings, constructDatastoreOrNetworkMappings } from '../mappingWizardTestHelpers';
import {
targetClusters,
sourceClusters
} from '../components/MappingWizardClustersStep/mappingWizardClustersStep.fixtures';
import { sourceClusters } from '../components/MappingWizardClustersStep/mappingWizardClustersStep.fixtures';
import { targetClusters } from '../../../../../../../redux/common/targetResources/targetResources.fixtures';
import {
sourceClusterDatastores,
targetClusterDatastores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Field, reduxForm } from 'redux-form';
import { length } from 'redux-form-validators';

import ClustersStepForm from './components/ClustersStepForm/ClustersStepForm';
import { FETCH_TARGET_COMPUTE_URLS, QUERY_PROVIDERS_URL } from './MappingWizardClustersStepConstants';
import { QUERY_PROVIDERS_URL } from './MappingWizardClustersStepConstants';
import { FETCH_TARGET_COMPUTE_URLS } from '../../../../../../../../redux/common/targetResources/targetResourcesConstants';
import { getProviderIds } from './helpers';
import { OPENSTACK } from '../../MappingWizardConstants';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import URI from 'urijs';
import API from '../../../../../../../../common/API';
import {
FETCH_V2V_SOURCE_CLUSTERS,
FETCH_V2V_TARGET_CLUSTERS,
QUERY_V2V_PROVIDERS
} from './MappingWizardClustersStepConstants';
import { FETCH_V2V_SOURCE_CLUSTERS, QUERY_V2V_PROVIDERS } from './MappingWizardClustersStepConstants';

export { showAlertAction, hideAlertAction } from '../../MappingWizardActions';

Expand All @@ -19,17 +15,6 @@ export const fetchSourceClustersAction = url => {
return _getSourceClustersActionCreator(uri.toString());
};

const _getTargetClustersActionCreator = url => dispatch =>
dispatch({
type: FETCH_V2V_TARGET_CLUSTERS,
payload: API.get(url)
});

export const fetchTargetClustersAction = url => {
const uri = new URI(url);
return _getTargetClustersActionCreator(uri.toString());
};

// ****************************************************************************
// QUERY_V2V_PROVIDERS
// ****************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ export const CONVERSION_HOST_TYPES = {
[OPENSTACK]: 'ManageIQ::Providers::Openstack::CloudManager::Vm'
};

export const FETCH_TARGET_COMPUTE_URLS = {
[RHV]:
'/api/clusters?expand=resources' +
'&attributes=ext_management_system.emstype,v_parent_datacenter,ext_management_system.name,hosts' +
'&filter[]=ext_management_system.emstype=rhevm',
[OPENSTACK]: '/api/cloud_tenants?expand=resources&attributes=ext_management_system.name,ext_management_system.id'
};

export const QUERY_PROVIDERS_URL = '/api/providers';

export const TARGET_WARNING_MESSAGES = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Immutable from 'seamless-immutable';

import {
FETCH_V2V_SOURCE_CLUSTERS,
FETCH_V2V_TARGET_CLUSTERS,
QUERY_V2V_PROVIDERS
} from './MappingWizardClustersStepConstants';
import { FETCH_V2V_SOURCE_CLUSTERS, QUERY_V2V_PROVIDERS } from './MappingWizardClustersStepConstants';
import { V2V_MAPPING_WIZARD_EXITED } from '../../../../screens/MappingWizard/MappingWizardConstants';

export const initialState = Immutable({
Expand Down Expand Up @@ -42,24 +38,7 @@ export default (state = initialState, action) => {
.set('errorSourceClusters', action.payload)
.set('isRejectedSourceClusters', true)
.set('isFetchingSourceClusters', false);
case `${FETCH_V2V_TARGET_CLUSTERS}_PENDING`:
return state.set('isFetchingTargetClusters', true).set('isRejectedTargetClusters', false);
case `${FETCH_V2V_TARGET_CLUSTERS}_FULFILLED`:
if (action.payload.data && action.payload.data.resources && action.payload.data.resources[0]) {
return state
.set('targetClusters', action.payload.data.resources)
.set('isRejectedTargetClusters', false)
.set('isFetchingTargetClusters', false);
}
return state
.set('targetClusters', [])
.set('isRejectedTargetClusters', false)
.set('isFetchingTargetClusters', false);
case `${FETCH_V2V_TARGET_CLUSTERS}_REJECTED`:
return state
.set('errorTargetClusters', action.payload)
.set('isRejectedTargetClusters', true)
.set('isFetchingTargetClusters', false);

case `${QUERY_V2V_PROVIDERS}_PENDING`:
return state.set('isQueryingProviders', true).set('isRejectedQueryProviders', false);
case `${QUERY_V2V_PROVIDERS}_FULFILLED`:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { mockStore } from '../../../../../../common/testReduxHelpers';
import * as actions from '../MappingWizardClustersStepActions';
import {
initialState,
requestSourceClustersData,
requestTargetClustersData
} from '../mappingWizardClustersStep.fixtures';
import { initialState, requestSourceClustersData } from '../mappingWizardClustersStep.fixtures';
import { mockRequest, mockReset } from '../../../../../../../../../common/mockRequests';

const store = mockStore(initialState);
Expand Down Expand Up @@ -35,27 +31,6 @@ describe('mappingWizard actions', () => {
expect(store.getActions()).toMatchSnapshot();
});
});

it('should fetch target clusters and return PENDING and FULFILLED action', () => {
const { fetchTargetClustersUrl } = requestTargetClustersData;
mockRequest({
url: fetchTargetClustersUrl,
status: 200
});
return store.dispatch(actions.fetchTargetClustersAction(fetchTargetClustersUrl)).then(() => {
expect(store.getActions()).toMatchSnapshot();
});
});
it('should fetch target clusters and return PENDING and REJECTED action', () => {
const { fetchTargetClustersUrl } = requestTargetClustersData;
mockRequest({
url: fetchTargetClustersUrl,
status: 404
});
return store.dispatch(actions.fetchTargetClustersAction(fetchTargetClustersUrl)).catch(() => {
expect(store.getActions()).toMatchSnapshot();
});
});
});

describe('queryProvidersAction', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { generateStore } from '../../../../../../common/testReduxHelpers';
import { reducers } from '../index';
import { initialState } from '../MappingWizardClustersStepReducer';
import MappingWizardClustersStep from '../MappingWizardClustersStep';
import { FETCH_TARGET_COMPUTE_URLS } from '../MappingWizardClustersStepConstants';
import { FETCH_TARGET_COMPUTE_URLS } from '../../../../../../../../../redux/common/targetResources/targetResourcesConstants';
import { OPENSTACK } from '../../../MappingWizardConstants';

const store = generateStore(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import Immutable from 'seamless-immutable';
import clustersReducer, { initialState } from '../MappingWizardClustersStepReducer';
import {
FETCH_V2V_SOURCE_CLUSTERS,
FETCH_V2V_TARGET_CLUSTERS,
QUERY_V2V_PROVIDERS
} from '../MappingWizardClustersStepConstants';
import { sourceClusters, targetClusters } from '../mappingWizardClustersStep.fixtures';
import { FETCH_V2V_SOURCE_CLUSTERS, QUERY_V2V_PROVIDERS } from '../MappingWizardClustersStepConstants';
import { sourceClusters } from '../mappingWizardClustersStep.fixtures';

test('sets default state', () => {
const action = { type: '@@INIT' };
Expand Down Expand Up @@ -81,72 +77,6 @@ describe('fetching source clusters', () => {
});
});

describe('fetching target clusters', () => {
test('is pending', () => {
const action = {
type: `${FETCH_V2V_TARGET_CLUSTERS}_PENDING`
};
const prevState = initialState.set('isRejectedTargetClusters', true);
const state = clustersReducer(prevState, action);

expect(state).toMatchSnapshot();
});

test('is rejected', () => {
const action = {
type: `${FETCH_V2V_TARGET_CLUSTERS}_REJECTED`,
payload: 'error'
};
const prevState = initialState.set('isFetchingTargetClusters', true);
const state = clustersReducer(prevState, action);

expect(state).toMatchSnapshot();
});

describe('is successful,', () => {
let prevState;
beforeEach(() => {
prevState = initialState.set('isRejectedTargetClusters', true).set('isFetchingTargetClusters', true);
});
test('and there is data', () => {
const { resources } = targetClusters;
const payload = {
data: {
...targetClusters,
resources: [
{
...resources
}
]
}
};
const action = {
type: `${FETCH_V2V_TARGET_CLUSTERS}_FULFILLED`,
payload
};
const state = clustersReducer(prevState, action);

expect(state).toMatchSnapshot();
});

test('and there is no data', () => {
const payload = {
data: {
...targetClusters,
resources: []
}
};
const action = {
type: `${FETCH_V2V_TARGET_CLUSTERS}_FULFILLED`,
payload
};
const state = clustersReducer(prevState, action);

expect(state).toMatchSnapshot();
});
});
});

describe('QUERY_V2V_PROVIDERS', () => {
test('querying providers is pending', () => {
const action = { type: `${QUERY_V2V_PROVIDERS}_PENDING` };
Expand Down
Loading