The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(studio): org integrations layout (FE-3617) (#47007)
Danny White77ecfd59978f
diff --git a/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsxindex 54538cf9ec0..7d4ef739ef9 100644--- a/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx+++ b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx@@ -266,52 +266,81 @@ export const IntegrationConnectionOption = forwardRef<HTMLLIElement, Integration})+type EmptyIntegrationConnectionProps = HTMLAttributes<HTMLDivElement> & {+ showNode?: boolean+ disabled?: boolean+ icon?: ReactNode+ disabledTooltip?: string+} & ({ onClick: () => void; href?: never } | { href: string; onClick?: never })+export const EmptyIntegrationConnection = forwardRef<HTMLDivElement,- HTMLAttributes<HTMLDivElement> & {- showNode?: boolean- onClick: () => void- disabled?: boolean- }->(({ className, showNode = true, onClick, disabled, ...props }, ref) => {- return (- <div- ref={ref}- {...props}- className={cn(- showNode && 'ml-6 pl-8 mt-4 border-l',- 'relative pb-2',- 'last:border-l-transparent',- className- )}- >- {showNode && (- <div className="absolute w-8 rounded-bl-full border-b border-l border-muted h-14 -top-4 -left-px"></div>- )}+ EmptyIntegrationConnectionProps+>(+ (+ {+ className,+ showNode = true,+ onClick,+ href,+ disabled,+ icon,+ disabledTooltip = 'Additional permissions required to add connection',+ children,+ ...props+ },+ ref+ ) => {+ const label = children ?? 'Add new project connection'++ return (<div+ ref={ref}+ {...props}className={cn(- 'w-full',- 'border border-dashed bg-surface-100 border-overlay',- 'flex h-20 px-10 rounded-lg justify-center items-center'+ showNode && 'ml-6 pl-8 mt-4 border-l',+ 'relative pb-2',+ 'last:border-l-transparent',+ className)}>- <ButtonTooltip- variant="default"- disabled={disabled}- onClick={() => onClick()}- tooltip={{- content: {- side: 'bottom',- text: disabled ? 'Additional permissions required to add connection' : undefined,- },- }}+ {showNode && (+ <div className="absolute w-8 rounded-bl-full border-b border-l border-muted h-14 -top-4 -left-px"></div>+ )}+ <div+ className={cn(+ 'w-full',+ 'border border-dashed bg-surface-100 border-overlay',+ 'flex h-20 px-10 rounded-lg justify-center items-center'+ )}>- Add new project connection- </ButtonTooltip>+ {href && !disabled ? (+ <Button icon={icon} asChild variant="default">+ <Link href={href} target="_blank" rel="noreferrer">+ {label}+ </Link>+ </Button>+ ) : (+ <ButtonTooltip+ icon={icon}+ variant="default"+ disabled={disabled}+ onClick={onClick ? () => onClick() : undefined}+ tooltip={{+ content: {+ side: 'bottom',+ text: disabled ? disabledTooltip : undefined,+ },+ }}+ >+ {label}+ </ButtonTooltip>+ )}+ </div></div>- </div>- )-})+ )+ }+)interface IntegrationConnectionHeader extends React.HTMLAttributes<HTMLDivElement> {name?: stringdiff --git a/apps/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx b/apps/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsxindex dadaf1cf727..01f43f3d848 100644--- a/apps/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx+++ b/apps/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx@@ -1,210 +1,16 @@-import { PermissionAction } from '@supabase/shared-types/out/constants'-import { useRouter } from 'next/router'-import { useCallback } from 'react'-import { toast } from 'sonner'-import { GenericSkeletonLoader } from 'ui-patterns'--import { IntegrationConnectionItem } from '../../Integrations/VercelGithub/IntegrationConnection'-import SidePanelVercelProjectLinker from './SidePanelVercelProjectLinker'-import { EmptyIntegrationConnection } from '@/components/interfaces/Integrations/VercelGithub/IntegrationPanels'-import { IntegrationImageHandler } from '@/components/interfaces/Settings/Integrations/IntegrationsSettings'+import { SidePanelVercelProjectLinker } from './SidePanelVercelProjectLinker'+import { GitHubSection } from '@/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection'import { VercelSection } from '@/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection'-import {- ScaffoldContainer,- ScaffoldContainerLegacy,- ScaffoldDivider,- ScaffoldSection,- ScaffoldSectionContent,- ScaffoldSectionDetail,- ScaffoldTitle,-} from '@/components/layouts/Scaffold'-import { InlineLink } from '@/components/ui/InlineLink'-import NoPermission from '@/components/ui/NoPermission'-import { useGitHubAuthorizationQuery } from '@/data/integrations/github-authorization-query'-import { useGitHubConnectionDeleteMutation } from '@/data/integrations/github-connection-delete-mutation'-import {- useGitHubConnectionsQuery,- type GitHubConnection,-} from '@/data/integrations/github-connections-query'-import type { IntegrationProjectConnection } from '@/data/integrations/integrations.types'-import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'-import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'-import {- GITHUB_INTEGRATION_INSTALLATION_URL,- GITHUB_INTEGRATION_REVOKE_AUTHORIZATION_URL,-} from '@/lib/github'-import { SHORTCUT_IDS } from '@/state/shortcuts/registry'-import { useShortcut } from '@/state/shortcuts/useShortcut'--type GitHubSectionProps = {- canCreateGitHubConnection: boolean- canReadGithubConnection: boolean- canUpdateGitHubConnection: boolean- connections?: GitHubConnection[]- isGitHubAuthorized: boolean- isLoadingPermissions: boolean- onAddGitHubConnection: () => void- onDeleteGitHubConnection: (connection: IntegrationProjectConnection) => void | Promise<void>-}--const GitHubSection = ({- canCreateGitHubConnection,- canReadGithubConnection,- canUpdateGitHubConnection,- connections,- isGitHubAuthorized,- isLoadingPermissions,- onAddGitHubConnection,- onDeleteGitHubConnection,-}: GitHubSectionProps) => (- <ScaffoldContainer>- <ScaffoldSection className="py-12">- <ScaffoldSectionDetail title="GitHub Connections">- <p>Connect any of your GitHub repositories to a project.</p>- <IntegrationImageHandler title="github" />- </ScaffoldSectionDetail>- <ScaffoldSectionContent>- {isLoadingPermissions ? (- <GenericSkeletonLoader />- ) : !canReadGithubConnection ? (- <NoPermission resourceText="view this organization's GitHub connections" />- ) : (- <div className="space-y-6">- <div className="space-y-1">- <h3 className="text-sm font-medium text-foreground">- How do GitHub connections work?- </h3>- <p className="text-sm text-foreground-light">- Connect a GitHub repository to a Supabase project. The GitHub app watches file,- branch, and pull request activity in your repository.- </p>- </div>-- <div>- <ul className="flex flex-col gap-y-2">- {connections?.map((connection) => (- <IntegrationConnectionItem- key={connection.id}- disabled={!canUpdateGitHubConnection}- connection={{- id: String(connection.id),- added_by: {- id: String(connection.user?.id),- primary_email: connection.user?.primary_email ?? '',- username: connection.user?.username ?? '',- },- foreign_project_id: String(connection.repository.id),- supabase_project_ref: connection.project.ref,- organization_integration_id: 'unused',- inserted_at: connection.inserted_at,- updated_at: connection.updated_at,- metadata: {- name: connection.repository.name,- } as IntegrationProjectConnection['metadata'],- }}- type="GitHub"- onDeleteConnection={onDeleteGitHubConnection}- />- ))}- </ul>-- <EmptyIntegrationConnection- onClick={onAddGitHubConnection}- showNode={false}- disabled={!canCreateGitHubConnection}- >- Add new project connection- </EmptyIntegrationConnection>- </div>-- {isGitHubAuthorized && (- <p className="text-sm text-foreground-light">- You are authorized with the Supabase GitHub App. You can configure your{' '}- <InlineLink href={GITHUB_INTEGRATION_INSTALLATION_URL}>- GitHub App installations and repository access- </InlineLink>- , or{' '}- <InlineLink href={GITHUB_INTEGRATION_REVOKE_AUTHORIZATION_URL}>- revoke your authorization- </InlineLink>- .- </p>- )}- </div>- )}- </ScaffoldSectionContent>- </ScaffoldSection>- </ScaffoldContainer>-)export const IntegrationSettings = () => {- const router = useRouter()- const { data: org } = useSelectedOrganizationQuery()-const showVercelIntegration = useIsFeatureEnabled('integrations:vercel')- const { can: canReadGithubConnection, isLoading: isLoadingPermissions } =- useAsyncCheckPermissions(PermissionAction.READ, 'integrations.github_connections')- const { can: canCreateGitHubConnection } = useAsyncCheckPermissions(- PermissionAction.CREATE,- 'integrations.github_connections'- )- const { can: canUpdateGitHubConnection } = useAsyncCheckPermissions(- PermissionAction.UPDATE,- 'integrations.github_connections'- )-- const { data: gitHubAuthorization } = useGitHubAuthorizationQuery()- const { data: connections } = useGitHubConnectionsQuery({ organizationId: org?.id })-- const { mutate: deleteGitHubConnection } = useGitHubConnectionDeleteMutation({- onSuccess: () => {- toast.success('Successfully deleted GitHub connection')- },- })-- const onAddGitHubConnection = useCallback(() => {- router.push('/project/_/settings/integrations')- }, [router])-- useShortcut(SHORTCUT_IDS.ORG_INTEGRATIONS_ADD_CONNECTION, onAddGitHubConnection, {- enabled: canCreateGitHubConnection,- })-- const onDeleteGitHubConnection = useCallback(- async (connection: IntegrationProjectConnection) => {- if (!org?.id) {- toast.error('Organization not found')- return- }-- deleteGitHubConnection({- connectionId: connection.id,- organizationId: org.id,- })- },- [deleteGitHubConnection, org?.id]- )-return (<>- <ScaffoldContainerLegacy>- <ScaffoldTitle>Integrations</ScaffoldTitle>- </ScaffoldContainerLegacy>- <GitHubSection- canCreateGitHubConnection={canCreateGitHubConnection}- canReadGithubConnection={canReadGithubConnection}- canUpdateGitHubConnection={canUpdateGitHubConnection}- connections={connections}- isGitHubAuthorized={Boolean(gitHubAuthorization)}- isLoadingPermissions={isLoadingPermissions}- onAddGitHubConnection={onAddGitHubConnection}- onDeleteGitHubConnection={onDeleteGitHubConnection}- />+ <GitHubSection isProjectScoped={false} />{showVercelIntegration && (<>- <ScaffoldDivider /><VercelSection isProjectScoped={false} /><SidePanelVercelProjectLinker /></>diff --git a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsxindex 44ad75a9c30..1f181eb7617 100644--- a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx+++ b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx@@ -1,6 +1,8 @@import { PermissionAction } from '@supabase/shared-types/out/constants'import { useParams } from 'common'-import { useMemo } from 'react'+import { useRouter } from 'next/router'+import { useCallback, useMemo } from 'react'+import { toast } from 'sonner'import {PageSection,PageSectionContent,@@ -13,39 +15,116 @@ import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'import { IntegrationSectionIcon } from '../IntegrationsSettings'import { GitHubIntegrationConnectionForm } from './GitHubIntegrationConnectionForm'+import { IntegrationConnectionItem } from '@/components/interfaces/Integrations/VercelGithub/IntegrationConnection'+import { EmptyIntegrationConnection } from '@/components/interfaces/Integrations/VercelGithub/IntegrationPanels'+import { InlineLink } from '@/components/ui/InlineLink'import NoPermission from '@/components/ui/NoPermission'-import { useGitHubConnectionsQuery } from '@/data/integrations/github-connections-query'+import { useGitHubAuthorizationQuery } from '@/data/integrations/github-authorization-query'+import { useGitHubConnectionDeleteMutation } from '@/data/integrations/github-connection-delete-mutation'+import {+ useGitHubConnectionsQuery,+ type GitHubConnection,+} from '@/data/integrations/github-connections-query'+import type { IntegrationProjectConnection } from '@/data/integrations/integrations.types'import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'+import {+ GITHUB_INTEGRATION_INSTALLATION_URL,+ GITHUB_INTEGRATION_REVOKE_AUTHORIZATION_URL,+} from '@/lib/github'+import { SHORTCUT_IDS } from '@/state/shortcuts/registry'+import { useShortcut } from '@/state/shortcuts/useShortcut'-export const GitHubSection = () => {+const toIntegrationProjectConnection = (+ connection: GitHubConnection+): IntegrationProjectConnection => ({+ id: String(connection.id),+ added_by: {+ id: String(connection.user?.id),+ primary_email: connection.user?.primary_email ?? '',+ username: connection.user?.username ?? '',+ },+ foreign_project_id: String(connection.repository.id),+ supabase_project_ref: connection.project.ref,+ organization_integration_id: 'unused',+ inserted_at: connection.inserted_at,+ updated_at: connection.updated_at,+ metadata: {+ name: connection.repository.name,+ } as IntegrationProjectConnection['metadata'],+})++export const GitHubSection = ({ isProjectScoped }: { isProjectScoped: boolean }) => {+ const router = useRouter()const { ref: projectRef } = useParams()- const { data: organization } = useSelectedOrganizationQuery()+ const { data: org } = useSelectedOrganizationQuery()const { can: canReadGitHubConnection, isLoading: isLoadingPermissions } =useAsyncCheckPermissions(PermissionAction.READ, 'integrations.github_connections')+ const { can: canCreateGitHubConnection } = useAsyncCheckPermissions(+ PermissionAction.CREATE,+ 'integrations.github_connections'+ )+ const { can: canUpdateGitHubConnection } = useAsyncCheckPermissions(+ PermissionAction.UPDATE,+ 'integrations.github_connections'+ )+ const { data: gitHubAuthorization } = useGitHubAuthorizationQuery({+ enabled: !isProjectScoped,+ })const { data: connections } = useGitHubConnectionsQuery(- { organizationId: organization?.id },- { enabled: !!projectRef && !!organization?.id }+ { organizationId: org?.id },+ { enabled: isProjectScoped ? !!projectRef && !!org?.id : !!org?.id })+ const { mutate: deleteGitHubConnection } = useGitHubConnectionDeleteMutation({+ onSuccess: () => {+ toast.success('Successfully deleted GitHub connection')+ },+ })+const existingConnection = useMemo(() => connections?.find((c) => c.project.ref === projectRef),[connections, projectRef])+ const onAddGitHubConnection = useCallback(() => {+ router.push('/project/_/settings/integrations')+ }, [router])++ useShortcut(SHORTCUT_IDS.ORG_INTEGRATIONS_ADD_CONNECTION, onAddGitHubConnection, {+ enabled: !isProjectScoped && canCreateGitHubConnection,+ })++ const onDeleteGitHubConnection = useCallback(+ async (connection: IntegrationProjectConnection) => {+ if (!org?.id) {+ toast.error('Organization not found')+ return+ }++ deleteGitHubConnection({+ connectionId: connection.id,+ organizationId: org.id,+ })+ },+ [deleteGitHubConnection, org?.id]+ )+return (<PageSection><PageSectionMeta><div className="flex flex-1 items-start gap-6"><IntegrationSectionIcon title="github" /><PageSectionSummary>- <PageSectionTitle>GitHub Integration</PageSectionTitle>+ <PageSectionTitle>+ {isProjectScoped ? 'GitHub Integration' : 'GitHub Connections'}+ </PageSectionTitle><PageSectionDescription>- Connect any of your GitHub repositories to a project. Supabase applies database- changes when you merge into your production branch. If branching is enabled, each pull- request gets its own preview database.+ {isProjectScoped+ ? 'Connect any of your GitHub repositories to a project. Supabase applies database changes when you merge into your production branch. If branching is enabled, each pull request gets its own preview database.'+ : 'Connect any of your GitHub repositories to a project. The GitHub app watches file, branch, and pull request activity in your repository.'}</PageSectionDescription></PageSectionSummary></div>@@ -55,8 +134,46 @@ export const GitHubSection = () => {<GenericSkeletonLoader />) : !canReadGitHubConnection ? (<NoPermission resourceText="view this organization's GitHub connections" />- ) : (+ ) : isProjectScoped ? (<GitHubIntegrationConnectionForm connection={existingConnection} />+ ) : (+ <div className="space-y-6">+ <div>+ <ul className="flex flex-col gap-y-2">+ {connections?.map((connection) => (+ <IntegrationConnectionItem+ key={connection.id}+ disabled={!canUpdateGitHubConnection}+ connection={toIntegrationProjectConnection(connection)}+ type="GitHub"+ onDeleteConnection={onDeleteGitHubConnection}+ />+ ))}+ </ul>++ <EmptyIntegrationConnection+ onClick={onAddGitHubConnection}+ showNode={false}+ disabled={!canCreateGitHubConnection}+ >+ Add new project connection+ </EmptyIntegrationConnection>+ </div>++ {gitHubAuthorization && (+ <p className="text-sm text-foreground-light">+ You are authorized with the Supabase GitHub App. You can configure your{' '}+ <InlineLink href={GITHUB_INTEGRATION_INSTALLATION_URL}>+ GitHub App installations and repository access+ </InlineLink>+ , or{' '}+ <InlineLink href={GITHUB_INTEGRATION_REVOKE_AUTHORIZATION_URL}>+ revoke your authorization+ </InlineLink>+ .+ </p>+ )}+ </div>)}</PageSectionContent></PageSection>diff --git a/apps/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx b/apps/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsxindex 5a0822d5b16..03d16b8ca75 100644--- a/apps/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx+++ b/apps/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx@@ -79,7 +79,7 @@ export const IntegrationSettings = () => {</Admonition>)}- <GitHubSection />+ <GitHubSection isProjectScoped={true} />{showVercelIntegration && (<>diff --git a/apps/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx b/apps/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsxindex 7ed0d0dff68..4b07624a1fd 100644--- a/apps/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx+++ b/apps/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx@@ -1,9 +1,8 @@import { PermissionAction } from '@supabase/shared-types/out/constants'import { ExternalLink } from 'lucide-react'-import Link from 'next/link'import { useCallback, useMemo } from 'react'import { toast } from 'sonner'-import { Button, cn } from 'ui'+import { cn } from 'ui'import {PageSection,PageSectionContent,@@ -217,22 +216,15 @@ export const VercelSection = ({ isProjectScoped }: { isProjectScoped: boolean })</EmptyIntegrationConnection></div>) : (- <div>- <Button- icon={<ExternalLink />}- asChild={!isBranch}- variant="default"- disabled={isBranch}- >- {isBranch ? (- <p>Install Vercel Integration</p>- ) : (- <Link href={integrationUrl} target="_blank" rel="noreferrer">- Install Vercel Integration- </Link>- )}- </Button>- </div>+ <EmptyIntegrationConnection+ showNode={false}+ disabled={isBranch}+ href={integrationUrl}+ icon={<ExternalLink />}+ disabledTooltip="Install Vercel Integration on your project's main branch"+ >+ Install Vercel Integration+ </EmptyIntegrationConnection>)}</div>{vercelProjectCount > 0 && vercelIntegration !== undefined && (diff --git a/apps/studio/pages/org/[slug]/integrations.tsx b/apps/studio/pages/org/[slug]/integrations.tsxindex 98500af439e..0aa36a51f55 100644--- a/apps/studio/pages/org/[slug]/integrations.tsx+++ b/apps/studio/pages/org/[slug]/integrations.tsx@@ -1,10 +1,35 @@+import { PageContainer } from 'ui-patterns/PageContainer'+import {+ PageHeader,+ PageHeaderDescription,+ PageHeaderMeta,+ PageHeaderSummary,+ PageHeaderTitle,+} from 'ui-patterns/PageHeader'+import { IntegrationSettings } from '@/components/interfaces/Organization/IntegrationSettings/IntegrationSettings'import DefaultLayout from '@/components/layouts/DefaultLayout'import OrganizationLayout from '@/components/layouts/OrganizationLayout'import type { NextPageWithLayout } from '@/types'const OrgIntegrationSettings: NextPageWithLayout = () => {- return <IntegrationSettings />+ return (+ <>+ <PageHeader size="small">+ <PageHeaderMeta>+ <PageHeaderSummary>+ <PageHeaderTitle>Integrations</PageHeaderTitle>+ <PageHeaderDescription>+ Connect external services to your organization+ </PageHeaderDescription>+ </PageHeaderSummary>+ </PageHeaderMeta>+ </PageHeader>+ <PageContainer size="small">+ <IntegrationSettings />+ </PageContainer>+ </>+ )}OrgIntegrationSettings.getLayout = (page) => (