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

Commit

Permalink
Fix Advanced Options Step Table selected count getting confused durin…
Browse files Browse the repository at this point in the history
…g edit
  • Loading branch information
mturley committed Sep 21, 2018
1 parent 1cfb858 commit e8d937c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ 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) => {
export const getVmIdsWithProperty = (editingPlan, property, vmStepSelectedVms) => {
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);
const vmIds = actionsWithProperty.map(action => action.vm_id);
return vmIds.filter(id => vmStepSelectedVms.some(vm => vm.id === id));
};

export const preselectPlaybooksForVms = (editingPlan, vms) => {
const vmIdsWithPreService = getVmIdsWithProperty(editingPlan, 'pre_service');
const vmIdsWithPostService = getVmIdsWithProperty(editingPlan, 'post_service');
const vmIdsWithPreService = getVmIdsWithProperty(editingPlan, 'pre_service', vms);
const vmIdsWithPostService = getVmIdsWithProperty(editingPlan, 'post_service', vms);
return vms.map(vm => ({
...vm,
preMigration: vmIdsWithPreService.some(id => id === vm.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ const mapStateToProps = (
: [...planWizardVMStep.preselected_vms, ...validVmsDeduped];

const configInfo = editingPlan && editingPlan.options && editingPlan.options.config_info;
const vmStepSelectedVms = getVMStepSelectedVms(allVms, selectedVms);

return {
...planWizardAdvancedOptionsStep,
...ownProps.data,
advancedOptionsStepForm,
vmStepSelectedVms: getVMStepSelectedVms(allVms, selectedVms),
vmStepSelectedVms,
initialValues: {
playbookVms: {
preMigration: editingPlan ? getVmIdsWithProperty(editingPlan, 'pre_service') : [],
postMigration: editingPlan ? getVmIdsWithProperty(editingPlan, 'post_service') : []
preMigration: editingPlan ? getVmIdsWithProperty(editingPlan, 'pre_service', vmStepSelectedVms) : [],
postMigration: editingPlan ? getVmIdsWithProperty(editingPlan, 'post_service', vmStepSelectedVms) : []
},
preMigrationPlaybook: editingPlan ? configInfo.pre_service_id : '',
postMigrationPlaybook: editingPlan ? configInfo.post_service_id : ''
Expand Down

0 comments on commit e8d937c

Please sign in to comment.