From e8d937cc7b0039f67b80a2872c99267e4734e4c4 Mon Sep 17 00:00:00 2001 From: Mike Turley Date: Thu, 13 Sep 2018 14:48:32 -0400 Subject: [PATCH] Fix Advanced Options Step Table selected count getting confused during edit --- .../components/PlanWizardAdvancedOptionsStep/helpers.js | 9 +++++---- .../components/PlanWizardAdvancedOptionsStep/index.js | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/javascript/react/screens/App/Overview/screens/PlanWizard/components/PlanWizardAdvancedOptionsStep/helpers.js b/app/javascript/react/screens/App/Overview/screens/PlanWizard/components/PlanWizardAdvancedOptionsStep/helpers.js index 0ba24d9ce4..0d4834d346 100644 --- a/app/javascript/react/screens/App/Overview/screens/PlanWizard/components/PlanWizardAdvancedOptionsStep/helpers.js +++ b/app/javascript/react/screens/App/Overview/screens/PlanWizard/components/PlanWizardAdvancedOptionsStep/helpers.js @@ -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), diff --git a/app/javascript/react/screens/App/Overview/screens/PlanWizard/components/PlanWizardAdvancedOptionsStep/index.js b/app/javascript/react/screens/App/Overview/screens/PlanWizard/components/PlanWizardAdvancedOptionsStep/index.js index f1d95bcfbe..1378847b0a 100644 --- a/app/javascript/react/screens/App/Overview/screens/PlanWizard/components/PlanWizardAdvancedOptionsStep/index.js +++ b/app/javascript/react/screens/App/Overview/screens/PlanWizard/components/PlanWizardAdvancedOptionsStep/index.js @@ -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 : ''