The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add repo selection logic in branch enable modal
Joshen Lim0ff85438a946
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsxindex 57edcab5309..5710c78df3f 100644--- a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx@@ -1,7 +1,7 @@import { useParams } from 'common'import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'import { useSelectedOrganization } from 'hooks'-import { useState } from 'react'+import { useEffect, useState } from 'react'import { Button, IconFileText, IconGitBranch, Modal } from 'ui'import BranchingWaitlistPopover from './BranchingWaitlistPopover'import GithubRepositorySelection from './GithubRepositorySelection'@@ -12,6 +12,12 @@ const EnableBranchingButton = () => {const [open, setOpen] = useState(false)const selectedOrg = useSelectedOrganization()+ const [selectedBranch, setSelectedBranch] = useState<string>()++ useEffect(() => {+ if (open) setSelectedBranch(undefined)+ }, [open])+const {data: integrations,error: integrationsError,@@ -62,7 +68,11 @@ const EnableBranchingButton = () => {</div></Modal.Content>- <GithubRepositorySelection integration={githubIntegration} />+ <GithubRepositorySelection+ integration={githubIntegration}+ selectedBranch={selectedBranch}+ setSelectedBranch={setSelectedBranch}+ />{/* <VercelProjectSelection integration={vercelIntegration} /> */}@@ -99,7 +109,7 @@ const EnableBranchingButton = () => {<Button block type="default">Cancel</Button>- <Button block disabled type="primary">+ <Button block disabled={selectedBranch === undefined} type="primary">I understand, enable branching</Button></div>diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsxindex d2068a2db6b..8cffc3f2c9f 100644--- a/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx@@ -1,20 +1,63 @@import clsx from 'clsx'+import Link from 'next/link'+import { useRef, useState } from 'react'+import {+ Badge,+ Button,+ CommandEmpty_Shadcn_,+ CommandGroup_Shadcn_,+ CommandInput_Shadcn_,+ CommandItem_Shadcn_,+ CommandList_Shadcn_,+ Command_Shadcn_,+ IconCheck,+ IconChevronDown,+ IconGitHub,+ Modal,+ PopoverContent_Shadcn_,+ PopoverTrigger_Shadcn_,+ Popover_Shadcn_,+} from 'ui'+import { useParams } from 'common'+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 Link from 'next/link'-import { Modal, Badge, Button, IconGitHub } from 'ui'interface GithubRepositorySelectionProps {integration?: Integration+ selectedBranch?: string+ setSelectedBranch: (name: string) => void}// [Joshen TODO] Integrate the Github repo selector-const GithubRepositorySelection = ({ integration }: GithubRepositorySelectionProps) => {+const GithubRepositorySelection = ({+ integration,+ selectedBranch,+ setSelectedBranch,+}: GithubRepositorySelectionProps) => {const { ref } = useParams()+ const [open, setOpen] = useState(false)+ const comboBoxRef = useRef<HTMLButtonElement>(null)+const githubProjectIntegration = integration?.connections.find((connection) => connection.supabase_project_ref === ref)+ const [repoOwner, repoName] = githubProjectIntegration?.metadata.name.split('/') ?? []++ const {+ data: githubBranches,+ error: githubBranchesError,+ isLoading: isLoadingBranches,+ isSuccess: isSuccessBranches,+ isError: isErrorBranches,+ } = useGithubBranchesQuery({+ organizationIntegrationId: integration?.id,+ repoOwner,+ repoName,+ })return (<div className={clsx('border-t border-b', !integration ? 'border-amber-300 bg-amber-100' : '')}>@@ -26,8 +69,8 @@ const GithubRepositorySelection = ({ integration }: GithubRepositorySelectionPro</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.'}+ ? '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.'}</p>{!integration && (<Link passHref href="/">@@ -39,13 +82,97 @@ const GithubRepositorySelection = ({ integration }: GithubRepositorySelectionPro</Link>)}{integration && !githubProjectIntegration && (- <div className="border border-dashed rounded w-full !mt-4 flex items-center justify-center py-4 space-x-4">+ <div className="border border-dashed rounded !mt-4 flex items-center justify-center py-4 space-x-4"><IconGitHub strokeWidth={2} /><Button type="default" onClick={() => {}}>Connect repo</Button></div>)}+ {integration && githubProjectIntegration && (+ <>+ <div className="border bg-surface-200 rounded-md !mt-4 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} />+ </div>+ <div>+ <p className="text-sm text-light">@{repoOwner}</p>+ <p className="text-sm">{repoName}</p>+ </div>+ </div>+ <Button type="default">Configure</Button>+ </div>+ <div className="!mt-4">+ <p className="text-sm text-light mb-2">Select your production branch:</p>+ {isLoadingBranches && <ShimmeringLoader />}+ {isErrorBranches && (+ <AlertError+ error={githubBranchesError}+ subject="Failed to retrieve Github branches"+ />+ )}+ {isSuccessBranches && (+ <Popover_Shadcn_ open={open} onOpenChange={setOpen} modal={false}>+ <PopoverTrigger_Shadcn_ asChild>+ <Button+ block+ type="default"+ size="medium"+ ref={comboBoxRef}+ className="justify-start"+ iconRight={+ <span className="grow flex justify-end">+ <IconChevronDown className={''} />+ </span>+ }+ >+ <p className={selectedBranch === undefined ? 'text-light' : 'text'}>+ {selectedBranch || 'Select a branch'}+ </p>+ </Button>+ </PopoverTrigger_Shadcn_>+ <PopoverContent_Shadcn_+ className="p-0"+ side="bottom"+ align="start"+ style={{ width: comboBoxRef.current?.offsetWidth }}+ >+ <Command_Shadcn_>+ <CommandInput_Shadcn_ placeholder="Find branch..." />+ <CommandList_Shadcn_>+ <CommandEmpty_Shadcn_>No branches found</CommandEmpty_Shadcn_>+ <CommandGroup_Shadcn_>+ {githubBranches?.map((branch) => (+ <CommandItem_Shadcn_+ asChild+ key={branch.name}+ value={branch.name}+ className="cursor-pointer w-full flex items-center justify-between"+ onSelect={() => {+ setOpen(false)+ setSelectedBranch(branch.name)+ }}+ onClick={() => {+ setOpen(false)+ setSelectedBranch(branch.name)+ }}+ >+ <a>+ {branch.name}+ {branch.name === selectedBranch && <IconCheck />}+ </a>+ </CommandItem_Shadcn_>+ ))}+ </CommandGroup_Shadcn_>+ </CommandList_Shadcn_>+ </Command_Shadcn_>+ </PopoverContent_Shadcn_>+ </Popover_Shadcn_>+ )}+ </div>+ </>+ )}</div></Modal.Content></div>