Files
supabase/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/DropReplicaConfirmationModal.tsx
Stephen Morgan 3d966e3709 feat(studio): show PrivateLink resource IDs and use connection copy (#48967)
## What kind of change does this PR introduce?

Feature and docs

## What is the current behavior?

PrivateLink is labelled as an AWS account, and there is no way to tell
which resource configuration belongs to the primary vs a read replica.

Put simply: you’re not adding an AWS account. You’re adding a
connection. One AWS account can have multiple PrivateLink connections,
just to different databases, with more fields also coming soon.

Part of PRODSEC-238 and fixes SEC-939.

## What is the new behavior?

Each connection shows resource configuration IDs so primary and replica
are distinguishable. Customer-facing copy says **connection**. API paths
and AWS console labels still say association.

| Before | After |
| --- | --- |
| <img width="1452" height="496" alt="CleanShot 2026-08-14 at 12 33
49@2x"
src="https://github.com/user-attachments/assets/3b295136-0325-4587-9291-b5f01fc07806"
/> | <img width="1440" height="434" alt="CleanShot 2026-08-14 at 12 34
30@2x"
src="https://github.com/user-attachments/assets/dd6ba064-18e4-4969-9c76-e3b79ac9d288"
/> |
| <img width="846" height="912" alt="CleanShot 2026-08-14 at 12 33
28@2x"
src="https://github.com/user-attachments/assets/c4c6caca-a2f6-4516-99c7-ad7cf865f8ac"
/> | <img width="844" height="880" alt="CleanShot 2026-08-14 at 12 34
39@2x"
src="https://github.com/user-attachments/assets/f3874c6b-abdc-4ef8-84fa-141cd9150871"
/> |
| <img width="1448" height="560" alt="CleanShot 2026-08-14 at 12 33
10@2x"
src="https://github.com/user-attachments/assets/8ae734cb-ec1f-4e4e-acf7-f4de459296d1"
/> | <img width="1460" height="496" alt="CleanShot 2026-08-14 at 12 32
15@2x"
src="https://github.com/user-attachments/assets/883050d5-a6f1-44bd-8ebd-1513a2c41e9f"
/> |

## Additional context

First PR in a stacked PrivateLink series (#49084 onwards). See
https://github.com/supabase/supabase/pull/49030 for the end state, as it
may already include fixes you might propose.

## To test

- **Project Settings → Integrations → AWS PrivateLink.** Open **Add
connection**, or **View** an existing one. Confirm the UI says
connection, and that resource config IDs are copyable.
- **Docs preview → Platform → PrivateLink.** Procedure steps should say
Add connection / View connection.

---------

Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
2026-08-17 11:06:26 +10:00

110 lines
3.5 KiB
TypeScript

import { useQueryClient } from '@tanstack/react-query'
import { useParams } from 'common'
import { toast } from 'sonner'
import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'
import { REPLICA_STATUS } from './ReadReplicas.constants'
import { InlineLink } from '@/components/ui/InlineLink'
import { replicaKeys } from '@/data/read-replicas/keys'
import { useReadReplicaRemoveMutation } from '@/data/read-replicas/replica-remove-mutation'
import type { Database } from '@/data/read-replicas/replicas-query'
import { formatDatabaseID } from '@/data/read-replicas/replicas.utils'
interface DropReplicaConfirmationModalProps {
selectedReplica?: Database
onSuccess: () => void
onCancel: () => void
}
export const DropReplicaConfirmationModal = ({
selectedReplica,
onSuccess,
onCancel,
}: DropReplicaConfirmationModalProps) => {
const { ref: projectRef } = useParams()
const queryClient = useQueryClient()
const formattedId = formatDatabaseID(selectedReplica?.identifier ?? '')
const getRemoveReplicaErrorMessage = (message: string) => {
const isPrivateLinkAssociationError =
/private\s*link/i.test(message) && /association/i.test(message)
if (isPrivateLinkAssociationError) {
return (
<span>
Remove the replica{' '}
<InlineLink href={`/project/${projectRef}/settings/integrations`}>
PrivateLink connection
</InlineLink>{' '}
before dropping this read replica
</span>
)
}
return `Failed to remove read replica: ${message}`
}
const { mutate: removeReadReplica, isPending: isRemoving } = useReadReplicaRemoveMutation({
onSuccess: () => {
toast.success(`Tearing down read replica (ID: ${formattedId})`)
// [Joshen] Temporarily optimistic rendering until API supports immediate status update
queryClient.setQueriesData(
{ queryKey: replicaKeys.list(projectRef) },
(old: Database[] | undefined) => {
const updatedReplicas = old?.map((x) => {
if (x.identifier === selectedReplica?.identifier) {
return { ...x, status: REPLICA_STATUS.GOING_DOWN }
}
return x
})
return updatedReplicas
}
)
onSuccess()
onCancel()
},
onError: (error) => {
toast.error(getRemoveReplicaErrorMessage(error.message))
},
})
const onConfirmRemove = async () => {
if (!projectRef) return console.error('Project is required')
if (selectedReplica === undefined) return toast.error('No replica selected')
removeReadReplica({
projectRef,
identifier: selectedReplica.identifier,
invalidateReplicaQueries: true,
})
}
return (
<ConfirmationModal
variant="destructive"
size="medium"
loading={isRemoving}
visible={selectedReplica !== undefined}
title={`Confirm to drop selected replica? (ID: ${formattedId})`}
confirmLabel="Drop replica"
confirmLabelLoading="Dropping replica"
onCancel={() => onCancel()}
onConfirm={() => onConfirmRemove()}
alert={{
title: 'This action cannot be undone',
description: 'You may still deploy a new replica in this region thereafter',
}}
>
<p className="text-sm">Before deleting this replica, consider:</p>
<ul className="text-sm text-foreground-light py-1 list-disc mx-4 space-y-1">
<li>
Network traffic from this region may slow down, especially if you have no other replicas
in this region
</li>
</ul>
</ConfirmationModal>
)
}