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

Commit

Permalink
Add PUT action creator for saving edited plan
Browse files Browse the repository at this point in the history
  • Loading branch information
mturley committed Sep 10, 2018
1 parent 37fc8bf commit 3e84233
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export const getVMStepSelectedVms = (allVms, selectedVms) => allVms.filter(vm =>
// Property can be 'pre_service' or 'post_service'.
// Returns an array of vm ids which have a truthy value for that property in the plan being edited.
export const getVmIdsWithProperty = (editingPlan, property) => {
const actions = editingPlan && editingPlan.options && editingPlan.options.config_info && editingPlan.options.config_info.actions;
const actions =
editingPlan && editingPlan.options && editingPlan.options.config_info && editingPlan.options.config_info.actions;
if (!actions) return [];
const actionsWithProperty = actions.filter(action => action[property]);
return actionsWithProperty.map(action => action.vm_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BootstrapSelect } from '../../../../../common/forms/BootstrapSelect';
import { validation } from '../../../../../../../../common/constants';
import { asyncValidate, onChange } from './helpers';

// TODO disable the mapping selection when editing
const PlanWizardGeneralStep = ({ transformationMappings }) => (
<Form className="form-horizontal">
<Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { noop, Spinner } from 'patternfly-react';

class PlanWizardResultsStep extends React.Component {
componentDidMount() {
const { postPlansUrl, postMigrationPlansAction, plansBody, planSchedule } = this.props;

postMigrationPlansAction(postPlansUrl, plansBody, planSchedule);
const { postPlansUrl, postMigrationPlansAction, putPlansUrl, putMigrationPlansAction, plansBody, planSchedule, editingPlan } = this.props;
if (!editingPlan) {
postMigrationPlansAction(postPlansUrl, plansBody, planSchedule);
} else {
putMigrationPlansAction(putPlansUrl, editingPlan.id, plansBody, planSchedule);
}
}
renderResult = (migrationPlanMessage, migrationPlanFollowupMessage, migrationPlanIcon) => (
<div className="wizard-pf-complete blank-slate-pf">
Expand Down Expand Up @@ -71,19 +74,24 @@ class PlanWizardResultsStep extends React.Component {
}
PlanWizardResultsStep.propTypes = {
postPlansUrl: PropTypes.string,
putPlansUrl: PropTypes.string,
postMigrationPlansAction: PropTypes.func,
putMigrationPlansAction: PropTypes.func,
plansBody: PropTypes.object,
planSchedule: PropTypes.string,
isPostingPlans: PropTypes.bool,
isRejectedPostingPlans: PropTypes.bool,
errorPostingPlans: PropTypes.object,
migrationPlansResult: PropTypes.object,
migrationRequestsResult: PropTypes.object,
hidePlanWizardAction: PropTypes.func
hidePlanWizardAction: PropTypes.func,
editingPlan: PropTypes.object
};
PlanWizardResultsStep.defaultProps = {
postPlansUrl: '/api/service_templates',
putPlansUrl: '/api/service_templates',
postMigrationPlansAction: noop,
putMigrationPlansAction: noop,
plansBody: {},
planSchedule: '',
isPostingPlans: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,21 @@ const _postMigrationPlansActionCreator = (url, migrationPlans, planSchedule) =>

export const postMigrationPlansAction = (url, migrationPlans, planSchedule) =>
_postMigrationPlansActionCreator(url, migrationPlans, planSchedule);

const _putMigrationPlansActionCreator = (url, planId, migrationPlans, planSchedule) => dispatch =>
dispatch({
type: POST_V2V_MIGRATION_PLANS,
payload: new Promise((resolve, reject) => {
API.put(`${url}/${planId}`, migrationPlans)
.then(response => {
resolve(response);
if (planSchedule === 'migration_plan_now') {
postMigrationRequestsAction(response, dispatch);
}
})
.catch(e => reject(e));
})
});

export const putMigrationPlansAction = (url, migrationPlans, planSchedule) =>
_putMigrationPlansActionCreator(url, migrationPlans, planSchedule);
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import PlanWizardResultsStep from './PlanWizardResultsStep';
import * as PlanWizardResultsStepActions from './PlanWizardResultsStepActions';

import reducer from './PlanWizardResultsStepReducer';
import { findEditingPlan } from '../../PlanWizardSelectors';

export const reducers = { planWizardResultsStep: reducer };

const mapStateToProps = ({ planWizardResultsStep, planWizard }, ownProps) => ({
const mapStateToProps = (
{ planWizardResultsStep, planWizard, overview: { transformationPlans, editingPlanId } },
ownProps
) => ({
...planWizardResultsStep,
...planWizard,
...ownProps.data
...ownProps.data,
editingPlan: findEditingPlan(transformationPlans, editingPlanId)
});

const mergeProps = (stateProps, dispatchProps, ownProps) => Object.assign(stateProps, ownProps.data, dispatchProps);
Expand Down

0 comments on commit 3e84233

Please sign in to comment.