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

Commit

Permalink
Generate one POST request per selected host
Browse files Browse the repository at this point in the history
  • Loading branch information
mturley committed Feb 27, 2019
1 parent 3952040 commit 60cb500
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
8 changes: 4 additions & 4 deletions app/javascript/react/screens/App/Settings/SettingsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export const conversionHostWizardExitedAction = () => dispatch => {
});
};

const _postConversionHostsActionCreator = (url, postBody) => dispatch =>
const _postConversionHostsActionCreator = (url, postBodies) => dispatch =>
dispatch({
type: POST_V2V_CONVERSION_HOSTS,
payload: API.post(url, postBody)
payload: Promise.all(postBodies.map(body => API.post(url, body)))
});

export const postConversionHostsAction = (url, postBody) =>
_postConversionHostsActionCreator(new URI(url).toString(), postBody);
export const postConversionHostsAction = (url, postBodies) =>
_postConversionHostsActionCreator(new URI(url).toString(), postBodies);
4 changes: 2 additions & 2 deletions app/javascript/react/screens/App/Settings/SettingsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const initialState = Immutable({
isPostingConversionHosts: false,
isRejectedPostingConversionHosts: false,
errorPostingConversionHosts: null,
postConversionHostsResult: {}
postConversionHostsResults: []
});

export default (state = initialState, action) => {
Expand Down Expand Up @@ -124,7 +124,7 @@ export default (state = initialState, action) => {
.set('isPostingConversionHosts', false)
.set('isRejectedPostingConversionHosts', false)
.set('errorPostingConversionHosts', null)
.set('postConversionHostsResult', action.payload);
.set('postConversionHostsResults', action.payload);
case `${POST_V2V_CONVERSION_HOSTS}_REJECTED`:
return state
.set('isPostingConversionHosts', false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ import { Form } from 'patternfly-react';

class ConversionHostWizardResultsStep extends React.Component {
componentDidMount() {
const { postBody, postConversionHostsAction, postConversionHostsUrl } = this.props;
postConversionHostsAction(postConversionHostsUrl, postBody);
const { postBodies, postConversionHostsAction, postConversionHostsUrl } = this.props;
postConversionHostsAction(postConversionHostsUrl, postBodies);
}

render() {
const { isPostingConversionHosts, isRejectedPostingConversionHosts, postConversionHostsResult } = this.props;
const { isPostingConversionHosts, isRejectedPostingConversionHosts, postConversionHostsResults } = this.props;
return (
<Form className="form-horizontal">
<h2>TODO: Results Step Contents</h2>
<ul>
<li>Posting? {isPostingConversionHosts}</li>
<li>Rejected? {isRejectedPostingConversionHosts}</li>
<li>Result: {JSON.stringify(postConversionHostsResult, 4)}</li>
<li>Results: {JSON.stringify(postConversionHostsResults, 4)}</li>
</ul>
</Form>
);
}
}

ConversionHostWizardResultsStep.propTypes = {
postBody: PropTypes.object,
postBodies: PropTypes.arrayOf(PropTypes.object),
postConversionHostsAction: PropTypes.func,
postConversionHostsUrl: PropTypes.string,
isPostingConversionHosts: PropTypes.bool,
isRejectedPostingConversionHosts: PropTypes.bool,
postConversionHostsResult: PropTypes.object
postConversionHostsResults: PropTypes.arrayOf(PropTypes.object)
};

ConversionHostWizardResultsStep.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
export const getConfigureConversionHostPostBody = (locationStepValues, hostsStepValues, authStepValues) => {
console.log('TODO: use location step values:', locationStepValues);
console.log('TODO: use hosts step values:', hostsStepValues);
console.log('TODO: use auth step values: ', authStepValues);
// TODO
return {
foo: 'bar'
};
};
import { OPENSTACK } from '../../../../../../../../../common/constants';
import { VDDK } from '../ConversionHostWizardConstants';

export const getConfigureConversionHostPostBodies = (locationStepValues, hostsStepValues, authStepValues) =>
hostsStepValues.hosts.map(host => {
const openstackSpecificProperties =
locationStepValues.providerType === OPENSTACK ? { auth_user: authStepValues.openstackUser } : {};
const vddkSpecificProperties =
authStepValues.transformationMethod === VDDK
? { param_v2v_vddk_package_url: authStepValues.vddkLibraryPath }
: {};
return {
name: host.name,
resource_type: host.type,
resource_id: host.id,
...openstackSpecificProperties,
...vddkSpecificProperties
};
// TODO: handle authStepValues.conversionHostSshKey
// TODO: handle authStepValues.transformationMethod (explicitly?)
// TODO: handle authStepValues.vmwareSshKey (if transformationMethod === SSH)
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import { connect } from 'react-redux';
import ConversionHostWizardResultsStep from './ConversionHostWizardResultsStep';

import { stepIDs } from '../ConversionHostWizardConstants';
import { getConfigureConversionHostPostBody } from './helpers';
import { getConfigureConversionHostPostBodies } from './helpers';
import { postConversionHostsAction } from '../../../../../SettingsActions';

const mapStateToProps = ({
form,
settings: { isPostingConversionHosts, isRejectedPostingConversionHosts, postConversionHostsResult }
settings: { isPostingConversionHosts, isRejectedPostingConversionHosts, postConversionHostsResults }
}) => {
const locationStepValues = form[stepIDs.locationStep] && form[stepIDs.locationStep].values;
const hostsStepValues = form[stepIDs.hostsStep] && form[stepIDs.hostsStep].values;
const authStepValues = form[stepIDs.authenticationStep] && form[stepIDs.authenticationStep].values;
const postBody = getConfigureConversionHostPostBody(locationStepValues, hostsStepValues, authStepValues);
const postBodies = getConfigureConversionHostPostBodies(locationStepValues, hostsStepValues, authStepValues);
return {
postBody,
postBodies,
isPostingConversionHosts,
isRejectedPostingConversionHosts,
postConversionHostsResult
postConversionHostsResults
};
};

Expand Down

0 comments on commit 60cb500

Please sign in to comment.