Skip to content

Commit

Permalink
Merge pull request #692 from michaelkro/689-preserve-adv-options-step
Browse files Browse the repository at this point in the history
[#689] Preserve playbook selections
  • Loading branch information
AparnaKarve authored Oct 8, 2018
2 parents 2162f1a + 3c064e9 commit b4fa511
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class PlanWizard extends React.Component {
};

prevStep = () => {
const { resetVmStepAction, resetAdvancedOptionsStepAction, setMetadataWithBackButtonClickedAction } = this.props;
const { resetVmStepAction, setMetadataWithBackButtonClickedAction } = this.props;
const { activeStepIndex } = this.state;

const activeStep = this.getActiveWizardStep();
Expand All @@ -91,8 +91,6 @@ class PlanWizard extends React.Component {
if (activeStep.id === stepIDs.vmStep) {
// reset all vm step values if going back from that step
resetVmStepAction();
} else if (activeStep.id === stepIDs.advancedOptionsStep) {
resetAdvancedOptionsStepAction();
}
this.setState({ activeStepIndex: Math.max(activeStepIndex - 1, 0) });
};
Expand Down Expand Up @@ -292,7 +290,6 @@ PlanWizard.propTypes = {
setMigrationsFilterAction: PropTypes.func,
showConfirmModalAction: PropTypes.func,
hideConfirmModalAction: PropTypes.func,
resetAdvancedOptionsStepAction: PropTypes.func,
showAlertAction: PropTypes.func,
hideAlertAction: PropTypes.func,
alertText: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ import { Form, Spinner } from 'patternfly-react';

import PlanWizardAdvancedOptionsStepTable from './components/PlanWizardAdvancedOptionsStepTable/PlanWizardAdvancedOptionsStepTable';
import { BootstrapSelect } from '../../../../../common/forms/BootstrapSelect';
import { preselectPlaybooksForVms } from './helpers';
import { preselectPlaybooksForVms, applyPlaybookSelections, updatePlaybookSelections } from './helpers';

class PlanWizardAdvancedOptionsStep extends Component {
constructor(props) {
super(props);

if (props.vms.length === 0) {
if (props.pristine) {
if (!props.editingPlan) {
props.setVmsAction(props.vmStepSelectedVms);
} else {
props.setVmsAction(preselectPlaybooksForVms(props.editingPlan, props.vmStepSelectedVms));
}
} else {
const {
vmStepSelectedVms,
advancedOptionsStepForm: {
values: { playbookVms }
}
} = props;
props.change('playbookVms', updatePlaybookSelections(vmStepSelectedVms, playbookVms));
props.setVmsAction(applyPlaybookSelections(vmStepSelectedVms, playbookVms));
}
}

Expand Down Expand Up @@ -96,7 +105,8 @@ PlanWizardAdvancedOptionsStep.propTypes = {
setVmsAction: PropTypes.func,
vmStepSelectedVms: PropTypes.array,
change: PropTypes.func,
editingPlan: PropTypes.object
editingPlan: PropTypes.object,
pristine: PropTypes.bool
};

PlanWizardAdvancedOptionsStep.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@ export const preselectPlaybooksForVms = (editingPlan, vms) => {
postMigration: vmIdsWithPostService.some(id => id === vm.id)
}));
};

export const applyPlaybookSelections = (vms, playbookVms) =>
vms.map(vm => ({
...vm,
preMigration: playbookVms.preMigration.includes(vm.id),
postMigration: playbookVms.postMigration.includes(vm.id)
}));

export const updatePlaybookSelections = (vms, playbookVms) => {
const vmIds = vms.map(vm => vm.id);
return {
preMigration: playbookVms.preMigration.filter(id => vmIds.includes(id)),
postMigration: playbookVms.postMigration.filter(id => vmIds.includes(id))
};
};

0 comments on commit b4fa511

Please sign in to comment.