The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Hook up github repo side panel linker to enable branching modal
Joshen Lim6d5c461796e7
diff --git a/studio/components/interfaces/Integrations/ProjectLinker.tsx b/studio/components/interfaces/Integrations/ProjectLinker.tsxindex 9365d763103..18db1f54911 100644--- a/studio/components/interfaces/Integrations/ProjectLinker.tsx+++ b/studio/components/interfaces/Integrations/ProjectLinker.tsx@@ -2,7 +2,7 @@ import { ReactNode, useRef, useState } from 'react'import { IntegrationProjectConnection } from 'data/integrations/integrations.types'import { IntegrationConnectionsCreateVariables } from 'data/integrations/types'-import { useSelectedOrganization } from 'hooks'+import { useSelectedOrganization, useStore } from 'hooks'import { BASE_PATH } from 'lib/constants'import {Button,@@ -18,6 +18,7 @@ import {Popover_Shadcn_,cn,} from 'ui'+import { toast } from 'react-hot-toast'export interface Project {id: string@@ -43,6 +44,9 @@ export interface ProjectLinkerProps {onSkip?: () => voidloadingForeignProjects?: booleanloadingSupabaseProjects?: boolean++ defaultSupabaseProjectRef?: string+ defaultForeignProjectId?: string}const ProjectLinker = ({@@ -58,6 +62,9 @@ const ProjectLinker = ({onSkip,loadingForeignProjects,loadingSupabaseProjects,++ defaultSupabaseProjectRef,+ defaultForeignProjectId,}: ProjectLinkerProps) => {const [supabaseProjectsComboBoxOpen, setSupabaseProjectsComboboxOpen] = useState(false)const [foreignProjectsComboBoxOpen, setForeignProjectsComboboxOpen] = useState(false)@@ -66,23 +73,22 @@ const ProjectLinker = ({const selectedOrganization = useSelectedOrganization()- const [supabaseProjectRef, setSupabaseProjectRef] = useState<string | undefined>(undefined)- const [foreignProjectId, setForeignProjectId] = useState<string | undefined>(undefined)+ const [supabaseProjectRef, setSupabaseProjectRef] = useState<string | undefined>(+ defaultSupabaseProjectRef+ )+ const [foreignProjectId, setForeignProjectId] = useState<string | undefined>(+ defaultForeignProjectId+ )// create a flat array of foreign project ids. ie, ["prj_MlkO6AiLG5ofS9ojKrkS3PhhlY3f", ..]const flatInstalledConnectionsIds = new Set(installedConnections.map((x) => x.foreign_project_id))- // check that foreign project is not already installed- const filteredForeignProjects = foreignProjects.filter((foreignProject) => {- return !flatInstalledConnectionsIds.has(foreignProject.id)- })-const selectedSupabaseProject = supabaseProjectRef? supabaseProjects.find((x) => x.ref?.toLowerCase() === supabaseProjectRef?.toLowerCase()): undefinedconst selectedForeignProject = foreignProjectId- ? filteredForeignProjects.find((x) => x.id?.toLowerCase() === foreignProjectId?.toLowerCase())+ ? foreignProjects.find((x) => x.id?.toLowerCase() === foreignProjectId?.toLowerCase()): undefinedfunction onCreateConnections() {@@ -92,6 +98,13 @@ const ProjectLinker = ({if (!selectedForeignProject?.id) return console.error('No Foreign project ID set')if (!selectedSupabaseProject?.ref) return console.error('No Supabase project ref set')+ const alreadyInstalled = flatInstalledConnectionsIds.has(foreignProjectId ?? '')+ if (alreadyInstalled) {+ return toast.error(+ `Unable to connect to ${selectedForeignProject.name}: Selected repository already has an installed connection to a project`+ )+ }+_onCreateConnections({organizationIntegrationId,connection: {@@ -142,7 +155,7 @@ const ProjectLinker = ({type="default"size="medium"block- disabled={loadingSupabaseProjects}+ disabled={defaultSupabaseProjectRef !== undefined || loadingSupabaseProjects}loading={loadingSupabaseProjects}className="justify-start"icon={@@ -155,9 +168,11 @@ const ProjectLinker = ({</div>}iconRight={- <span className="grow flex justify-end">- <IconChevronDown className={''} />- </span>+ defaultSupabaseProjectRef === undefined ? (+ <span className="grow flex justify-end">+ <IconChevronDown className={''} />+ </span>+ ) : null}>{selectedSupabaseProject ? selectedSupabaseProject.name : 'Choose Project'}@@ -246,7 +261,7 @@ const ProjectLinker = ({<CommandList_Shadcn_ className="!max-h-[170px]"><CommandEmpty_Shadcn_>No results found.</CommandEmpty_Shadcn_><CommandGroup_Shadcn_>- {filteredForeignProjects.map((project) => {+ {foreignProjects.map((project) => {return (<CommandItem_Shadcn_value={project.id}diff --git a/studio/components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker.tsx b/studio/components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker.tsxindex 48b4fc77db7..646d2ba226f 100644--- a/studio/components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker.tsx+++ b/studio/components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker.tsx@@ -9,6 +9,8 @@ import { useProjectsQuery } from 'data/projects/projects-query'import { useSelectedOrganization } from 'hooks'import { EMPTY_ARR } from 'lib/void'import { SidePanel } from 'ui'+import { useIntegrationsGitHubInstalledConnectionDeleteMutation } from 'data/integrations/integrations-github-connection-delete-mutation'+import { IntegrationConnectionsCreateVariables } from 'data/integrations/types'const GITHUB_ICON = (<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 96" className="w-6">@@ -25,12 +27,14 @@ export type SidePanelGitHubRepoLinkerProps = {isOpen?: booleanonClose?: () => voidorganizationIntegrationId?: string+ projectRef?: string}const SidePanelGitHubRepoLinker = ({isOpen = false,onClose,organizationIntegrationId,+ projectRef,}: SidePanelGitHubRepoLinkerProps) => {const selectedOrganization = useSelectedOrganization()@@ -40,6 +44,9 @@ const SidePanelGitHubRepoLinker = ({const githubIntegrations = integrationData?.filter((integration) => integration.integration.name === 'GitHub') // github+ const existingProjectGithubConnection = githubIntegrations?.[0].connections.find(+ (connection) => connection.supabase_project_ref === projectRef+ )/*** Find the right integration@@ -87,6 +94,23 @@ const SidePanelGitHubRepoLinker = ({},})+ const { mutate: deleteGitHubConnection } =+ useIntegrationsGitHubInstalledConnectionDeleteMutation()++ const createGithubConnection = (variables: IntegrationConnectionsCreateVariables) => {+ const existingProjectGithubConnection = githubIntegrations?.[0].connections.find(+ (connection) => connection.supabase_project_ref === variables.connection.supabase_project_ref+ )+ if (existingProjectGithubConnection !== undefined && selectedOrganization !== undefined) {+ deleteGitHubConnection({+ connectionId: existingProjectGithubConnection.id,+ integrationId: existingProjectGithubConnection.organization_integration_id,+ orgSlug: selectedOrganization.slug,+ })+ }+ createConnections(variables)+ }+return (<SidePanelheader={'Add GitHub repository'}@@ -107,10 +131,12 @@ Check the details below before proceeding</SidePanel.Content><SidePanel.Content className="flex flex-col gap-2"><ProjectLinker+ defaultSupabaseProjectRef={projectRef}+ defaultForeignProjectId={existingProjectGithubConnection?.foreign_project_id}organizationIntegrationId={selectedIntegration?.id}foreignProjects={githubRepos}supabaseProjects={supabaseProjects}- onCreateConnections={createConnections}+ onCreateConnections={createGithubConnection}installedConnections={selectedIntegration?.connections}isLoading={isCreatingConnection}integrationIcon={GITHUB_ICON}diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsxindex 5710c78df3f..496172b0aff 100644--- a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx@@ -6,6 +6,8 @@ import { Button, IconFileText, IconGitBranch, Modal } from 'ui'import BranchingWaitlistPopover from './BranchingWaitlistPopover'import GithubRepositorySelection from './GithubRepositorySelection'import VercelProjectSelection from './VercelProjectSelection'+import SidePanelGitHubRepoLinker from 'components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker'+import { IntegrationName } from 'data/integrations/integrations.types'const EnableBranchingButton = () => {const { ref } = useParams()@@ -13,6 +15,7 @@ const EnableBranchingButton = () => {const selectedOrg = useSelectedOrganization()const [selectedBranch, setSelectedBranch] = useState<string>()+ const [addConnectionType, setAddConnectionType] = useState<IntegrationName>()useEffect(() => {if (open) setSelectedBranch(undefined)@@ -72,6 +75,7 @@ const EnableBranchingButton = () => {integration={githubIntegration}selectedBranch={selectedBranch}setSelectedBranch={setSelectedBranch}+ onSelectConnectRepo={() => setAddConnectionType('GitHub')}/>{/* <VercelProjectSelection integration={vercelIntegration} /> */}@@ -115,6 +119,13 @@ const EnableBranchingButton = () => {</div></Modal.Content></Modal>++ <SidePanelGitHubRepoLinker+ isOpen={addConnectionType === 'GitHub'}+ projectRef={ref}+ organizationIntegrationId={githubIntegration?.id}+ onClose={() => setAddConnectionType(undefined)}+ /></>)}diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsxindex 8cffc3f2c9f..ef0933440eb 100644--- a/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx@@ -29,6 +29,7 @@ interface GithubRepositorySelectionProps {integration?: IntegrationselectedBranch?: stringsetSelectedBranch: (name: string) => void+ onSelectConnectRepo: () => void}// [Joshen TODO] Integrate the Github repo selector@@ -37,6 +38,7 @@ const GithubRepositorySelection = ({integration,selectedBranch,setSelectedBranch,+ onSelectConnectRepo,}: GithubRepositorySelectionProps) => {const { ref } = useParams()const [open, setOpen] = useState(false)@@ -82,10 +84,10 @@ const GithubRepositorySelection = ({</Link>)}{integration && !githubProjectIntegration && (- <div className="border border-dashed rounded !mt-4 flex items-center justify-center py-4 space-x-4">+ <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={() => {}}>- Connect repo+ <Button type="default" onClick={() => onSelectConnectRepo()}>+ Connect repository to project</Button></div>)}@@ -101,7 +103,9 @@ const GithubRepositorySelection = ({<p className="text-sm">{repoName}</p></div></div>- <Button type="default">Configure</Button>+ <Button type="default" onClick={() => onSelectConnectRepo()}>+ Configure+ </Button></div><div className="!mt-4"><p className="text-sm text-light mb-2">Select your production branch:</p>