Skip to content

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

Implemenet enable branching button

Joshen Lim7a5d7562c9e0
diff --git a/studio/components/layouts/AppLayout/AppHeader.tsx b/studio/components/layouts/AppLayout/AppHeader.tsx
index 74483659353..41e3cb83317 100644
--- a/studio/components/layouts/AppLayout/AppHeader.tsx
+++ b/studio/components/layouts/AppLayout/AppHeader.tsx
@@ -12,7 +12,7 @@ import SettingsButton from './SettingsButton'
import UserSettingsDropdown from './UserSettingsDropdown'
import BranchDropdown from './BranchDropdown'
import { useProjectsQuery } from 'data/projects/projects-query'
-import EnableBranchingButton from './EnableBranchingButton'
+import EnableBranchingButton from './EnableBranchingButton/EnableBranchingButton'
const AppHeader = () => {
const router = useRouter()
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx
new file mode 100644
index 00000000000..60f9711e0e6
--- /dev/null
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx
@@ -0,0 +1,54 @@
+import Link from 'next/link'
+import { useState } from 'react'
+import {
+ Popover_Shadcn_,
+ PopoverTrigger_Shadcn_,
+ Button,
+ IconGitBranch,
+ PopoverContent_Shadcn_,
+ Badge,
+} from 'ui'
+
+const BranchingWaitlistPopover = () => {
+ const [open, setOpen] = useState(false)
+
+ return (
+ <Popover_Shadcn_ open={open} onOpenChange={setOpen} modal={false}>
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button type="default" icon={<IconGitBranch strokeWidth={1.5} />}>
+ Enable branching
+ </Button>
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_
+ align="start"
+ side="bottom"
+ className="space-y-4 w-80"
+ style={{ marginLeft: '-18px' }}
+ >
+ <Badge color="scale">Alpha Testing</Badge>
+ <div className="flex items-center space-x-2">
+ <IconGitBranch strokeWidth={2} />
+ <p>Database Branching</p>
+ </div>
+ <p className="text-xs text-light">
+ Register for early access and you'll be contacted by email when your organization is
+ enrolled in database branching.
+ </p>
+ <div className="flex items-center space-x-2">
+ <Link passHref href={'/'}>
+ <a rel="noreferrer" target="_blank">
+ <Button>Join waitlist</Button>
+ </a>
+ </Link>
+ <Link passHref href={'/'}>
+ <a rel="noreferrer" target="_blank">
+ <Button type="default">View the docs</Button>
+ </a>
+ </Link>
+ </div>
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
+ )
+}
+
+export default BranchingWaitlistPopover
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
similarity index 56%
rename from studio/components/layouts/AppLayout/EnableBranchingButton.tsx
rename to studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
index ffdf401e774..57edcab5309 100644
--- a/studio/components/layouts/AppLayout/EnableBranchingButton.tsx
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
@@ -2,7 +2,10 @@ import { useParams } from 'common'
import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
import { useSelectedOrganization } from 'hooks'
import { useState } from 'react'
-import { Badge, Button, IconFileText, IconGitBranch, Modal } from 'ui'
+import { Button, IconFileText, IconGitBranch, Modal } from 'ui'
+import BranchingWaitlistPopover from './BranchingWaitlistPopover'
+import GithubRepositorySelection from './GithubRepositorySelection'
+import VercelProjectSelection from './VercelProjectSelection'
const EnableBranchingButton = () => {
const { ref } = useParams()
@@ -19,19 +22,25 @@ const EnableBranchingButton = () => {
orgSlug: selectedOrg?.slug,
})
+ // [Joshen] To be dynamic
+ const isBranchingAllowed = true
+
const githubIntegration = integrations?.find(
(integration) =>
integration.integration.name === 'GitHub' &&
- integration.connections.some((connection) => connection.supabase_project_ref === ref)
+ integration.organization.slug === selectedOrg?.slug
)
+
const vercelIntegration = integrations?.find(
- (integration) =>
- integration.integration.name === 'Vercel' &&
- integration.connections.some((connection) => connection.supabase_project_ref === ref)
+ (integration) => integration.integration.name === 'Vercel'
+ )
+ const vercelProjectIntegration = vercelIntegration?.connections.find(
+ (connection) => connection.supabase_project_ref === ref
)
- const hasVercelIntegration = false
- console.log({ githubIntegration, vercelIntegration })
+ if (!isBranchingAllowed) {
+ return <BranchingWaitlistPopover />
+ }
return (
<>
@@ -53,54 +62,9 @@ const EnableBranchingButton = () => {
</div>
</Modal.Content>
- {githubIntegration !== undefined ? (
- <>
- <Modal.Separator />
- <Modal.Content>
- <div className="flex items-center space-x-4 py-4">
- <IconGitBranch strokeWidth={2} size={20} />
- <div>
- <p className="text">Enable database branching</p>
- <p className="text-sm text-light">Management environments in Supabase</p>
- </div>
- </div>
- </Modal.Content>
- <Modal.Separator />
- </>
- ) : (
- <div className="border-t border-b border-amber-300 bg-amber-100">
- <Modal.Content>
- <div className="space-y-1 py-6">
- <div className="flex items-center space-x-2">
- <p>Git Connection</p>
- <Badge color="amber">Required</Badge>
- </div>
- <p className="text-sm text-light">
- Your database will make preview branches based on your branches in the Git
- repository that your project is connected with.
- </p>
- <Button type="default" className="!mt-3" onClick={() => {}}>
- Install Github Integration
- </Button>
- </div>
- </Modal.Content>
- </div>
- )}
+ <GithubRepositorySelection integration={githubIntegration} />
- {/* <Modal.Content>
- <div className="space-y-1 py-6">
- <div className="flex items-center space-x-2">
- <p>Frontend Cloud Previews</p>
- <Badge color="gray">Optional</Badge>
- </div>
- <p className="text-sm text-light">
- Previews can be available by connecting your Supabase project to a Vercel project.
- </p>
- <Button type="default" className="!mt-3" onClick={() => {}}>
- Install Vercel Integration
- </Button>
- </div>
- </Modal.Content> */}
+ {/* <VercelProjectSelection integration={vercelIntegration} /> */}
{/* <Modal.Separator /> */}
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx
new file mode 100644
index 00000000000..d2068a2db6b
--- /dev/null
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx
@@ -0,0 +1,55 @@
+import clsx from 'clsx'
+import { useParams } from 'common'
+import { Integration } from 'data/integrations/integrations.types'
+import Link from 'next/link'
+import { Modal, Badge, Button, IconGitHub } from 'ui'
+
+interface GithubRepositorySelectionProps {
+ integration?: Integration
+}
+
+// [Joshen TODO] Integrate the Github repo selector
+
+const GithubRepositorySelection = ({ integration }: GithubRepositorySelectionProps) => {
+ const { ref } = useParams()
+ const githubProjectIntegration = integration?.connections.find(
+ (connection) => connection.supabase_project_ref === ref
+ )
+
+ return (
+ <div className={clsx('border-t border-b', !integration ? 'border-amber-300 bg-amber-100' : '')}>
+ <Modal.Content>
+ <div className="space-y-1 py-6">
+ <div className="flex items-center space-x-2">
+ <p>Git Connection</p>
+ <Badge color="amber">Required</Badge>
+ </div>
+ <p className="text-sm text-light">
+ {githubProjectIntegration !== undefined
+ ? 'Your database will make preview branches based on your branches in the following repository'
+ : 'Your database will make preview branches based on your branches in the Git repository that your project is connected with.'}
+ </p>
+ {!integration && (
+ <Link passHref href="/">
+ <a target="_blank" rel="noreferrer">
+ <Button type="default" className="!mt-3">
+ Install Github Integration
+ </Button>
+ </a>
+ </Link>
+ )}
+ {integration && !githubProjectIntegration && (
+ <div className="border border-dashed rounded w-full !mt-4 flex items-center justify-center py-4 space-x-4">
+ <IconGitHub strokeWidth={2} />
+ <Button type="default" onClick={() => {}}>
+ Connect repo
+ </Button>
+ </div>
+ )}
+ </div>
+ </Modal.Content>
+ </div>
+ )
+}
+
+export default GithubRepositorySelection
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/VercelProjectSelection.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/VercelProjectSelection.tsx
new file mode 100644
index 00000000000..1e0e50356f1
--- /dev/null
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/VercelProjectSelection.tsx
@@ -0,0 +1,37 @@
+import { useParams } from 'common'
+import { Integration } from 'data/integrations/integrations.types'
+import { Badge, Button, Modal } from 'ui'
+
+interface VercelProjectSelectionProps {
+ integration?: Integration
+}
+
+const VercelProjectSelection = ({ integration }: VercelProjectSelectionProps) => {
+ const { ref } = useParams()
+ const vercelProjectIntegration = integration?.connections.find(
+ (connection) => connection.supabase_project_ref === ref
+ )
+
+ return (
+ <Modal.Content>
+ <div className="space-y-1 py-6">
+ <div className="flex items-center space-x-2">
+ <p>Frontend Cloud Previews</p>
+ <Badge color="gray">Optional</Badge>
+ </div>
+ <p className="text-sm text-light">
+ Previews can be available by connecting your Supabase project to a Vercel project.
+ </p>
+ {!integration && (
+ <Button type="default" className="!mt-3" onClick={() => {}}>
+ Install Vercel Integration
+ </Button>
+ )}
+ {integration && !vercelProjectIntegration && <div>Connect project</div>}
+ {integration && vercelProjectIntegration && <div>Select project</div>}
+ </div>
+ </Modal.Content>
+ )
+}
+
+export default VercelProjectSelection