mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
## Context Realised that if the project has a GH integration, but the user's account is not connected to GH - the branch validation in the "Sync with Git Branch" field will not work. The Edit branch modal also obfuscates the error being returned from the validation API so its not clear what the issue is <img width="500" alt="image" src="https://github.com/user-attachments/assets/739dfe7c-8920-4edf-a751-63d7f6273db4" /> Opting to show an "Authorize" CTA for this scenario so it's clear from the user's POV what to do (Refer to "To test" below for screenshots) ## To test - [ ] Verify that on an account which isn't connect to GH + project with no GH integration - CTA is as per normal ("Configure") which should direct you to the settings -> integrations page (Same for edit branch) <img width="500" alt="image" src="https://github.com/user-attachments/assets/9a010fde-8ab0-43d6-b5c9-ced9fed1426e" /> <img width="500" alt="image" src="https://github.com/user-attachments/assets/d129cccf-7238-4305-913b-0cf78c7dcc26" /> - [ ] Set up a GH integration and check Create / Edit branch - the branch input field should work with proper branch name validation <img width="500" alt="image" src="https://github.com/user-attachments/assets/4d643956-2d11-406b-b198-193f3221b7a9" /> - [ ] Now go to Account settings and remove the GH connection, then check the Create / Edit branch modals - should have the "Authorize" CTA (instead of the input field) <img width="500" alt="image" src="https://github.com/user-attachments/assets/ac152c0d-2e9c-4d89-95bc-36127c0fc8df" /> <img width="500" alt="image" src="https://github.com/user-attachments/assets/d1f50d38-d801-4546-96fd-8cf3b5d0f805" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a “Sync with a GitHub branch” connection entry with an inline authorize flow. * Integrated GitHub authorization awareness into branch create/edit modals so users are guided to authorize or proceed to syncing. * **Bug Fixes** * Unified loading, success, and error handling for GitHub authorization/connection checks across create and edit flows. * Improved Git branch validation messaging to show cleaner error text. * **Accessibility/UX** * Updated modal UI text and added an explicit label for the “Include data” toggle. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import { useParams } from 'common'
|
|
import { Github } from 'lucide-react'
|
|
import { useRouter } from 'next/router'
|
|
import { Button } from 'ui'
|
|
|
|
import { useGitHubAuthorizationQuery } from '@/data/integrations/github-authorization-query'
|
|
import { useGitHubConnectionsQuery } from '@/data/integrations/github-connections-query'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { openInstallGitHubIntegrationWindow } from '@/lib/github'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
export const ConnectToGitHub = () => {
|
|
const router = useRouter()
|
|
const { ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { data: selectedOrg } = useSelectedOrganizationQuery()
|
|
const { showCreateBranchModal, setShowCreateBranchModal } = useAppStateSnapshot()
|
|
|
|
const isBranch = project?.parent_project_ref !== undefined
|
|
const projectRef =
|
|
project !== undefined ? (isBranch ? project.parent_project_ref : ref) : undefined
|
|
|
|
const { data: gitHubAuthorization } = useGitHubAuthorizationQuery()
|
|
|
|
const { data: connections } = useGitHubConnectionsQuery(
|
|
{ organizationId: selectedOrg?.id },
|
|
{ enabled: showCreateBranchModal }
|
|
)
|
|
const githubConnection = connections?.find((connection) => connection.project.ref === projectRef)
|
|
|
|
const showAuthorizeCta = githubConnection && !gitHubAuthorization
|
|
|
|
const onClick = () => {
|
|
if (showAuthorizeCta) {
|
|
openInstallGitHubIntegrationWindow('authorize')
|
|
} else {
|
|
if (showCreateBranchModal) setShowCreateBranchModal(false)
|
|
router.push(`/project/${projectRef}/settings/integrations`)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex items-center gap-2 justify-between">
|
|
<div className="flex flex-col gap-1">
|
|
<span className="text-sm text leading-none">Sync with a GitHub branch</span>
|
|
<p className="text-sm text-foreground-lighter">
|
|
Keep this preview branch in sync with a chosen GitHub branch
|
|
</p>
|
|
</div>
|
|
<Button variant="default" icon={<Github />} onClick={onClick}>
|
|
{showAuthorizeCta ? 'Authorize' : 'Configure'}
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|