Skip to content

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

Add branch dropdown in nav v1

Joshen Limd5b6de599611
diff --git a/studio/components/layouts/AppLayout/BranchDropdown.tsx b/studio/components/layouts/AppLayout/BranchDropdown.tsx
index df881dc7801..33c0f65332d 100644
--- a/studio/components/layouts/AppLayout/BranchDropdown.tsx
+++ b/studio/components/layouts/AppLayout/BranchDropdown.tsx
@@ -63,7 +63,11 @@ const BranchLink = ({
)
}
-const BranchDropdown = () => {
+interface BranchDropdownProps {
+ alt?: boolean
+}
+
+const BranchDropdown = ({ alt = false }: BranchDropdownProps) => {
const router = useRouter()
const { ref } = useParams()
const projectDetails = useSelectedProject()
@@ -97,11 +101,13 @@ const BranchDropdown = () => {
type="text"
className="pr-2"
iconRight={
- <IconCode className="text-scale-1100 rotate-90" strokeWidth={2} size={12} />
+ !alt ? (
+ <IconCode className="text-scale-1100 rotate-90" strokeWidth={2} size={12} />
+ ) : null
}
>
<div className="flex items-center space-x-2">
- <p className="text-sm">{selectedBranch?.name}</p>
+ <p className={alt ? 'text-xs' : 'text-sm'}>{selectedBranch?.name}</p>
{selectedBranch?.is_default ? (
<Badge color="amber">Production</Badge>
) : (
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx
index a6c48cad0d4..70e326e1302 100644
--- a/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx
@@ -9,13 +9,17 @@ import {
Popover_Shadcn_,
} from 'ui'
-const BranchingWaitlistPopover = () => {
+interface BranchingWaitlistPopoverProps {
+ alt?: boolean
+}
+
+const BranchingWaitlistPopover = ({ alt = false }: BranchingWaitlistPopoverProps) => {
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} />}>
+ <Button type={alt ? 'text' : 'default'} icon={<IconGitBranch strokeWidth={1.5} />}>
Enable branching
</Button>
</PopoverTrigger_Shadcn_>
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
index e1aa1f34fc1..b3445c1261a 100644
--- a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
@@ -1,186 +1,32 @@
-import { useParams } from 'common'
-import { useEffect, useState } from 'react'
-import { Button, IconFileText, IconGitBranch, Modal } from 'ui'
+import { Button, IconGitBranch } from 'ui'
-import SidePanelGitHubRepoLinker from 'components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker'
-import AlertError from 'components/ui/AlertError'
-import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
-import { useBranchCreateMutation } from 'data/branches/branch-create-mutation'
-import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
-import { IntegrationName } from 'data/integrations/integrations.types'
-import { useSelectedOrganization, useStore } from 'hooks'
+import { useSelectedOrganization } from 'hooks'
import { useAppUiStateSnapshot } from 'state/app'
import BranchingWaitlistPopover from './BranchingWaitlistPopover'
-import GithubRepositorySelection from './GithubRepositorySelection'
-import VercelProjectSelection from './VercelProjectSelection'
-const EnableBranchingButton = () => {
- const { ui } = useStore()
- const { ref } = useParams()
- const selectedOrg = useSelectedOrganization()
+interface EnableBranchingButtonProps {
+ alt?: boolean
+}
+const EnableBranchingButton = ({ alt = false }: EnableBranchingButtonProps) => {
const snap = useAppUiStateSnapshot()
- const [selectedBranch, setSelectedBranch] = useState<string>()
- const [addConnectionType, setAddConnectionType] = useState<IntegrationName>()
-
- useEffect(() => {
- if (snap.showEnableBranchingModal) setSelectedBranch(undefined)
- }, [snap.showEnableBranchingModal])
-
- const {
- data: integrations,
- error: integrationsError,
- isLoading: isLoadingIntegrations,
- isSuccess: isSuccessIntegrations,
- isError: isErrorIntegrations,
- } = useOrgIntegrationsQuery({
- orgSlug: selectedOrg?.slug,
- })
-
- const { mutate: createBranch, isLoading: isCreating } = useBranchCreateMutation({
- onSuccess: () => {
- ui.setNotification({ category: 'success', message: `Successfully created new branch` })
- snap.setShowEnableBranchingModal(false)
- },
- })
+ const selectedOrg = useSelectedOrganization()
const hasAccessToBranching =
selectedOrg?.opt_in_tags?.includes('PREVIEW_BRANCHES_OPT_IN') ?? false
- const hasGithubIntegrationInstalled =
- integrations?.some((integration) => integration.integration.name === 'GitHub') ?? false
- const githubIntegration = integrations?.find(
- (integration) =>
- integration.integration.name === 'GitHub' &&
- integration.connections.some((connection) => connection.supabase_project_ref === ref)
- )
-
- // [Joshen] Leaving this out first
- // const hasVercelIntegrationInstalled =
- // integrations?.some((integration) => integration.integration.name === 'Vercel') ?? false
- // const vercelIntegration = integrations?.find(
- // (integration) =>
- // integration.integration.name === 'Vercel' &&
- // integration.connections.some((connection) => connection.supabase_project_ref === ref)
- // )
-
- const onEnableBranching = () => {
- if (!ref) return console.error('Project ref is required')
- if (!selectedBranch) return console.error('No branch selected')
- createBranch({ projectRef: ref, branchName: selectedBranch, gitBranch: selectedBranch })
- }
-
if (!hasAccessToBranching) {
- return <BranchingWaitlistPopover />
+ return <BranchingWaitlistPopover alt={alt} />
}
return (
- <>
- <Button
- icon={<IconGitBranch strokeWidth={1.5} />}
- type="default"
- onClick={() => snap.setShowEnableBranchingModal(true)}
- >
- Enable branching
- </Button>
- <Modal
- hideFooter
- visible={snap.showEnableBranchingModal}
- onCancel={() => snap.setShowEnableBranchingModal(false)}
- className="!bg"
- size="medium"
- >
- <Modal.Content className="px-7 py-5 flex items-center space-x-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>
- </Modal.Content>
-
- {isLoadingIntegrations && (
- <>
- <Modal.Separator />
- <Modal.Content className="px-7 py-6">
- <GenericSkeletonLoader />
- </Modal.Content>
- <Modal.Separator />
- </>
- )}
-
- {isErrorIntegrations && (
- <>
- <Modal.Separator />
- <Modal.Content className="px-7 py-6">
- <AlertError error={integrationsError} subject="Failed to retrieve integrations" />
- </Modal.Content>
- <Modal.Separator />
- </>
- )}
-
- {isSuccessIntegrations && (
- <>
- <GithubRepositorySelection
- integration={githubIntegration}
- selectedBranch={selectedBranch}
- hasGithubIntegrationInstalled={hasGithubIntegrationInstalled}
- setSelectedBranch={setSelectedBranch}
- />
- {/* <VercelProjectSelection integration={vercelIntegration} /> */}
- </>
- )}
-
- {/* [Joshen TODO] Feels like this copy writing needs some relooking before we ship, make sure they are factual too */}
- <Modal.Content className="px-7 py-6 flex flex-col gap-3">
- <p className="text-sm text-light">Please keep in mind the following:</p>
- <div className="flex flex-row gap-4">
- <div>
- <figure className="w-10 h-10 rounded-md bg-warning-200 border border-warning-300 flex items-center justify-center">
- <IconFileText className="text-amber-900" size={20} strokeWidth={2} />
- </figure>
- </div>
- <div>
- <p className="text-sm text">
- You will not be able to use the dashboard to make changes to the database
- </p>
- <p className="text-sm text-light">
- Schema changes for database preview branches must be done via Git. We are
- nonetheless working on allowing the dashboard to make schema changes for preview
- branches.
- </p>
- </div>
- </div>
- </Modal.Content>
-
- <Modal.Separator />
-
- <Modal.Content className="px-7">
- <div className="flex items-center space-x-2 py-2 pb-4">
- <Button
- size="medium"
- block
- disabled={isCreating}
- type="default"
- onClick={() => snap.setShowEnableBranchingModal(false)}
- >
- Cancel
- </Button>
- <Button
- size="medium"
- block
- disabled={selectedBranch === undefined || isCreating}
- loading={isCreating}
- type="primary"
- onClick={() => onEnableBranching()}
- >
- I understand, enable branching
- </Button>
- </div>
- </Modal.Content>
- </Modal>
-
- <SidePanelGitHubRepoLinker projectRef={ref} />
- </>
+ <Button
+ type={alt ? 'text' : 'default'}
+ icon={<IconGitBranch strokeWidth={1.5} />}
+ onClick={() => snap.setShowEnableBranchingModal(true)}
+ >
+ Enable branching
+ </Button>
)
}
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingModal.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingModal.tsx
new file mode 100644
index 00000000000..5c525442190
--- /dev/null
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingModal.tsx
@@ -0,0 +1,175 @@
+import { useParams } from 'common'
+import { useEffect, useState } from 'react'
+import { Button, IconFileText, IconGitBranch, Modal } from 'ui'
+
+import SidePanelGitHubRepoLinker from 'components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker'
+import AlertError from 'components/ui/AlertError'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import { useBranchCreateMutation } from 'data/branches/branch-create-mutation'
+import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
+import { IntegrationName } from 'data/integrations/integrations.types'
+import { useSelectedOrganization, useStore } from 'hooks'
+import { useAppUiStateSnapshot } from 'state/app'
+import BranchingWaitlistPopover from './BranchingWaitlistPopover'
+import GithubRepositorySelection from './GithubRepositorySelection'
+import VercelProjectSelection from './VercelProjectSelection'
+
+// [Joshen] Temp
+
+const EnableBranchingModal = () => {
+ const { ui } = useStore()
+ const { ref } = useParams()
+ const selectedOrg = useSelectedOrganization()
+
+ const snap = useAppUiStateSnapshot()
+ const [selectedBranch, setSelectedBranch] = useState<string>()
+ const [addConnectionType, setAddConnectionType] = useState<IntegrationName>()
+
+ useEffect(() => {
+ if (snap.showEnableBranchingModal) setSelectedBranch(undefined)
+ }, [snap.showEnableBranchingModal])
+
+ const {
+ data: integrations,
+ error: integrationsError,
+ isLoading: isLoadingIntegrations,
+ isSuccess: isSuccessIntegrations,
+ isError: isErrorIntegrations,
+ } = useOrgIntegrationsQuery({
+ orgSlug: selectedOrg?.slug,
+ })
+
+ const { mutate: createBranch, isLoading: isCreating } = useBranchCreateMutation({
+ onSuccess: () => {
+ ui.setNotification({ category: 'success', message: `Successfully created new branch` })
+ snap.setShowEnableBranchingModal(false)
+ },
+ })
+
+ const hasGithubIntegrationInstalled =
+ integrations?.some((integration) => integration.integration.name === 'GitHub') ?? false
+ const githubIntegration = integrations?.find(
+ (integration) =>
+ integration.integration.name === 'GitHub' &&
+ integration.connections.some((connection) => connection.supabase_project_ref === ref)
+ )
+
+ // [Joshen] Leaving this out first
+ // const hasVercelIntegrationInstalled =
+ // integrations?.some((integration) => integration.integration.name === 'Vercel') ?? false
+ // const vercelIntegration = integrations?.find(
+ // (integration) =>
+ // integration.integration.name === 'Vercel' &&
+ // integration.connections.some((connection) => connection.supabase_project_ref === ref)
+ // )
+
+ const onEnableBranching = () => {
+ if (!ref) return console.error('Project ref is required')
+ if (!selectedBranch) return console.error('No branch selected')
+ createBranch({ projectRef: ref, branchName: selectedBranch, gitBranch: selectedBranch })
+ }
+
+ return (
+ <>
+ <Modal
+ hideFooter
+ visible={snap.showEnableBranchingModal}
+ onCancel={() => snap.setShowEnableBranchingModal(false)}
+ className="!bg"
+ size="medium"
+ >
+ <Modal.Content className="px-7 py-5 flex items-center space-x-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>
+ </Modal.Content>
+
+ {isLoadingIntegrations && (
+ <>
+ <Modal.Separator />
+ <Modal.Content className="px-7 py-6">
+ <GenericSkeletonLoader />
+ </Modal.Content>
+ <Modal.Separator />
+ </>
+ )}
+
+ {isErrorIntegrations && (
+ <>
+ <Modal.Separator />
+ <Modal.Content className="px-7 py-6">
+ <AlertError error={integrationsError} subject="Failed to retrieve integrations" />
+ </Modal.Content>
+ <Modal.Separator />
+ </>
+ )}
+
+ {isSuccessIntegrations && (
+ <>
+ <GithubRepositorySelection
+ integration={githubIntegration}
+ selectedBranch={selectedBranch}
+ hasGithubIntegrationInstalled={hasGithubIntegrationInstalled}
+ setSelectedBranch={setSelectedBranch}
+ />
+ {/* <VercelProjectSelection integration={vercelIntegration} /> */}
+ </>
+ )}
+
+ {/* [Joshen TODO] Feels like this copy writing needs some relooking before we ship, make sure they are factual too */}
+ <Modal.Content className="px-7 py-6 flex flex-col gap-3">
+ <p className="text-sm text-light">Please keep in mind the following:</p>
+ <div className="flex flex-row gap-4">
+ <div>
+ <figure className="w-10 h-10 rounded-md bg-warning-200 border border-warning-300 flex items-center justify-center">
+ <IconFileText className="text-amber-900" size={20} strokeWidth={2} />
+ </figure>
+ </div>
+ <div>
+ <p className="text-sm text">
+ You will not be able to use the dashboard to make changes to the database
+ </p>
+ <p className="text-sm text-light">
+ Schema changes for database preview branches must be done via Git. We are
+ nonetheless working on allowing the dashboard to make schema changes for preview
+ branches.
+ </p>
+ </div>
+ </div>
+ </Modal.Content>
+
+ <Modal.Separator />
+
+ <Modal.Content className="px-7">
+ <div className="flex items-center space-x-2 py-2 pb-4">
+ <Button
+ size="medium"
+ block
+ disabled={isCreating}
+ type="default"
+ onClick={() => snap.setShowEnableBranchingModal(false)}
+ >
+ Cancel
+ </Button>
+ <Button
+ size="medium"
+ block
+ disabled={selectedBranch === undefined || isCreating}
+ loading={isCreating}
+ type="primary"
+ onClick={() => onEnableBranching()}
+ >
+ I understand, enable branching
+ </Button>
+ </div>
+ </Modal.Content>
+ </Modal>
+
+ <SidePanelGitHubRepoLinker projectRef={ref} />
+ </>
+ )
+}
+
+export default EnableBranchingModal
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx
index cfd42ae8d16..3a3b3ee70e9 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx
@@ -14,10 +14,16 @@ import NotificationsPopover from './NotificationsPopover'
import OrgDropdown from './OrgDropdown'
import ProjectDropdown from './ProjectDropdown'
import { useProjectSubscriptionV2Query } from 'data/subscriptions/project-subscription-v2-query'
+import BranchDropdown from 'components/layouts/AppLayout/BranchDropdown'
+import EnableBranchingButton from 'components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton'
const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder = true }: any) => {
- const selectedOrganization = useSelectedOrganization()
const selectedProject = useSelectedProject()
+ const selectedOrganization = useSelectedOrganization()
+ const hasAccessToBranching =
+ selectedOrganization?.opt_in_tags?.includes('PREVIEW_BRANCHES_OPT_IN') ?? false
+ const isBranchingEnabled =
+ selectedProject?.is_branch_enabled === true || selectedProject?.parent_project_ref !== undefined
const { ref: projectRef } = useParams()
const { data: isReadOnlyMode } = useProjectReadOnlyQuery({
@@ -57,10 +63,8 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder =
{/* Organization is selected */}
{projectRef && selectedOrganization ? (
<>
- {/* Org Dropdown */}
<OrgDropdown />
- {/* Project is selected */}
{selectedProject && (
<>
<span className="text-scale-800 dark:text-scale-700">
@@ -78,7 +82,6 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder =
<path d="M16 3.549L7.12 20.600"></path>
</svg>
</span>
- {/* Project Dropdown */}
<ProjectDropdown />
{/* [Terry] Temporary until we figure out how we want to display this permanently */}
@@ -104,6 +107,27 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder =
)}
</>
)}
+
+ {hasAccessToBranching && (
+ <>
+ <span className="text-scale-800 dark:text-scale-700">
+ <svg
+ viewBox="0 0 24 24"
+ width="16"
+ height="16"
+ stroke="currentColor"
+ strokeWidth="1"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ fill="none"
+ shapeRendering="geometricPrecision"
+ >
+ <path d="M16 3.549L7.12 20.600"></path>
+ </svg>
+ </span>
+ {isBranchingEnabled ? <BranchDropdown alt /> : <EnableBranchingButton alt />}
+ </>
+ )}
</>
) : (
<Link href="/projects">
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/ProjectDropdown.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/ProjectDropdown.tsx
index d8c59401f7c..8d9ca83423e 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/ProjectDropdown.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/ProjectDropdown.tsx
@@ -106,7 +106,7 @@ const ProjectDropdown = () => {
}
>
<Button type="text">
- <span className="text-sm">{selectedProject?.name}</span>
+ <span className="text-xs">{selectedProject?.name}</span>
</Button>
</Dropdown>
) : (
diff --git a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
index 72d71362d2c..47f8d1bf0cc 100644
--- a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
+++ b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
@@ -17,6 +17,7 @@ import ProjectPausedState from './ProjectPausedState'
import RestoringState from './RestoringState'
import UpgradingState from './UpgradingState'
import AppLayout from '../AppLayout/AppLayout'
+import EnableBranchingModal from '../AppLayout/EnableBranchingButton/EnableBranchingModal'
// [Joshen] This is temporary while we unblock users from managing their project
// if their project is not responding well for any reason. Eventually needs a bit of an overhaul
@@ -115,6 +116,8 @@ const ProjectLayout = ({
)}
</main>
</div>
+
+ <EnableBranchingModal />
</ProjectContextProvider>
</AppLayout>
)
@@ -253,6 +256,8 @@ export const ProjectLayoutNonBlocking = ({
)}
</main>
</div>
+
+ <EnableBranchingModal />
</ProjectContextProvider>
</AppLayout>
)