Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(studio): allow deleting a branch from general settings page (#47677)

Han Qiaoce81c2f6ecf3
diff --git a/apps/studio/components/interfaces/BranchManagement/DeleteBranchModal.tsx b/apps/studio/components/interfaces/BranchManagement/DeleteBranchModal.tsx
new file mode 100644
index 00000000000..9968cf84bc5
--- /dev/null
+++ b/apps/studio/components/interfaces/BranchManagement/DeleteBranchModal.tsx
@@ -0,0 +1,52 @@
+import { toast } from 'sonner'
+import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
+
+import { useBranchDeleteMutation } from '@/data/branches/branch-delete-mutation'
+import { type Branch } from '@/data/branches/branches-query'
+
+export interface DeleteBranchModalProps {
+ open: boolean
+ branch?: Branch
+ onClose: () => void
+ onSuccess?: () => void
+}
+
+export const DeleteBranchModal = ({ open, branch, onClose, onSuccess }: DeleteBranchModalProps) => {
+ const { mutate: deleteBranch, isPending: isDeleting } = useBranchDeleteMutation({
+ onSuccess: () => {
+ toast.success('Successfully deleted branch')
+ onSuccess?.()
+ onClose()
+ },
+ })
+
+ const onConfirmDeleteBranch = () => {
+ if (!branch) return console.error('No branch selected')
+
+ const { project_ref: branchRef, parent_project_ref: projectRef } = branch
+ deleteBranch({ branchRef, projectRef })
+ }
+
+ return (
+ <TextConfirmModal
+ variant="destructive"
+ visible={open}
+ onCancel={() => onClose()}
+ onConfirm={() => onConfirmDeleteBranch()}
+ loading={isDeleting}
+ title="Delete branch"
+ confirmLabel="Delete branch"
+ confirmPlaceholder="Type in name of branch"
+ confirmString={branch?.name ?? ''}
+ alert={{
+ title: 'You cannot recover this branch once deleted',
+ }}
+ text={
+ <>
+ This will delete your database preview branch{' '}
+ <span className="text-bold text-foreground">{branch?.name}</span>.
+ </>
+ }
+ />
+ )
+}
diff --git a/apps/studio/components/interfaces/BranchManagement/Overview.tsx b/apps/studio/components/interfaces/BranchManagement/Overview.tsx
index 05761892bc8..6b797f75cc2 100644
--- a/apps/studio/components/interfaces/BranchManagement/Overview.tsx
+++ b/apps/studio/components/interfaces/BranchManagement/Overview.tsx
@@ -29,6 +29,7 @@ import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'
import { BranchLoader, BranchManagementSection, BranchRow, BranchRowLoader } from './BranchPanels'
import { EditBranchModal } from './EditBranchModal'
import { PreviewBranchesEmptyState } from './EmptyStates'
+import { SwitchToPreviewModal } from './SwitchToPreviewModal'
import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper'
import { useBranchPushMutation } from '@/data/branches/branch-push-mutation'
@@ -330,6 +331,7 @@ const PreviewBranchActions = ({
<DropdownMenuTrigger asChild>
<Button
variant="text"
+ aria-label="More branch actions"
icon={<MoreVertical />}
className="px-1"
onClick={(e) => e.stopPropagation()}
@@ -551,19 +553,11 @@ const PreviewBranchActions = ({
</p>
</ConfirmationModal>
- <ConfirmationModal
- variant="warning"
- visible={showPersistentBranchDeleteConfirmationModal}
- confirmLabel="Switch to preview"
- title="Branch must be switched to preview before deletion"
- loading={isUpdatingBranch}
- onCancel={() => setShowPersistentBranchDeleteConfirmationModal(false)}
- onConfirm={onTogglePersistent}
- >
- <p className="text-sm text-foreground-light">
- You must switch the branch "{branch.name}" to preview before deleting it.
- </p>
- </ConfirmationModal>
+ <SwitchToPreviewModal
+ branch={branch}
+ open={showPersistentBranchDeleteConfirmationModal}
+ onClose={() => setShowPersistentBranchDeleteConfirmationModal(false)}
+ />
<EditBranchModal
branch={branch}
diff --git a/apps/studio/components/interfaces/BranchManagement/SwitchToPreviewModal.tsx b/apps/studio/components/interfaces/BranchManagement/SwitchToPreviewModal.tsx
new file mode 100644
index 00000000000..d86c42a8389
--- /dev/null
+++ b/apps/studio/components/interfaces/BranchManagement/SwitchToPreviewModal.tsx
@@ -0,0 +1,49 @@
+import { toast } from 'sonner'
+import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'
+
+import { useBranchUpdateMutation } from '@/data/branches/branch-update-mutation'
+import { type Branch } from '@/data/branches/branches-query'
+import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
+
+interface SwitchToPreviewModalProps {
+ open: boolean
+ branch?: Branch
+ onClose: () => void
+}
+
+export const SwitchToPreviewModal = ({ open, branch, onClose }: SwitchToPreviewModalProps) => {
+ const { data: project } = useSelectedProjectQuery()
+
+ const branchRef = project?.ref
+ const projectRef = project?.parent_project_ref
+
+ const { mutate: updateBranch, isPending: isUpdatingBranch } = useBranchUpdateMutation({
+ onSuccess() {
+ toast.success('Successfully updated branch')
+ onClose()
+ },
+ })
+
+ const onTogglePersistent = () => {
+ if (branchRef === undefined || projectRef === undefined || branch === undefined) {
+ return console.error('Branch metadata is required')
+ }
+ updateBranch({ branchRef, projectRef, persistent: !branch.persistent })
+ }
+
+ return (
+ <ConfirmationModal
+ variant="default"
+ visible={open}
+ confirmLabel="Switch to preview"
+ title="Switch branch to preview before deleting"
+ loading={isUpdatingBranch}
+ onCancel={() => onClose()}
+ onConfirm={onTogglePersistent}
+ >
+ <p className="text-sm text-foreground-light">
+ You must switch the branch "{branch?.name}" to preview before deleting it.
+ </p>
+ </ConfirmationModal>
+ )
+}
diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
index 7d7f161e372..95e1b1f34a4 100644
--- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
+++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
@@ -25,10 +25,14 @@ import {
} from '@/data/custom-domains/custom-domains-query'
import { useProjectAddonsQuery } from '@/data/subscriptions/project-addons-query'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
+import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
export const CustomDomainConfig = () => {
const { ref } = useParams()
+ const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
+ const isBranch = Boolean(project?.parent_project_ref)
+ const entityLabel = isBranch ? 'branch' : 'project'
const customDomainsDisabledDueToQuota = useFlag('customDomainsDisabledDueToQuota')
@@ -89,7 +93,7 @@ export const CustomDomainConfig = () => {
? 'We are working with our upstream DNS provider before we are able to sign up new custom domains. Please check back in a few hours.'
: plan === 'free'
? 'Paid Plans come with free vanity subdomains or Custom Domains for an additional $10/month per domain.'
- : 'To configure a custom domain for your project, please enable the add-on. Each Custom Domain costs $10 per month.'
+ : `To configure a custom domain for your ${entityLabel}, please enable the add-on. Each Custom Domain costs $10 per month.`
}
addon="customDomain"
source="customDomain"
diff --git a/apps/studio/components/interfaces/Settings/General/DeleteBranchPanel.tsx b/apps/studio/components/interfaces/Settings/General/DeleteBranchPanel.tsx
new file mode 100644
index 00000000000..7521c5556a4
--- /dev/null
+++ b/apps/studio/components/interfaces/Settings/General/DeleteBranchPanel.tsx
@@ -0,0 +1,121 @@
+import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { useRouter } from 'next/router'
+import { useState } from 'react'
+import { Alert, AlertDescription, AlertTitle, CriticalIcon } from 'ui'
+import {
+ PageSection,
+ PageSectionContent,
+ PageSectionDescription,
+ PageSectionMeta,
+ PageSectionSummary,
+ PageSectionTitle,
+} from 'ui-patterns/PageSection'
+
+import { DeleteBranchModal } from '../../BranchManagement/DeleteBranchModal'
+import { SwitchToPreviewModal } from '../../BranchManagement/SwitchToPreviewModal'
+import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
+import { useBranchesQuery } from '@/data/branches/branches-query'
+import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
+import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
+import { useTrack } from '@/lib/telemetry/track'
+
+export const DeleteBranchPanel = () => {
+ const router = useRouter()
+ const track = useTrack()
+ const { data: project } = useSelectedProjectQuery()
+
+ const branchRef = project?.ref
+ const projectRef = project?.parent_project_ref
+
+ const [showDeleteModal, setShowDeleteModal] = useState(false)
+ const [showSwitchToPreviewModal, setShowSwitchToPreviewModal] = useState(false)
+
+ const { can: canDeleteBranches } = useAsyncCheckPermissions(
+ PermissionAction.DELETE,
+ 'preview_branches'
+ )
+
+ const { data: branches } = useBranchesQuery({ projectRef })
+ const branch = branches?.find((b) => b.project_ref === branchRef)
+ const isBranchMetadataReady =
+ branchRef !== undefined && projectRef !== undefined && branch !== undefined
+ const isPersistentBranch = Boolean(branch?.persistent)
+
+ const onClickDelete = () => {
+ if (!isBranchMetadataReady) return
+
+ if (isPersistentBranch) {
+ setShowSwitchToPreviewModal(true)
+ } else {
+ setShowDeleteModal(true)
+ }
+ }
+
+ if (project === undefined) return null
+
+ return (
+ <PageSection id="delete-branch">
+ <PageSectionMeta>
+ <PageSectionSummary>
+ <PageSectionTitle>Delete branch</PageSectionTitle>
+ <PageSectionDescription>
+ Permanently remove this branch and its database
+ </PageSectionDescription>
+ </PageSectionSummary>
+ </PageSectionMeta>
+
+ <PageSectionContent>
+ <Alert variant="destructive">
+ <CriticalIcon />
+ <AlertTitle>Deleting this branch will also remove its database.</AlertTitle>
+ <AlertDescription>
+ Make sure you have made a backup if you want to keep your data.
+ </AlertDescription>
+ <div className="mt-2">
+ <ButtonTooltip
+ variant="danger"
+ disabled={!canDeleteBranches || !isBranchMetadataReady}
+ onClick={onClickDelete}
+ tooltip={{
+ content: {
+ side: 'bottom',
+ text: !canDeleteBranches
+ ? 'You need additional permissions to delete this branch'
+ : !isBranchMetadataReady
+ ? 'Branch details are still loading'
+ : undefined,
+ },
+ }}
+ >
+ Delete branch
+ </ButtonTooltip>
+ </div>
+ </Alert>
+ </PageSectionContent>
+
+ <DeleteBranchModal
+ branch={branch}
+ open={showDeleteModal}
+ onClose={() => setShowDeleteModal(false)}
+ onSuccess={() => {
+ setShowDeleteModal(false)
+ track(
+ 'branch_delete_button_clicked',
+ {
+ branchType: isPersistentBranch ? 'persistent' : 'preview',
+ origin: 'settings_page',
+ },
+ { project: projectRef }
+ )
+ router.push(`/project/${projectRef}/branches`)
+ }}
+ />
+
+ <SwitchToPreviewModal
+ branch={branch}
+ open={showSwitchToPreviewModal}
+ onClose={() => setShowSwitchToPreviewModal(false)}
+ />
+ </PageSection>
+ )
+}
diff --git a/apps/studio/components/interfaces/Settings/General/General.tsx b/apps/studio/components/interfaces/Settings/General/General.tsx
index 8525945abb4..f804a93bbed 100644
--- a/apps/studio/components/interfaces/Settings/General/General.tsx
+++ b/apps/studio/components/interfaces/Settings/General/General.tsx
@@ -1,6 +1,6 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { IS_PLATFORM } from 'common'
+import { IS_PLATFORM, useParams } from 'common'
import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import { Button, Card, CardContent, CardFooter, Form, FormControl, FormField, Input } from 'ui'
@@ -21,6 +21,7 @@ import { AVAILABLE_REPLICA_REGIONS } from '../Infrastructure/InfrastructureConfi
import { ProjectAccessSection } from './ProjectAccessSection'
import { DocsButton } from '@/components/ui/DocsButton'
import { InlineLink } from '@/components/ui/InlineLink'
+import { useBranchesQuery } from '@/data/branches/branches-query'
import { useProjectUpdateMutation } from '@/data/projects/project-update-mutation'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useDeploymentMode } from '@/hooks/misc/useDeploymentMode'
@@ -28,8 +29,17 @@ import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { DOCS_URL } from '@/lib/constants'
export const General = () => {
+ const { ref } = useParams()
const { data: project } = useSelectedProjectQuery()
const isBranch = Boolean(project?.parent_project_ref)
+ const entityLabel = isBranch ? 'Branch' : 'Project'
+
+ const { data: branches } = useBranchesQuery(
+ { projectRef: project?.parent_project_ref },
+ { enabled: isBranch }
+ )
+ const branch = branches?.find((x) => x.project_ref === ref)
+ const projectName = isBranch ? branch?.name : project?.name
const { can: canUpdateProject } = useAsyncCheckPermissions(PermissionAction.UPDATE, 'projects', {
resource: {
@@ -43,7 +53,7 @@ export const General = () => {
name: z.string().trim().min(3, 'Project name must be at least 3 characters long'),
})
- const defaultValues = { name: project?.name ?? '' }
+ const defaultValues = { name: projectName ?? '' }
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues,
@@ -170,14 +180,14 @@ export const General = () => {
render={({ field }) => (
<FormItemLayout
layout="flex-row-reverse"
- label="Project name"
+ label={`${entityLabel} name`}
description="Displayed throughout the dashboard."
className="[&>div]:md:w-1/2"
>
<FormControl>
<Input
{...field}
- disabled={isBranch || !canUpdateProject}
+ readOnly={isBranch || !canUpdateProject}
autoComplete="off"
/>
</FormControl>
@@ -186,10 +196,25 @@ export const General = () => {
/>
</CardContent>
+ {isBranch && (
+ <CardContent>
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label={`${entityLabel} type`}
+ description="Preview or persistent"
+ className="[&>div]:md:w-1/2 [&>div>div]:md:w-full"
+ >
+ <FormControl>
+ <Input readOnly value={branch?.persistent ? 'Persistent' : 'Preview'} />
+ </FormControl>
+ </FormItemLayout>
+ </CardContent>
+ )}
+
<CardContent>
<FormItemLayout
layout="flex-row-reverse"
- label="Project ID"
+ label={`${entityLabel} ID`}
description="Reference used in APIs and URLs."
className="[&>div]:md:w-1/2 [&>div>div]:md:w-full"
>
@@ -202,7 +227,7 @@ export const General = () => {
<CardContent>
<FormItemLayout
layout="flex-row-reverse"
- label="Project region"
+ label={`${entityLabel} region`}
description={regionLabel?.name}
className="[&>div]:md:w-1/2 [&>div>div]:md:w-full"
>
diff --git a/apps/studio/components/interfaces/Settings/General/Infrastructure/PauseProjectButton.tsx b/apps/studio/components/interfaces/Settings/General/Infrastructure/PauseProjectButton.tsx
index a2bb05837e7..129623c664c 100644
--- a/apps/studio/components/interfaces/Settings/General/Infrastructure/PauseProjectButton.tsx
+++ b/apps/studio/components/interfaces/Settings/General/Infrastructure/PauseProjectButton.tsx
@@ -23,7 +23,7 @@ import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganizati
import { useIsProjectActive, useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { PROJECT_STATUS } from '@/lib/constants'
-const PauseProjectButton = () => {
+export const PauseProjectButton = () => {
const router = useRouter()
const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
@@ -42,6 +42,7 @@ const PauseProjectButton = () => {
const isFreePlan = organization?.plan.id === 'free'
const isBranch = Boolean(project?.parent_project_ref)
+ const entityLabel = isBranch ? 'branch' : 'project'
const { hasAccess: projectPausingAllowedInOrg } = useCheckEntitlements(
'project_pausing',
organization?.slug
@@ -57,7 +58,7 @@ const PauseProjectButton = () => {
const requestPauseProject = () => {
if (!canPauseProject) {
- return toast.error('You do not have the required permissions to pause this project')
+ return toast.error(`You do not have the required permissions to pause this ${entityLabel}`)
}
pauseProject({ ref: projectRef })
}
@@ -70,14 +71,19 @@ const PauseProjectButton = () => {
!isProjectActive
function getTooltipText() {
- if (isPaused) return 'Your project is already paused'
- if (!canPauseProject) return 'You need additional permissions to pause this project'
- if (isProjectUnhealthy)
- return 'Your project is unhealthy — restart it instead to restore normal operation'
- if (!isProjectActive) return 'Unable to pause project as project is not active'
- if (!isBranch && !projectPausingAllowedInOrg && !isFreePlan)
+ if (isPaused) {
+ return `Your ${entityLabel} is already paused`
+ } else if (!canPauseProject) {
+ return `You need additional permissions to pause this ${entityLabel}`
+ } else if (isProjectUnhealthy) {
+ return `Your ${entityLabel} is unhealthy — restart it instead to restore normal operation`
+ } else if (!isProjectActive) {
+ return `Unable to pause ${entityLabel} as ${entityLabel} is not active`
+ } else if (!isBranch && !projectPausingAllowedInOrg && !isFreePlan) {
return 'Projects on a paid plan will always be running'
- return undefined
+ } else {
+ return undefined
+ }
}
return (
@@ -95,22 +101,22 @@ const PauseProjectButton = () => {
},
}}
>
- Pause project
+ Pause {entityLabel}
</ButtonTooltip>
<AlertDialog open={isModalOpen} onOpenChange={setIsModalOpen}>
<AlertDialogContent>
<AlertDialogHeader>
- <AlertDialogTitle>Pause project?</AlertDialogTitle>
+ <AlertDialogTitle>Pause {entityLabel}?</AlertDialogTitle>
<AlertDialogDescription>
- This project will be unavailable while paused. Paused projects can be resumed for 90
- days. After that, backups remain available to download.
+ This {entityLabel} will be unavailable while paused. Paused {entityLabel} can be
+ resumed for 90 days. After that, backups remain available to download.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isPausing}>Cancel</AlertDialogCancel>
<AlertDialogAction disabled={isPausing} onClick={requestPauseProject} variant="danger">
- {isPausing ? 'Pausing project...' : 'Pause project'}
+ {isPausing ? `Pausing ${entityLabel}...` : `Pause ${entityLabel}`}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
@@ -118,5 +124,3 @@ const PauseProjectButton = () => {
</>
)
}
-
-export default PauseProjectButton
diff --git a/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx b/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx
index 6a2bf0ca9d4..72bf674119f 100644
--- a/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx
+++ b/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx
@@ -28,15 +28,19 @@ import {
import { PROJECT_STATUS } from '@/lib/constants'
import { type ResponseError } from '@/types'
-const RestartServerButton = () => {
+export const RestartServerButton = () => {
const router = useRouter()
const { data: project } = useSelectedProjectQuery()
const isProjectActive = useIsProjectActive()
+
+ const isBranch = Boolean(project?.parent_project_ref)
+ const entityLabel = isBranch ? 'branch' : 'project'
+ const entityLabelCapitalized = entityLabel.charAt(0).toUpperCase() + entityLabel.slice(1)
const canRestart = isProjectActive || project?.status === PROJECT_STATUS.ACTIVE_UNHEALTHY
const isAwsK8s = useIsAwsK8sCloudProvider()
const { setProjectStatus } = useSetProjectStatus()
- const [serviceToRestart, setServiceToRestart] = useState<'project' | 'database'>()
+ const [serviceToRestart, setServiceToRestart] = useState<'project' | 'branch' | 'database'>()
const { projectSettingsRestartProject } = useIsFeatureEnabled([
'project_settings:restart_project',
@@ -79,7 +83,7 @@ const RestartServerButton = () => {
restartProject({ ref: projectRef })
}
- const requestDatabaseRestart = async () => {
+ const requestDatabaseRestart = () => {
if (!canRestartProject) {
return toast.error('You do not have the required permissions to restart this project')
}
@@ -115,29 +119,30 @@ const RestartServerButton = () => {
projectRestartDisabled ||
isAwsK8s
}
- onClick={() => setServiceToRestart('project')}
+ onClick={() => setServiceToRestart(entityLabel)}
tooltip={{
content: {
side: 'bottom',
text: projectRestartDisabled
- ? 'Project restart is currently disabled'
+ ? `${entityLabelCapitalized} restart is currently disabled`
: !canRestartProject
- ? 'You need additional permissions to restart this project'
+ ? `You need additional permissions to restart this ${entityLabel}`
: !canRestart
- ? 'Unable to restart project as project is not active'
+ ? `Unable to restart ${entityLabel} as ${entityLabel} is not active`
: isAwsK8s
- ? 'Project restart is not supported for AWS (Revamped) projects'
+ ? `${entityLabelCapitalized} restart is not supported for AWS (Revamped) projects`
: undefined,
},
}}
>
- Restart project
+ Restart {entityLabel}
</ButtonTooltip>
{hasRestartDropdown && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="default"
+ aria-label={`Restart ${entityLabel}`}
className="shrink-0 rounded-l-none px-[4px] py-[5px] -ml-px"
icon={<ChevronDown />}
disabled={!canRestartProject}
@@ -191,16 +196,14 @@ const RestartServerButton = () => {
confirmLabelLoading="Restarting"
loading={isLoading}
onCancel={() => setServiceToRestart(undefined)}
- onConfirm={async () => {
- if (serviceToRestart === 'project') {
- await requestProjectRestart()
+ onConfirm={() => {
+ if (serviceToRestart === 'project' || serviceToRestart === 'branch') {
+ requestProjectRestart()
} else if (serviceToRestart === 'database') {
- await requestDatabaseRestart()
+ requestDatabaseRestart()
}
}}
/>
</>
)
}
-
-export default RestartServerButton
diff --git a/apps/studio/components/interfaces/Settings/General/Project.test.tsx b/apps/studio/components/interfaces/Settings/General/Project.test.tsx
index eeb3ead7ee7..82d5cce7184 100644
--- a/apps/studio/components/interfaces/Settings/General/Project.test.tsx
+++ b/apps/studio/components/interfaces/Settings/General/Project.test.tsx
@@ -48,11 +48,11 @@ vi.mock('@/components/interfaces/Project/ResumeProjectButton', () => ({
}))
vi.mock('./Infrastructure/PauseProjectButton', () => ({
- default: () => <div>PauseProjectButton</div>,
+ PauseProjectButton: () => <div>PauseProjectButton</div>,
}))
vi.mock('./Infrastructure/RestartServerButton', () => ({
- default: () => <div>RestartServerButton</div>,
+ RestartServerButton: () => <div>RestartServerButton</div>,
}))
vi.mock('@/data/projects/project-pause-status-query', () => ({
diff --git a/apps/studio/components/interfaces/Settings/General/Project.tsx b/apps/studio/components/interfaces/Settings/General/Project.tsx
index 3d3df0799c0..2af66db00af 100644
--- a/apps/studio/components/interfaces/Settings/General/Project.tsx
+++ b/apps/studio/components/interfaces/Settings/General/Project.tsx
@@ -9,8 +9,8 @@ import {
PageSectionTitle,
} from 'ui-patterns/PageSection'
-import PauseProjectButton from './Infrastructure/PauseProjectButton'
-import RestartServerButton from './Infrastructure/RestartServerButton'
+import { PauseProjectButton } from './Infrastructure/PauseProjectButton'
+import { RestartServerButton } from './Infrastructure/RestartServerButton'
import { ResumeProjectButton } from '@/components/interfaces/Project/ResumeProjectButton'
import { useProjectPauseStatusQuery } from '@/data/projects/project-pause-status-query'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
@@ -19,7 +19,11 @@ import { PROJECT_STATUS } from '@/lib/constants'
export const Project = () => {
const { data: project } = useSelectedProjectQuery()
+ const isBranch = Boolean(project?.parent_project_ref)
const isPaused = project?.status === PROJECT_STATUS.INACTIVE
+ const entityLabel = isBranch ? 'branch' : 'project'
+ const entityLabelCapitalized = isBranch ? 'Branch' : 'Project'
+
const { projectSettingsRestartProject } = useIsFeatureEnabled([
'project_settings:restart_project',
])
@@ -34,30 +38,30 @@ export const Project = () => {
const primaryActionLabel = isPaused
? shouldShowDashboardLink
- ? 'View project dashboard'
- : 'Resume project'
+ ? `View ${entityLabel} dashboard`
+ : `Resume ${entityLabel}`
: projectSettingsRestartProject
- ? 'Restart project'
+ ? `Restart ${entityLabel}`
: 'Restart database'
const primaryActionDescription = isPaused
? isPauseStatusSuccess && !pauseStatus.can_restore
- ? 'This project can no longer be resumed here. Open the dashboard to download backups and view recovery options.'
+ ? `This ${entityLabel} can no longer be resumed here. Open the dashboard to download backups and view recovery options.`
: isPauseStatusError
- ? 'Open the dashboard to manage this paused project.'
- : 'Bring your paused project back online.'
- : 'Your project will not be available for a few minutes.'
+ ? `Open the dashboard to manage this paused ${entityLabel}.`
+ : `Bring your paused ${entityLabel} back online.`
+ : `Your ${entityLabel} will not be available for a few minutes.`
return (
<>
<PageSection id="restart-project">
<PageSectionMeta>
<PageSectionSummary>
- <PageSectionTitle>Project availability</PageSectionTitle>
+ <PageSectionTitle>{entityLabelCapitalized} availability</PageSectionTitle>
<PageSectionDescription>
{isPaused
- ? 'Resume your paused project or review recovery options'
- : 'Restart or pause your project when performing maintenance'}
+ ? `Resume your paused ${entityLabel} or review recovery options`
+ : `Restart or pause your ${entityLabel} when performing maintenance`}
</PageSectionDescription>
</PageSectionSummary>
</PageSectionMeta>
@@ -84,6 +88,7 @@ export const Project = () => {
)}
</div>
</CardContent>
+
{!isPaused && (
<CardContent>
<div
@@ -91,10 +96,10 @@ export const Project = () => {
id="pause-project"
>
<div>
- <p className="text-sm">Pause project</p>
+ <p className="text-sm">Pause {entityLabel}</p>
<div className="max-w-[420px]">
<p className="text-sm text-foreground-light">
- Your project will not be accessible while it is paused.
+ Your {entityLabel} will not be accessible while it is paused.
</p>
</div>
</div>
diff --git a/apps/studio/pages/project/[ref]/branches/index.tsx b/apps/studio/pages/project/[ref]/branches/index.tsx
index 102a0783c76..f16f58b939c 100644
--- a/apps/studio/pages/project/[ref]/branches/index.tsx
+++ b/apps/studio/pages/project/[ref]/branches/index.tsx
@@ -4,9 +4,9 @@ import { partition } from 'lodash'
import { MessageCircle } from 'lucide-react'
import { useRouter } from 'next/router'
import { useState, type PropsWithChildren } from 'react'
-import { toast } from 'sonner'
import { Button } from 'ui'
+import { DeleteBranchModal } from '@/components/interfaces/BranchManagement/DeleteBranchModal'
import { Overview } from '@/components/interfaces/BranchManagement/Overview'
import BranchLayout from '@/components/layouts/BranchLayout/BranchLayout'
import { DefaultLayout } from '@/components/layouts/DefaultLayout'
@@ -16,8 +16,6 @@ import { AlertError } from '@/components/ui/AlertError'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { DocsButton } from '@/components/ui/DocsButton'
import { NoPermission } from '@/components/ui/NoPermission'
-import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper'
-import { useBranchDeleteMutation } from '@/data/branches/branch-delete-mutation'
import { Branch, useBranchesQuery } from '@/data/branches/branches-query'
import { useGitHubConnectionsQuery } from '@/data/integrations/github-connections-query'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
@@ -79,13 +77,6 @@ const BranchesPage: NextPageWithLayout = () => {
const isGithubConnected = githubConnection !== undefined
- const { mutate: deleteBranch, isPending: isDeleting } = useBranchDeleteMutation({
- onSuccess: () => {
- toast.success('Successfully deleted branch')
- setSelectedBranchToDelete(undefined)
- },
- })
-
const generateCreatePullRequestURL = (branch?: string) => {
if (githubConnection === undefined) return 'https://github.com'
@@ -94,33 +85,6 @@ const BranchesPage: NextPageWithLayout = () => {
: `https://github.com/${githubConnection.repository.name}/compare`
}
- const onConfirmDeleteBranch = () => {
- if (selectedBranchToDelete === undefined) return console.error('No branch selected')
- const {
- project_ref: branchRef,
- parent_project_ref: projectRef,
- persistent,
- } = selectedBranchToDelete
- deleteBranch(
- { branchRef, projectRef },
- {
- onSuccess: () => {
- if (branchRef === ref) {
- router.push(`/project/${projectRef}/branches`)
- }
- track(
- 'branch_delete_button_clicked',
- {
- branchType: persistent ? 'persistent' : 'preview',
- origin: 'branches_page',
- },
- { project: projectRef }
- )
- },
- }
- )
- }
-
return (
<>
<ScaffoldContainer>
@@ -165,25 +129,23 @@ const BranchesPage: NextPageWithLayout = () => {
</ScaffoldSection>
</ScaffoldContainer>
- <TextConfirmModal
- variant="warning"
- visible={selectedBranchToDelete !== undefined}
- onCancel={() => setSelectedBranchToDelete(undefined)}
- onConfirm={() => onConfirmDeleteBranch()}
- loading={isDeleting}
- title="Delete branch"
- confirmLabel="Delete branch"
- confirmPlaceholder="Type in name of branch"
- confirmString={selectedBranchToDelete?.name ?? ''}
- alert={{
- title: 'You cannot recover this branch once deleted',
+ <DeleteBranchModal
+ branch={selectedBranchToDelete}
+ open={!!selectedBranchToDelete}
+ onClose={() => setSelectedBranchToDelete(undefined)}
+ onSuccess={() => {
+ if (selectedBranchToDelete?.project_ref === ref) {
+ router.push(`/project/${projectRef}/branches`)
+ }
+ track(
+ 'branch_delete_button_clicked',
+ {
+ branchType: selectedBranchToDelete?.persistent ? 'persistent' : 'preview',
+ origin: 'branches_page',
+ },
+ { project: projectRef }
+ )
}}
- text={
- <>
- This will delete your database preview branch{' '}
- <span className="text-bold text-foreground">{selectedBranchToDelete?.name}</span>.
- </>
- }
/>
</>
)
diff --git a/apps/studio/pages/project/[ref]/settings/general.tsx b/apps/studio/pages/project/[ref]/settings/general.tsx
index e043eabef87..92bd8b01719 100644
--- a/apps/studio/pages/project/[ref]/settings/general.tsx
+++ b/apps/studio/pages/project/[ref]/settings/general.tsx
@@ -11,6 +11,7 @@ import {
import { subscriptionHasHipaaAddon } from '@/components/interfaces/Billing/Subscription/Subscription.utils'
import { ComplianceConfig } from '@/components/interfaces/Settings/General/ComplianceConfig/ProjectComplianceMode'
import { CustomDomainConfig } from '@/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig'
+import { DeleteBranchPanel } from '@/components/interfaces/Settings/General/DeleteBranchPanel'
import { DeleteProjectPanel } from '@/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectPanel'
import { General } from '@/components/interfaces/Settings/General/General'
import { Project } from '@/components/interfaces/Settings/General/Project'
@@ -58,7 +59,7 @@ const ProjectSettings: NextPageWithLayout = () => {
{!isBranch && hasHipaaAddon && <ComplianceConfig />}
{projectSettingsCustomDomains && <CustomDomainConfig />}
{!isBranch && projectTransferEnabled && <TransferProjectPanel />}
- {!isBranch && <DeleteProjectPanel />}
+ {isBranch ? <DeleteBranchPanel /> : <DeleteProjectPanel />}
</>
)}
</PageContainer>
diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.ts
index 659541bcc9e..22cfaba8675 100644
--- a/packages/common/telemetry-constants.ts
+++ b/packages/common/telemetry-constants.ts
@@ -1788,7 +1788,7 @@ export interface BranchDeleteButtonClickedEvent {
/**
* Where the delete action was initiated from
*/
- origin: 'branches_page' | 'merge_page'
+ origin: 'branches_page' | 'merge_page' | 'settings_page'
}
groups: TelemetryGroups
}