mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
Part 4 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 create mutation takes a grant. `CreateBranchButton`, `CreateBranchModal`, and `Branch.Commands` (legacy `CREATE preview_branches`) switch to `useGrant('POST /v1/projects/{ref}/branches')`. "Include data" is disabled without production create; previously it failed after you submitted. The GitHub integration form gets a minimal production-create guard, which ##52377 replaces. ## Testing New `CreateBranchButton` test.
32 lines
1000 B
TypeScript
32 lines
1000 B
TypeScript
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { useGrant, type GrantResult } from '@/lib/grants'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
function getDisabledReason({ status }: GrantResult<'POST /v1/projects/{ref}/branches'>) {
|
|
if (status === 'denied') return 'You need additional permissions to create branches'
|
|
if (status === 'error') return 'Failed to check permissions'
|
|
return undefined
|
|
}
|
|
|
|
export const CreateBranchButton = () => {
|
|
const snap = useAppStateSnapshot()
|
|
const createBranchGrant = useGrant('POST /v1/projects/{ref}/branches', {})
|
|
const canCreateBranches = createBranchGrant.status === 'granted'
|
|
|
|
return (
|
|
<ButtonTooltip
|
|
variant="primary"
|
|
disabled={!canCreateBranches}
|
|
onClick={() => snap.setShowCreateBranchModal(true)}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: getDisabledReason(createBranchGrant),
|
|
},
|
|
}}
|
|
>
|
|
Create branch
|
|
</ButtonTooltip>
|
|
)
|
|
}
|