mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
Part 6 of 7 in a stack that splits #52331 into reviewable pieces. Resolves part of [FE-4693](https://linear.app/supabase/issue/FE-4693/pilot-migrate-branches-to-grants-8-endpoints-createbranchmodal). There are no functional changes beyond #52331, and the top of the stack is identical to it. See #52331 for the full rationale. ## Stack 1. #52372 Grant infra for branch variants 2. #52373 Branches list query 3. #52374 Page gates on the list grant 4. #52375 Branch creation 5. #52376 Branch read, delete, reset, and restore 6. 👉 #52377 Branch update and push 7. #52378 Branch diff and merge ## Changes The update and push mutations take grants. `Overview` (including "Switch to persistent", which previously had no check), `EditBranchModal`, `SwitchToPreviewModal`, `MergeRequestButton`, the merge-requests page, and the merge page use `useBranchGrant`. The "Update branch" button in `OutOfDateNotice` is disabled without push; previously it did nothing. The GitHub integration form blocks saving without the production-branch grant. Previously the connection was saved even when the branch request failed. ## Testing New `GitHubIntegrationConnectionForm` test.
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
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 { useBranchGrant } from '@/hooks/branches/useBranchGrant'
|
|
|
|
interface SwitchToPreviewModalProps {
|
|
open: boolean
|
|
branch?: Branch
|
|
onClose: () => void
|
|
}
|
|
|
|
export const SwitchToPreviewModal = ({ open, branch, onClose }: SwitchToPreviewModalProps) => {
|
|
const updateBranchGrant = useBranchGrant('PATCH /v1/branches/{branch_id_or_ref}', {
|
|
projectRef: branch?.parent_project_ref,
|
|
isDefault: branch?.is_default,
|
|
})
|
|
const { mutate: updateBranch, isPending: isUpdatingBranch } = useBranchUpdateMutation({
|
|
onSuccess() {
|
|
toast.success('Successfully updated branch')
|
|
onClose()
|
|
},
|
|
})
|
|
|
|
const onSwitchToPreview = () => {
|
|
if (branch === undefined || updateBranchGrant.status !== 'granted') return
|
|
updateBranch({
|
|
grant: updateBranchGrant.grant,
|
|
branchRef: branch.project_ref,
|
|
projectRef: branch.parent_project_ref,
|
|
persistent: false,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<ConfirmationModal
|
|
variant="default"
|
|
visible={open}
|
|
confirmLabel="Switch to preview"
|
|
title="Switch branch to preview before deleting"
|
|
loading={isUpdatingBranch}
|
|
disabled={branch === undefined || updateBranchGrant.status !== 'granted'}
|
|
onCancel={() => onClose()}
|
|
onConfirm={onSwitchToPreview}
|
|
>
|
|
<p className="text-sm text-foreground-light">
|
|
You must switch the branch "{branch?.name}" to preview before deleting it.
|
|
</p>
|
|
</ConfirmationModal>
|
|
)
|
|
}
|