The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add create main branch functionality
Joshen Lim074ce6cc5cc4
diff --git a/studio/components/interfaces/Integrations/ProjectLinker.tsx b/studio/components/interfaces/Integrations/ProjectLinker.tsxindex 18db1f54911..2bebe5af4b7 100644--- a/studio/components/interfaces/Integrations/ProjectLinker.tsx+++ b/studio/components/interfaces/Integrations/ProjectLinker.tsx@@ -2,8 +2,9 @@ import { ReactNode, useRef, useState } from 'react'import { IntegrationProjectConnection } from 'data/integrations/integrations.types'import { IntegrationConnectionsCreateVariables } from 'data/integrations/types'-import { useSelectedOrganization, useStore } from 'hooks'+import { useSelectedOrganization } from 'hooks'import { BASE_PATH } from 'lib/constants'+import { toast } from 'react-hot-toast'import {Button,CommandEmpty_Shadcn_,@@ -18,7 +19,6 @@ import {Popover_Shadcn_,cn,} from 'ui'-import { toast } from 'react-hot-toast'export interface Project {id: string@@ -189,14 +189,14 @@ const ProjectLinker = ({<CommandList_Shadcn_ className="!max-h-[170px]"><CommandEmpty_Shadcn_>No results found.</CommandEmpty_Shadcn_><CommandGroup_Shadcn_>- {supabaseProjects.map((project) => {+ {supabaseProjects.map((project, i) => {return (<CommandItem_Shadcn_- value={project.ref}+ value={`${project.name}-${i}`}key={project.ref}className="flex gap-2 items-center"- onSelect={(ref) => {- if (ref) setSupabaseProjectRef(ref)+ onSelect={() => {+ if (project.ref) setSupabaseProjectRef(project.ref)setSupabaseProjectsComboboxOpen(false)}}>@@ -261,14 +261,14 @@ const ProjectLinker = ({<CommandList_Shadcn_ className="!max-h-[170px]"><CommandEmpty_Shadcn_>No results found.</CommandEmpty_Shadcn_><CommandGroup_Shadcn_>- {foreignProjects.map((project) => {+ {foreignProjects.map((project, i) => {return (<CommandItem_Shadcn_- value={project.id}key={project.id}+ value={`${project.name}-${i}`}className="flex gap-2 items-center"- onSelect={(id) => {- if (id) setForeignProjectId(id)+ onSelect={() => {+ if (project.id) setForeignProjectId(project.id)setForeignProjectsComboboxOpen(false)}}>diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsxindex 496172b0aff..3bbda7a6bb8 100644--- a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx@@ -1,6 +1,6 @@import { useParams } from 'common'import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'-import { useSelectedOrganization } from 'hooks'+import { useSelectedOrganization, useStore } from 'hooks'import { useEffect, useState } from 'react'import { Button, IconFileText, IconGitBranch, Modal } from 'ui'import BranchingWaitlistPopover from './BranchingWaitlistPopover'@@ -8,8 +8,12 @@ import GithubRepositorySelection from './GithubRepositorySelection'import VercelProjectSelection from './VercelProjectSelection'import SidePanelGitHubRepoLinker from 'components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker'import { IntegrationName } from 'data/integrations/integrations.types'+import { useBranchCreateMutation } from 'data/branches/branch-create-mutation'+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'+import AlertError from 'components/ui/AlertError'const EnableBranchingButton = () => {+ const { ui } = useStore()const { ref } = useParams()const [open, setOpen] = useState(false)const selectedOrg = useSelectedOrganization()@@ -31,6 +35,13 @@ const EnableBranchingButton = () => {orgSlug: selectedOrg?.slug,})+ const { mutate: createBranch, isLoading: isCreating } = useBranchCreateMutation({+ onSuccess: () => {+ ui.setNotification({ category: 'success', message: `Successfully created new branch` })+ setOpen(false)+ },+ })+// [Joshen] To be dynamicconst isBranchingAllowed = true@@ -40,12 +51,19 @@ const EnableBranchingButton = () => {integration.organization.slug === selectedOrg?.slug)- const vercelIntegration = integrations?.find(- (integration) => integration.integration.name === 'Vercel'- )- const vercelProjectIntegration = vercelIntegration?.connections.find(- (connection) => connection.supabase_project_ref === ref- )+ // [Joshen] Leaving this out first as not clear yet branching x vercel implementation+ // const vercelIntegration = integrations?.find(+ // (integration) => integration.integration.name === 'Vercel'+ // )+ // const vercelProjectIntegration = vercelIntegration?.connections.find(+ // (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 (!isBranchingAllowed) {return <BranchingWaitlistPopover />@@ -71,16 +89,44 @@ const EnableBranchingButton = () => {</div></Modal.Content>- <GithubRepositorySelection- integration={githubIntegration}- selectedBranch={selectedBranch}- setSelectedBranch={setSelectedBranch}- onSelectConnectRepo={() => setAddConnectionType('GitHub')}- />-- {/* <VercelProjectSelection integration={vercelIntegration} /> */}-- {/* <Modal.Separator /> */}+ {isLoadingIntegrations && (+ <>+ <Modal.Separator />+ <Modal.Content>+ <div className="py-6">+ <GenericSkeletonLoader />+ </div>+ </Modal.Content>+ <Modal.Separator />+ </>+ )}++ {isErrorIntegrations && (+ <>+ <Modal.Separator />+ <Modal.Content>+ <div className="py-6">+ <AlertError error={integrationsError} subject="Failed to retrieve integrations" />+ </div>+ </Modal.Content>+ <Modal.Separator />+ </>+ )}++ {isSuccessIntegrations && (+ <>+ <GithubRepositorySelection+ integration={githubIntegration}+ selectedBranch={selectedBranch}+ setSelectedBranch={setSelectedBranch}+ onSelectConnectRepo={() => setAddConnectionType('GitHub')}+ />++ {/* <VercelProjectSelection integration={vercelIntegration} /> */}++ {/* <Modal.Separator /> */}+ </>+ )}{/* [Joshen TODO] Feels like this copy writing needs some relooking before we ship, make sure they are factual too */}<Modal.Content>@@ -110,10 +156,16 @@ const EnableBranchingButton = () => {<Modal.Content><div className="flex items-center space-x-2 py-2 pb-4">- <Button block type="default">+ <Button block disabled={isCreating} type="default">Cancel</Button>- <Button block disabled={selectedBranch === undefined} type="primary">+ <Button+ block+ disabled={selectedBranch === undefined || isCreating}+ loading={isCreating}+ type="primary"+ onClick={() => onEnableBranching()}+ >I understand, enable branching</Button></div>diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsxindex ef0933440eb..3a0804d531c 100644--- a/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx@@ -24,6 +24,7 @@ import AlertError from 'components/ui/AlertError'import ShimmeringLoader from 'components/ui/ShimmeringLoader'import { useGithubBranchesQuery } from 'data/integrations/integrations-github-branches-query'import { Integration } from 'data/integrations/integrations.types'+import { EmptyIntegrationConnection } from 'components/interfaces/Integrations/IntegrationPanels'interface GithubRepositorySelectionProps {integration?: Integration@@ -69,7 +70,7 @@ const GithubRepositorySelection = ({<p>Git Connection</p><Badge color="amber">Required</Badge></div>- <p className="text-sm text-light">+ <p className="text-sm text-light !mb-4">{githubProjectIntegration !== undefined? 'Your database preview branches will be based on the branches in the following repository that your project is connected with:': 'Your database preview branches will be based on the branches in the Git repository that your project is connected with.'}@@ -84,16 +85,11 @@ const GithubRepositorySelection = ({</Link>)}{integration && !githubProjectIntegration && (- <div className="bg border border-dashed rounded !mt-4 flex items-center justify-center py-6 space-x-4">- <IconGitHub strokeWidth={2} />- <Button type="default" onClick={() => onSelectConnectRepo()}>- Connect repository to project- </Button>- </div>+ <EmptyIntegrationConnection onClick={() => onSelectConnectRepo()} />)}{integration && githubProjectIntegration && (<>- <div className="border bg-surface-200 rounded-md !mt-4 flex items-center justify-between py-4 px-4">+ <div className="border bg-surface-200 rounded-md flex items-center justify-between py-4 px-4"><div className="flex items-center space-x-4"><div className="w-10 h-10 rounded-md flex items-center justify-center bg-scale-100"><IconGitHub strokeWidth={2} />diff --git a/studio/components/layouts/AppLayout/ProjectDropdown.tsx b/studio/components/layouts/AppLayout/ProjectDropdown.tsxindex db802d7fe65..42283f06859 100644--- a/studio/components/layouts/AppLayout/ProjectDropdown.tsx+++ b/studio/components/layouts/AppLayout/ProjectDropdown.tsx@@ -81,7 +81,7 @@ const ProjectLink = ({<CommandItem_Shadcn_asChildkey={project.ref}- value={project.name}+ value={`${project.name}-${project.ref}`}className="cursor-pointer w-full flex items-center justify-between"onSelect={() => {router.push(href)diff --git a/studio/data/branches/branch-create-mutation.ts b/studio/data/branches/branch-create-mutation.tsindex a9296b688af..2dddbb1abb0 100644--- a/studio/data/branches/branch-create-mutation.ts+++ b/studio/data/branches/branch-create-mutation.ts@@ -4,6 +4,7 @@ import { toast } from 'react-hot-toast'import { post } from 'data/fetchers'import { ResponseError } from 'types'import { branchKeys } from './keys'+import { projectKeys } from 'data/projects/keys'export type BranchCreateVariables = {projectRef: string@@ -50,6 +51,9 @@ export const useBranchCreateMutation = ({async onSuccess(data, variables, context) {const { projectRef } = variablesawait queryClient.invalidateQueries(branchKeys.list(projectRef))+ // [Joshen] Need to refresh projects cause thats where we'll check if branching is enabled or not+ // pending adding preview_project_refs to project details, then we can just check there instead+ await queryClient.invalidateQueries(projectKeys.list())await onSuccess?.(data, variables, context)},async onError(data, variables, context) {