From de7aa03230b63f40be53086d31d3569dc5ba92c9 Mon Sep 17 00:00:00 2001 From: Xuanqi He Date: Tue, 8 Oct 2024 16:13:01 -0400 Subject: [PATCH] fix: Retain ODCR settings when copying clusters and navigating steps - Ensure CapacityReservationTarget fields (CapacityReservationId and CapacityReservationResourceGroupArn) are retained when creating a new cluster from an existing one. - Fix issue where CapacityReservationTarget values were cleared upon navigating back and forth in the wizard. --- .../Queues/MultiInstanceComputeResource.tsx | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/frontend/src/old-pages/Configure/Queues/MultiInstanceComputeResource.tsx b/frontend/src/old-pages/Configure/Queues/MultiInstanceComputeResource.tsx index c0745b51..ab6846be 100644 --- a/frontend/src/old-pages/Configure/Queues/MultiInstanceComputeResource.tsx +++ b/frontend/src/old-pages/Configure/Queues/MultiInstanceComputeResource.tsx @@ -209,29 +209,35 @@ export function ComputeResource({ [efaInstances, instanceTypePath, setEnableEFA], ) - const [odcrCbOption, setOdcrCbOption] = React.useState('none') - const [odcrCbInput, setOdcrCbInput] = React.useState('') - - const capacityReservationTargetPath = useMemo( - () => [...path, 'CapacityReservationTarget'], - [path], + const initialCapacityReservationTarget = useState([...path, 'CapacityReservationTarget']) || {} + const [odcrCbOption, setOdcrCbOption] = React.useState( + initialCapacityReservationTarget.CapacityReservationId + ? 'capacityReservationId' + : initialCapacityReservationTarget.CapacityReservationResourceGroupArn + ? 'capacityReservationResourceGroupArn' + : 'none' + ) + const [odcrCbInput, setOdcrCbInput] = React.useState( + initialCapacityReservationTarget.CapacityReservationId || + initialCapacityReservationTarget.CapacityReservationResourceGroupArn || + '' ) - React.useEffect(() => { + useEffect(() => { if (odcrCbOption === 'none') { - clearState(capacityReservationTargetPath) + clearState([...path, 'CapacityReservationTarget']) } else { const updateData = { CapacityReservationId: odcrCbOption === 'capacityReservationId' ? odcrCbInput : undefined, CapacityReservationResourceGroupArn: odcrCbOption === 'capacityReservationResourceGroupArn' ? odcrCbInput : undefined, } - setState(capacityReservationTargetPath, updateData) + setState([...path, 'CapacityReservationTarget'], updateData) if (odcrCbOption === 'capacityReservationId') { clearState(instanceTypePath) } } - }, [odcrCbOption, odcrCbInput]) + }, [odcrCbOption, odcrCbInput, path, instanceTypePath]) return (