Skip to content

Commit

Permalink
fix: Retain ODCR settings when copying clusters and navigating steps
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
hehe7318 authored and gmarciani committed Oct 8, 2024
1 parent c2f0f11 commit 7d78e85
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<SpaceBetween direction="vertical" size="s">
Expand Down

0 comments on commit 7d78e85

Please sign in to comment.