fix(studio): apply replica compute recommendation

This commit is contained in:
Danny White committed 2026-08-21 11:33:03 +10:00
1 parent 9febbab71b
commit bb6d39843a
2 files changed
+36 -3

No files matched your search

@@ -375,14 +375,17 @@ export function DiskManagementForm({
// Apply the recommendation only after the sheet's close lifecycle has completed.
useEffect(() => {
if (!recommendedCompute || !isSuccess) return
// The compute add-on supplies the option. Keep the recommendation pending
// until disk attributes have initialised the form, so a later reset cannot
// overwrite it. Other infrastructure requests are unrelated to this handoff.
if (!recommendedCompute || !isAddonsSuccess) return
form.setValue('computeSize', recommendedCompute, {
shouldDirty: true,
shouldValidate: true,
})
void form.trigger(['provisionedIOPS', 'throughput'])
onRecommendedComputeApplied?.()
if (isDiskAttributesSuccess) onRecommendedComputeApplied?.()
const element = computeSettingsRef.current
if (!element) return
@@ -404,7 +407,8 @@ export function DiskManagementForm({
mainScrollContainer.scrollTo({ top: Math.max(0, top), behavior: 'smooth' })
}, [
form,
isSuccess,
isAddonsSuccess,
isDiskAttributesSuccess,
mainScrollContainer,
onRecommendedComputeApplied,
recommendedCompute,
@@ -0,0 +1,29 @@
import { screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, test, vi } from 'vitest'
import { AddReadReplicaSheet } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet'
import { customRender } from '@/tests/lib/custom-render'
vi.mock('@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm', () => ({
ReadReplicaForm: ({ onRecommendCompute }: { onRecommendCompute: (size: 'ci_small') => void }) => (
<button type="button" tabIndex={0} onClick={() => onRecommendCompute('ci_small')}>
Change to Small compute
</button>
),
}))
describe('AddReadReplicaSheet', () => {
test('hands the recommendation off after closing the sheet', async () => {
const user = userEvent.setup()
const onRecommendCompute = vi.fn()
customRender(<AddReadReplicaSheet onRecommendCompute={onRecommendCompute} />, {
nuqs: { searchParams: { addReplica: 'true' } },
})
await user.click(screen.getByRole('button', { name: 'Change to Small compute' }))
await waitFor(() => expect(onRecommendCompute).toHaveBeenCalledWith('ci_small'))
})
})