Skip to content

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

add new GitHub connection form for project settings

Jonathan Summers-Muir0f89d4584904
diff --git a/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx b/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx
index 5dbf87de0d9..2d5a5a35a20 100644
--- a/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx
+++ b/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx
@@ -1,46 +1,62 @@
-import { useCallback, useState } from 'react'
+import { zodResolver } from '@hookform/resolvers/zod'
+import {
+ EmptyIntegrationConnection,
+ IntegrationConnectionHeader,
+ IntegrationInstallation,
+} from 'components/interfaces/Integrations/IntegrationPanels'
+import { Markdown } from 'components/interfaces/Markdown'
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import {
ScaffoldContainer,
ScaffoldDivider,
- ScaffoldSectionContent,
ScaffoldSection,
+ ScaffoldSectionContent,
ScaffoldSectionDetail,
} from 'components/layouts/Scaffold'
import { useIntegrationsGitHubInstalledConnectionDeleteMutation } from 'data/integrations/integrations-github-connection-delete-mutation'
import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
import { useIntegrationsVercelInstalledConnectionDeleteMutation } from 'data/integrations/integrations-vercel-installed-connection-delete-mutation'
import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-projects-query'
-import { IntegrationName, IntegrationProjectConnection } from 'data/integrations/integrations.types'
-import { getIntegrationConfigurationUrl } from 'lib/integration-utils'
-import { IntegrationConnectionItem } from '../../Integrations/IntegrationConnection'
-import SidePanelGitHubRepoLinker from './../../Organization/IntegrationSettings/SidePanelGitHubRepoLinker'
-import SidePanelVercelProjectLinker from './../../Organization/IntegrationSettings/SidePanelVercelProjectLinker'
+import {
+ IntegrationName,
+ IntegrationProjectConnection,
+ Integration,
+} from 'data/integrations/integrations.types'
import { useSelectedOrganization } from 'hooks'
-import { useSidePanelsStateSnapshot } from 'state/side-panels'
-import { Markdown } from 'components/interfaces/Markdown'
import { BASE_PATH } from 'lib/constants'
-import {
- EmptyIntegrationConnection,
- IntegrationConnectionHeader,
- IntegrationInstallation,
-} from 'components/interfaces/Integrations/IntegrationPanels'
import { pluralize } from 'lib/helpers'
-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
+import { getIntegrationConfigurationUrl } from 'lib/integration-utils'
+import { useCallback, useRef, useState } from 'react'
+import { useForm } from 'react-hook-form'
+import { useSidePanelsStateSnapshot } from 'state/side-panels'
import {
Button,
+ CommandEmpty_Shadcn_,
+ CommandGroup_Shadcn_,
+ CommandInput_Shadcn_,
+ CommandItem_Shadcn_,
+ CommandList_Shadcn_,
+ Command_Shadcn_,
FormControl_Shadcn_,
FormDescription_Shadcn_,
FormField_Shadcn_,
FormItem_Shadcn_,
FormLabel_Shadcn_,
Form_Shadcn_,
- Input,
+ IconCheck,
+ IconChevronDown,
+ Input_Shadcn_,
+ PopoverContent_Shadcn_,
+ PopoverTrigger_Shadcn_,
+ Popover_Shadcn_,
Switch,
cn,
} from 'ui'
import * as z from 'zod'
-import { useForm } from 'react-hook-form'
-import { zodResolver } from '@hookform/resolvers/zod'
+import { IntegrationConnectionItem } from '../../Integrations/IntegrationConnection'
+import SidePanelGitHubRepoLinker from './../../Organization/IntegrationSettings/SidePanelGitHubRepoLinker'
+import SidePanelVercelProjectLinker from './../../Organization/IntegrationSettings/SidePanelVercelProjectLinker'
+import { useGithubBranchesQuery } from 'data/integrations/integrations-github-branches-query'
const IntegrationImageHandler = ({ title }: { title: 'vercel' | 'github' }) => {
return (
@@ -203,11 +219,8 @@ You can change the scope of the access for Supabase by configuring
className="!rounded-b-none !mb-0"
/>
<div className="relative pl-8 ml-6 border-l border-scale-600 dark:border-scale-400 pb-3">
- <div className="border-b border-l border-r rounded-b-md px-8 py-4">
- <FormThing />
-
- {/* <label className="text-sm text-light">Production branch</label>
- <Input /> */}
+ <div className="border-b border-l border-r rounded-b-md">
+ <VercelIntegrationConnectionForm connection={connection} />
</div>
</div>
</div>
@@ -238,16 +251,27 @@ You can change the scope of the access for Supabase by configuring
</ScaffoldContainer>
)
- const FormThing = () => {
+ const VercelIntegrationConnectionForm = ({
+ connection,
+ }: {
+ connection: IntegrationProjectConnection
+ }) => {
const FormSchema = z.object({
- marketing_emails: z.boolean().default(false).optional(),
- security_emails: z.boolean(),
+ environmentVariablesProduction: z.boolean().default(false),
+ environmentVariablesPreview: z.boolean().default(false),
+ authRedirectUrisProduction: z.boolean().default(false),
+ authRedirectUrisPreview: z.boolean().default(false),
})
+ const config = connection.metadata.supabaseConfig
+
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
- security_emails: true,
+ environmentVariablesProduction: config.environmentVariables?.production ?? false,
+ environmentVariablesPreview: config.environmentVariables?.preview ?? false,
+ authRedirectUrisProduction: config.authRedirectUris?.production ?? false,
+ authRedirectUrisPreview: config.authRedirectUris?.preview ?? false,
},
})
@@ -266,10 +290,10 @@ You can change the scope of the access for Supabase by configuring
<Form_Shadcn_ {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="w-full space-y-6">
<div>
- <div className="flex flex-col gap-6">
+ <div className="flex flex-col gap-6 px-8 py-8">
<FormField_Shadcn_
control={form.control}
- name="marketing_emails"
+ name="environmentVariablesProduction"
render={({ field }) => (
<FormItem_Shadcn_ className="flex flex-row items-center justify-between">
<div className="">
@@ -288,7 +312,30 @@ You can change the scope of the access for Supabase by configuring
/>
<FormField_Shadcn_
control={form.control}
- name="security_emails"
+ name="authRedirectUrisProduction"
+ render={({ field }) => (
+ <FormItem_Shadcn_ className="flex flex-row items-center justify-between">
+ <div className="">
+ <FormLabel_Shadcn_ className="!text">
+ Auto manage Supabase Auth redirect URIs
+ </FormLabel_Shadcn_>
+ <FormDescription_Shadcn_ className="text-xs">
+ Deploy Edge Functions when merged into Production Beanch
+ </FormDescription_Shadcn_>
+ </div>
+ <FormControl_Shadcn_>
+ <Switch checked={field.value} onCheckedChange={field.onChange} />
+ </FormControl_Shadcn_>
+ </FormItem_Shadcn_>
+ )}
+ />
+ </div>
+ <ScaffoldDivider />
+ <div className="flex flex-col gap-6 px-8 py-8">
+ <h5 className="text-sm">Database Branching configuration </h5>
+ <FormField_Shadcn_
+ control={form.control}
+ name="environmentVariablesPreview"
render={({ field }) => (
<FormItem_Shadcn_ className="flex flex-row items-center justify-between">
<div className="">
@@ -307,12 +354,12 @@ You can change the scope of the access for Supabase by configuring
/>
<FormField_Shadcn_
control={form.control}
- name="security_emails"
+ name="authRedirectUrisPreview"
render={({ field }) => (
<FormItem_Shadcn_ className="flex flex-row items-center justify-between">
<div className="">
<FormLabel_Shadcn_ className="!text">
- Auto manage Supabase Auth redirect URIs
+ Auto manage Supabase Auth redirect URIs for Preview deployments
</FormLabel_Shadcn_>
<FormDescription_Shadcn_ className="text-xs">
Deploy Edge Functions when merged into Production Beanch
@@ -375,17 +422,40 @@ These connections will be part of a GitHub workflow that is currently in develop
{integration.connections.length > 0 ? (
<>
<IntegrationConnectionHeader
- title={ConnectionHeaderTitle}
- markdown={`Repository connections for GitHub`}
+ // title={ConnectionHeaderTitle}
+ // markdown={`Repository connections for GitHub`}
/>
<ul className="flex flex-col">
{integration.connections.map((connection) => (
- <IntegrationConnectionItem
+ <div
key={connection.id}
- connection={connection}
- type={'GitHub' as IntegrationName}
- onDeleteConnection={onDeleteGitHubConnection}
- />
+ className="relative flex flex-col -gap-[1px] [&>li]:pb-0"
+ >
+ <IntegrationConnectionItem
+ showNode={false}
+ key={connection.id}
+ connection={connection}
+ type={'GitHub' as IntegrationName}
+ onDeleteConnection={onDeleteGitHubConnection}
+ className="!rounded-b-none !mb-0"
+ />
+
+ <div className="border-b border-l border-r">
+ <GitHubIntegrationConnectionForm
+ connection={connection}
+ integration={integration}
+ />
+ </div>
+ {/* <Alert_Shadcn_ className="!border-t-transparent rounded-t-none [&>svg]:left-8 !px-10">
+ <AlertTitle_Shadcn_>
+ Only 1 GitHub connection per project
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Due to the nature of how GitHub connections work, only 1 connection
+ can be made per project to avoid migration conflicts.
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_> */}
+ </div>
))}
</ul>
</>
@@ -397,9 +467,6 @@ These connections will be part of a GitHub workflow that is currently in develop
)} Repository connections for GitHub`}
/>
)}
- <EmptyIntegrationConnection onClick={() => onAddGitHubConnection(integration.id)}>
- Add new project connection
- </EmptyIntegrationConnection>
</div>
)
})}
@@ -408,11 +475,175 @@ These connections will be part of a GitHub workflow that is currently in develop
</ScaffoldContainer>
)
+ const GitHubIntegrationConnectionForm = ({
+ connection,
+ integration,
+ }: {
+ connection: IntegrationProjectConnection
+ integration: Integration
+ }) => {
+ const [open, setOpen] = useState(false)
+ const comboBoxRef = useRef<HTMLButtonElement>(null)
+ const [selectedBranch, setSelectedBranch] = useState<string>()
+
+ const FormSchema = z.object({
+ productionBranch: z.boolean().default(false),
+ supabaseDirectory: z.boolean().default(false),
+ })
+
+ const projectContext = useProjectContext()
+
+ const config = connection.metadata.supabaseConfig ?? {}
+
+ const form = useForm<z.infer<typeof FormSchema>>({
+ resolver: zodResolver(FormSchema),
+ defaultValues: {
+ productionBranch: config.environmentVariables?.production ?? false,
+ supabaseDirectory: config.environmentVariables?.preview ?? false,
+ },
+ })
+
+ function onSubmit(data: z.infer<typeof FormSchema>) {
+ // toast({
+ // title: 'You submitted the following values:',
+ // description: (
+ // <pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
+ // <code className="text-white">{JSON.stringify(data, null, 2)}</code>
+ // </pre>
+ // ),
+ // })
+ }
+
+ const githubProjectIntegration = integration?.connections.find(
+ (connection) => connection.supabase_project_ref === projectContext.project?.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 (
+ <Form_Shadcn_ {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)} className="w-full space-y-6">
+ <div className="flex flex-col gap-6 px-8 py-8">
+ <FormField_Shadcn_
+ control={form.control}
+ name="supabaseDirectory"
+ render={({ field }) => (
+ <FormItem_Shadcn_ className="flex flex-col">
+ <>
+ {isSuccessBranches && (
+ <>
+ <FormLabel_Shadcn_ className="!text">Production branch</FormLabel_Shadcn_>
+ <FormDescription_Shadcn_ className="text-xs">
+ Deploy Edge Functions when merged into Production branch
+ </FormDescription_Shadcn_>
+ <Popover_Shadcn_ open={open} onOpenChange={setOpen} modal={false}>
+ <PopoverTrigger_Shadcn_ asChild name="branch-selector">
+ <Button
+ block
+ type="default"
+ size="medium"
+ ref={comboBoxRef}
+ className={cn(
+ 'justify-start w-64',
+ selectedBranch === undefined ? 'text-light' : 'text'
+ )}
+ iconRight={
+ <span className="grow flex justify-end">
+ <IconChevronDown className={''} />
+ </span>
+ }
+ >
+ {selectedBranch || 'Select a branch'}
+ </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_>
+ </>
+ )}
+ </>
+ </FormItem_Shadcn_>
+ )}
+ />
+ <FormField_Shadcn_
+ control={form.control}
+ name="productionBranch"
+ render={({ field }) => (
+ <FormItem_Shadcn_ className="flex flex-col">
+ <>
+ <FormLabel_Shadcn_ className="!text">Supabase directory</FormLabel_Shadcn_>
+ <FormDescription_Shadcn_ className="text-xs">
+ Deploy Edge Functions when merged into Production branch
+ </FormDescription_Shadcn_>
+ <div className="flex flex-row gap-3">
+ <FormControl_Shadcn_ className="xl:w-96">
+ <Input_Shadcn_ onChange={field.onChange} />
+ </FormControl_Shadcn_>
+ <Button type="default" size={'small'}>
+ Update
+ </Button>
+ </div>
+ </>
+ </FormItem_Shadcn_>
+ )}
+ />
+ </div>
+ </form>
+ </Form_Shadcn_>
+ )
+ }
+
return (
<>
- <VercelSection />
- <ScaffoldDivider />
<GitHubSection />
+ <ScaffoldDivider />
+ <VercelSection />
<SidePanelVercelProjectLinker />
<SidePanelGitHubRepoLinker />
</>
diff --git a/studio/data/integrations/integrations.types.ts b/studio/data/integrations/integrations.types.ts
index eb2bf344d11..dc7c3583dc7 100644
--- a/studio/data/integrations/integrations.types.ts
+++ b/studio/data/integrations/integrations.types.ts
@@ -117,8 +117,13 @@ export type VercelGitLink =
export type Imetadata = {
id: string
supabaseConfig: {
- projectEnvVars: {
- write: boolean
+ environmentVariables: {
+ production: boolean
+ preview: boolean
+ }
+ authRedirectUris: {
+ production: boolean
+ preview: boolean
}
}
link?: VercelGitLink
diff --git a/studio/state/side-panels.ts b/studio/state/side-panels.ts
index 65fdbc61f70..776d308ed9a 100644
--- a/studio/state/side-panels.ts
+++ b/studio/state/side-panels.ts
@@ -1,6 +1,30 @@
+import types from 'pages/api/pg-meta/[ref]/types'
import { proxy, snapshot, useSnapshot } from 'valtio'
+export type SidePanelTypeProps = 'VERCEL_CONNECTIONS' | 'GITHUB_CONNECTIONS'
+
+// export type OpenProps =
+// | { type: 'VERCEL_CONNECTIONS'; integrationId: string }
+// | { type: 'GITHUB_CONNECTIONS'; integrationId: string }
+
export const sidePanelsState = proxy({
+ // setOpen: (type: SidePanelTypeProps, integrationId: string) => {
+ // sidePanelsState.integrationConnections = type
+ // switch (type) {
+ // case 'VERCEL_CONNECTIONS':
+ // sidePanelsState.vercelConnectionsIntegrationId = integrationId
+ // break
+ // case 'GITHUB_CONNECTIONS':
+ // sidePanelsState.githubConnectionsIntegrationId = integrationId
+ // break
+ // }
+ // },
+ // setClosed: () => {
+ // sidePanelsState.integrationConnections = false
+ // },
+
+ // integrationConnections: false as SidePanelTypeProps | false,
+
/**
* Vercel connections
*/