Skip to content

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

chore: you can now add new connections via dashboard

Jonathan Summers-Muirf8d94c647abb
diff --git a/studio/components/interfaces/Integrations/IntegrationPanels.tsx b/studio/components/interfaces/Integrations/IntegrationPanels.tsx
index 5aa16fbbde3..e8a3352fded 100644
--- a/studio/components/interfaces/Integrations/IntegrationPanels.tsx
+++ b/studio/components/interfaces/Integrations/IntegrationPanels.tsx
@@ -49,7 +49,6 @@ const HandleIcon = ({ type }: { type: HandleIconType }) => {
}
const Avatar = ({ src }: { src: string }) => {
- console.log('src of avatar', src)
return (
<div className="relative border shadow-lg w-8 h-8 rounded-full overflow-hidden">
<Image src={src} width={30} height={30} layout="fill" alt="avatar" className="relative" />
diff --git a/studio/components/interfaces/Integrations/ProjectLinker.tsx b/studio/components/interfaces/Integrations/ProjectLinker.tsx
index 570de471499..3b0553124f1 100644
--- a/studio/components/interfaces/Integrations/ProjectLinker.tsx
+++ b/studio/components/interfaces/Integrations/ProjectLinker.tsx
@@ -2,7 +2,9 @@ import { ENV_VAR_RAW_KEYS } from 'components/interfaces/Integrations/Integration
import { Markdown } from 'components/interfaces/Markdown'
import { vercelIcon } from 'components/to-be-cleaned/ListIcons'
import { useIntegrationConnectionsCreateMutation } from 'data/integrations/integration-connections-create-mutation'
+import { Integration, IntegrationProjectConnection } from 'data/integrations/integrations-query'
import { VercelProjectsResponse } from 'data/integrations/integrations-vercel-projects-query'
+import { useStore } from 'hooks'
import { BASE_PATH } from 'lib/constants'
import { useState } from 'react'
import { Button, IconArrowRight, IconPlus, IconX, Input, Listbox, Select, cn } from 'ui'
@@ -20,7 +22,7 @@ export interface ProjectLinkerProps {
foreignProjects: VercelProjectsResponse[]
supabaseProjects: Project[]
onCreateConnections?: () => void
- installedConnections?: any[]
+ installedConnections: IntegrationProjectConnection[] | undefined
}
const UNDEFINED_SELECT_VALUE = 'undefined'
@@ -31,10 +33,12 @@ const ProjectLinker = ({
foreignProjects,
supabaseProjects,
onCreateConnections: _onCreateConnections,
- installedConnections,
+ installedConnections = [],
}: ProjectLinkerProps) => {
- const [supabaseProjectId, setSupabaseProjectId] = useState('')
- const [vercelProjectId, setVercelProjectId] = useState('')
+ const { ui } = useStore()
+
+ const [supabaseProjectId, setSupabaseProjectId] = useState(UNDEFINED_SELECT_VALUE)
+ const [vercelProjectId, setVercelProjectId] = useState(UNDEFINED_SELECT_VALUE)
// function addConnection() {
// setConnections([
@@ -54,6 +58,8 @@ const ProjectLinker = ({
// setConnections(newConnections)
// }
+ // console.log('installed connections', installedConnections)
+
const { mutate: createConnections, isLoading } = useIntegrationConnectionsCreateMutation({
onSuccess() {
_onCreateConnections?.()
@@ -78,6 +84,7 @@ const ProjectLinker = ({
},
},
},
+ orgId: ui.selectedOrganization?.id,
})
}
@@ -95,9 +102,22 @@ const ProjectLinker = ({
)
}
+ /**
+ * create a flat array of foreign project ids. ie, ["prj_MlkO6AiLG5ofS9ojKrkS3PhhlY3f", ..]
+ */
+ const flatInstalledConnectionsIds = installedConnections.map((x) => x.foreign_project_id)
+ /**
+ * check that vercel project is not already installed
+ */
+ const filteredForeignProjects: VercelProjectsResponse[] = foreignProjects.filter(
+ (foreignProject) => {
+ return !flatInstalledConnectionsIds.includes(foreignProject.id)
+ }
+ )
+
return (
<div className="flex flex-col gap-4">
- <div className="relative border rounded-lg p-12 bg border-body">
+ <div className="relative border rounded- lg p-12 bg border-body">
<div
className="absolute inset-0 bg-grid-white/5 [mask-image:linear-gradient(0deg,#fff,rgba(255,255,255,0.6))] dark:bg-grid-slate-700/25 dark:[mask-image:linear-gradient(0deg,rgba(255,255,255,0.1),rgba(255,255,255,0.5))]"
style={{ backgroundPosition: '10px 10px' }}
@@ -160,31 +180,33 @@ const ProjectLinker = ({
<Listbox.Option value={UNDEFINED_SELECT_VALUE} label="Choose a project" disabled>
Choose a Vercel project
</Listbox.Option>
- {foreignProjects.map((project) => (
- <Listbox.Option
- key={project.id}
- value={project.id}
- label={project.name}
- addOnBefore={() => {
- return (
- <>
- {!project?.framework ? (
- vercelIcon
- ) : (
- <img
- src={`/img/icons/frameworks/${project.framework}.svg`}
- width={21}
- height={21}
- alt={`icon`}
- />
- )}
- </>
- )
- }}
- >
- {project.name}
- </Listbox.Option>
- ))}
+ {filteredForeignProjects.map((project) => {
+ return (
+ <Listbox.Option
+ key={project.id}
+ value={project.id}
+ label={project.name}
+ addOnBefore={() => {
+ return (
+ <>
+ {!project?.framework ? (
+ vercelIcon
+ ) : (
+ <img
+ src={`/img/icons/frameworks/${project.framework}.svg`}
+ width={21}
+ height={21}
+ alt={`icon`}
+ />
+ )}
+ </>
+ )
+ }}
+ >
+ {project.name}
+ </Listbox.Option>
+ )
+ })}
</Listbox>
</Panel>
</div>
diff --git a/studio/components/interfaces/Organization/IntegrationSettings/Integration.tsx b/studio/components/interfaces/Organization/IntegrationSettings/Integration.tsx
index cf4a11985df..3bd3b2434c3 100644
--- a/studio/components/interfaces/Organization/IntegrationSettings/Integration.tsx
+++ b/studio/components/interfaces/Organization/IntegrationSettings/Integration.tsx
@@ -1,4 +1,3 @@
-import { useParams } from 'common'
import {
EmptyIntegrationConnection,
IntegrationConnection,
@@ -12,16 +11,11 @@ import {
ScaffoldSectionContent,
ScaffoldSectionDetail,
} from 'components/layouts/Scaffold'
-import { useIntegrationConnectionsCreateMutation } from 'data/integrations/integration-connections-create-mutation'
-import {
- Integration as TIntegration,
- useIntegrationsQuery,
-} from 'data/integrations/integrations-query'
+import { Integration as TIntegration } from 'data/integrations/integrations-query'
import { useIntegrationsVercelInstalledConnectionDeleteMutation } from 'data/integrations/integrations-vercel-installed-connection-delete-mutation'
import { useStore } from 'hooks'
import { pluralize } from 'lib/helpers'
import { EMPTY_ARR } from 'lib/void'
-import { useMemo } from 'react'
import { useGithubConnectionConfigPanelSnapshot } from 'state/github-connection-config-panel'
import { Button, Dropdown, IconChevronDown, IconRefreshCcw, IconTrash } from 'ui'
@@ -42,7 +36,7 @@ const Integration = ({
detail,
integrations = EMPTY_ARR,
}: IntegrationProps) => {
- const githubConnectionConfigPanelShotshot = useGithubConnectionConfigPanelSnapshot()
+ const snapshot = useGithubConnectionConfigPanelSnapshot()
const { ui } = useStore()
@@ -90,6 +84,7 @@ Repository connections for ${title?.toLowerCase()}
<div className="flex flex-col gap-12">
{integrations.length > 0 &&
integrations.map((integration, i) => {
+ console.log('integration.id', integration?.id)
return (
<div key={i}>
<IntegrationInstallation
@@ -152,7 +147,10 @@ Repository connections for ${title?.toLowerCase()}
<ConnectionHeading integration={integration} />
)}
<EmptyIntegrationConnection
- onClick={() => githubConnectionConfigPanelShotshot.setVisible(true)}
+ onClick={() => {
+ snapshot.setOrganizationIntegrationId(integration.id)
+ snapshot.setOpen(true)
+ }}
>
Add new project connection
</EmptyIntegrationConnection>
diff --git a/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx b/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx
index e535d1f0577..e2932027eba 100644
--- a/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx
+++ b/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx
@@ -72,8 +72,7 @@ You can change the scope of the access for Supabase by configuring here.
`}
integrations={githubIntegrations}
/>
- {/* <SidePanelGitHubRepoSelection /> */}
- {/* <SidePanelVercelProjectLinker /> */}
+ <SidePanelVercelProjectLinker />
</>
)
}
diff --git a/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx b/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx
index be862353f74..58ee9775500 100644
--- a/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx
+++ b/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx
@@ -1,37 +1,48 @@
-import { useParams } from 'common'
-import ProjectLinker from 'components/interfaces/Integrations/ProjectsLinker'
+import ProjectLinker from 'components/interfaces/Integrations/ProjectLinker'
import { Markdown } from 'components/interfaces/Markdown'
import { useIntegrationsQuery } from 'data/integrations/integrations-query'
+import { useVercelProjectConnectionsQuery } from 'data/integrations/integrations-vercel-installed-connections-query'
+import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-projects-query'
+import { useProjectsQuery } from 'data/projects/projects-query'
import { useStore } from 'hooks'
+import { EMPTY_ARR } from 'lib/void'
import { observer } from 'mobx-react-lite'
-import { useMemo, useState } from 'react'
+import { useMemo } from 'react'
import { useGithubConnectionConfigPanelSnapshot } from 'state/github-connection-config-panel'
import { SidePanel } from 'ui'
-import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-projects-query'
-import { useProjectsQuery } from 'data/projects/projects-query'
-import { EMPTY_ARR } from 'lib/void'
-import { Organization } from 'types'
-import { useVercelProjectConnectionsQuery } from 'data/integrations/integrations-vercel-installed-connections-query'
-
const SidePanelVercelProjectLinker = () => {
const { ui } = useStore()
+ const selectedOrg = ui.selectedOrganization
- const { data } = useIntegrationsQuery({ orgId: ui.selectedOrganization?.id })
-
- const vercelIntegrations = data?.filter((integration) => integration.integration.id === 1) // vercel
+ const { data: integrationData } = useIntegrationsQuery({
+ orgId: ui.selectedOrganization?.id,
+ })
+ const vercelIntegrations = integrationData?.filter(
+ (integration) => integration.integration.name === 'Vercel'
+ ) // vercel
- const selectedOrg = ui.selectedOrganization
+ const snapshot = useGithubConnectionConfigPanelSnapshot()
- const [organizationIntegrationId, setOrganizationIntegrationId] = useState<string>(
- '880cb835-54b4-415b-8178-6f7920fdc40d'
+ /**
+ * Find the right integration
+ *
+ * we use the snapshot.organizationIntegrationId which should be set whenever this sidepanel is opened
+ */
+ const selectedIntegration = vercelIntegrations?.find(
+ (x) => x.id === snapshot.organizationIntegrationId
)
- const githubConnectionConfigPanelSnapshot = useGithubConnectionConfigPanelSnapshot()
+ const organizationIntegrationId = snapshot.organizationIntegrationId
+ const open = snapshot.open
+ /**
+ * Supabase projects available
+ */
const { data: supabaseProjectsData } = useProjectsQuery({
enabled: organizationIntegrationId !== null,
})
+
const supabaseProjects = useMemo(
() =>
supabaseProjectsData
@@ -47,30 +58,26 @@ const SidePanelVercelProjectLinker = () => {
{ enabled: organizationIntegrationId !== null }
)
- const vercelProjectConnections = useMemo(
- () => vercelProjectConnectionsData ?? EMPTY_ARR,
- [vercelProjectConnectionsData]
- )
-
const { data: vercelProjectsData } = useVercelProjectsQuery(
{
orgId: selectedOrg?.id,
orgSlug: selectedOrg?.slug,
+ organization_integration_id: organizationIntegrationId,
},
{ enabled: organizationIntegrationId !== null }
)
- console.log('vercelProjectsData', vercelProjectsData)
const vercelProjects = useMemo(() => vercelProjectsData ?? EMPTY_ARR, [vercelProjectsData])
return (
<SidePanel
header={'Add GitHub repository'}
size="large"
- visible={githubConnectionConfigPanelSnapshot.visible}
- onCancel={() => githubConnectionConfigPanelSnapshot.setVisible(false)}
+ visible={open}
+ hideFooter
+ onCancel={() => snapshot.setOpen(false)}
>
- <div className="my-10 flex flex-col gap-6">
+ <div className="py-10 flex flex-col gap-6 bg-body h-full">
<SidePanel.Content>
<Markdown
content={`
@@ -82,15 +89,13 @@ Check the details below before proceeding
</SidePanel.Content>
<SidePanel.Content className="flex flex-col gap-2">
<ProjectLinker
- organizationIntegrationId={'880cb835-54b4-415b-8178-6f7920fdc40d'}
+ organizationIntegrationId={selectedIntegration?.id}
foreignProjects={vercelProjects}
supabaseProjects={supabaseProjects}
onCreateConnections={() => {
- // if (next) {
- // window.location.href = next
- // }
+ snapshot.setOpen(false)
}}
- installedConnections={vercelProjectConnections}
+ installedConnections={selectedIntegration?.connections}
/>
</SidePanel.Content>
<SidePanel.Content>
diff --git a/studio/data/integrations/integration-connections-create-mutation.ts b/studio/data/integrations/integration-connections-create-mutation.ts
index 170a18a2404..aa73ad05b9a 100644
--- a/studio/data/integrations/integration-connections-create-mutation.ts
+++ b/studio/data/integrations/integration-connections-create-mutation.ts
@@ -1,6 +1,7 @@
-import { useMutation, UseMutationOptions } from '@tanstack/react-query'
+import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
import { post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
+import { integrationKeys } from './keys'
export type IntegrationConnectionsCreateVariables = {
organizationIntegrationId: string
@@ -10,6 +11,7 @@ export type IntegrationConnectionsCreateVariables = {
integrationId: number
metadata: any
}
+ orgId: number | undefined
}
export async function createIntegrationConnections({
@@ -40,12 +42,14 @@ export const useIntegrationConnectionsCreateMutation = ({
>,
'mutationFn'
> = {}) => {
+ const queryClient = useQueryClient()
return useMutation<
IntegrationConnectionsCreateData,
unknown,
IntegrationConnectionsCreateVariables
>((vars) => createIntegrationConnections(vars), {
async onSuccess(data, variables, context) {
+ await Promise.all([queryClient.invalidateQueries(integrationKeys.list(variables.orgId))])
await onSuccess?.(data, variables, context)
},
...options,
diff --git a/studio/data/integrations/integrations-query.ts b/studio/data/integrations/integrations-query.ts
index 1865da940d3..4467bbf9b9f 100644
--- a/studio/data/integrations/integrations-query.ts
+++ b/studio/data/integrations/integrations-query.ts
@@ -3,7 +3,123 @@ import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { integrationKeys } from './keys'
-type metadata = {
+export type VercelFramework =
+ | (
+ | 'blitzjs'
+ | 'nextjs'
+ | 'gatsby'
+ | 'remix'
+ | 'astro'
+ | 'hexo'
+ | 'eleventy'
+ | 'docusaurus-2'
+ | 'docusaurus'
+ | 'preact'
+ | 'solidstart'
+ | 'dojo'
+ | 'ember'
+ | 'vue'
+ | 'scully'
+ | 'ionic-angular'
+ | 'angular'
+ | 'polymer'
+ | 'svelte'
+ | 'sveltekit'
+ | 'sveltekit-1'
+ | 'ionic-react'
+ | 'create-react-app'
+ | 'gridsome'
+ | 'umijs'
+ | 'sapper'
+ | 'saber'
+ | 'stencil'
+ | 'nuxtjs'
+ | 'redwoodjs'
+ | 'hugo'
+ | 'jekyll'
+ | 'brunch'
+ | 'middleman'
+ | 'zola'
+ | 'hydrogen'
+ | 'vite'
+ | 'vitepress'
+ | 'vuepress'
+ | 'parcel'
+ | 'sanity'
+ | 'storybook'
+ )
+ | null
+
+export type VercelGitLink =
+ | {
+ /**
+ * GitHub link
+ */
+ org?: string
+ repo?: string
+ repoId?: number
+ type?: 'github'
+ createdAt?: number
+ deployHooks: {
+ createdAt?: number
+ id: string
+ name: string
+ ref: string
+ url: string
+ }[]
+ gitCredentialId?: string
+ updatedAt?: number
+ sourceless?: boolean
+ productionBranch?: string
+ }
+ | {
+ /**
+ * GitLab link
+ */
+ projectId?: string
+ projectName?: string
+ projectNameWithNamespace?: string
+ projectNamespace?: string
+ projectUrl?: string
+ type?: 'gitlab'
+ createdAt?: number
+ deployHooks: {
+ createdAt?: number
+ id: string
+ name: string
+ ref: string
+ url: string
+ }[]
+ gitCredentialId?: string
+ updatedAt?: number
+ sourceless?: boolean
+ productionBranch?: string
+ }
+ | {
+ /**
+ * Bitbucket link
+ */
+ name?: string
+ slug?: string
+ owner?: string
+ type?: 'bitbucket'
+ uuid?: string
+ workspaceUuid?: string
+ createdAt?: number
+ deployHooks: {
+ createdAt?: number
+ id: string
+ name: string
+ ref: string
+ url: string
+ }[]
+ gitCredentialId?: string
+ updatedAt?: number
+ sourceless?: boolean
+ productionBranch?: string
+ }
+
+type Imetadata = {
metadata: {
id: string
supabaseConfig: {
@@ -11,121 +127,9 @@ type metadata = {
write: boolean
}
}
- link?:
- | {
- /**
- * GitHub link
- */
- org?: string
- repo?: string
- repoId?: number
- type?: 'github'
- createdAt?: number
- deployHooks: {
- createdAt?: number
- id: string
- name: string
- ref: string
- url: string
- }[]
- gitCredentialId?: string
- updatedAt?: number
- sourceless?: boolean
- productionBranch?: string
- }
- | {
- /**
- * GitLab link
- */
- projectId?: string
- projectName?: string
- projectNameWithNamespace?: string
- projectNamespace?: string
- projectUrl?: string
- type?: 'gitlab'
- createdAt?: number
- deployHooks: {
- createdAt?: number
- id: string
- name: string
- ref: string
- url: string
- }[]
- gitCredentialId?: string
- updatedAt?: number
- sourceless?: boolean
- productionBranch?: string
- }
- | {
- /**
- * Bitbucket link
- */
- name?: string
- slug?: string
- owner?: string
- type?: 'bitbucket'
- uuid?: string
- workspaceUuid?: string
- createdAt?: number
- deployHooks: {
- createdAt?: number
- id: string
- name: string
- ref: string
- url: string
- }[]
- gitCredentialId?: string
- updatedAt?: number
- sourceless?: boolean
- productionBranch?: string
- }
+ link?: VercelGitLink
name: string
- framework:
- | (
- | 'blitzjs'
- | 'nextjs'
- | 'gatsby'
- | 'remix'
- | 'astro'
- | 'hexo'
- | 'eleventy'
- | 'docusaurus-2'
- | 'docusaurus'
- | 'preact'
- | 'solidstart'
- | 'dojo'
- | 'ember'
- | 'vue'
- | 'scully'
- | 'ionic-angular'
- | 'angular'
- | 'polymer'
- | 'svelte'
- | 'sveltekit'
- | 'sveltekit-1'
- | 'ionic-react'
- | 'create-react-app'
- | 'gridsome'
- | 'umijs'
- | 'sapper'
- | 'saber'
- | 'stencil'
- | 'nuxtjs'
- | 'redwoodjs'
- | 'hugo'
- | 'jekyll'
- | 'brunch'
- | 'middleman'
- | 'zola'
- | 'hydrogen'
- | 'vite'
- | 'vitepress'
- | 'vuepress'
- | 'parcel'
- | 'sanity'
- | 'storybook'
- )
- | null
+ framework: VercelFramework
}
}
export type IntegrationProjectConnection = {
@@ -134,8 +138,9 @@ export type IntegrationProjectConnection = {
updated_at: string
added_by: addedBy
supabase_project_id: string
+ foreign_project_id: string
organization_integration_id: string
- metadata: metadata
+ metadata: Imetadata
}
export type IntegrationsVariables = {
@@ -146,7 +151,7 @@ export type IntegrationProjectConnectionPayload = {
foreignProjectId: string
supabaseProjectId: string
integrationId: string
- metadata: metadata
+ metadata: Imetadata
}
type userDetails = {
@@ -166,7 +171,7 @@ export type Integration = {
added_by: addedBy
created_at: string
updated_at: string
- connections: IntegrationProjectConnection[]
+ connections: IntegrationProjectConnection[] | []
metadata?: {
vercelTeam?: string
gitHubConnectionOwner?: string
diff --git a/studio/data/integrations/integrations-vercel-installed-connection-delete-mutation.ts b/studio/data/integrations/integrations-vercel-installed-connection-delete-mutation.ts
index fa6d74522a8..dbcac04ee61 100644
--- a/studio/data/integrations/integrations-vercel-installed-connection-delete-mutation.ts
+++ b/studio/data/integrations/integrations-vercel-installed-connection-delete-mutation.ts
@@ -41,7 +41,6 @@ export const useIntegrationsVercelInstalledConnectionDeleteMutation = ({
async onSuccess(data, variables, context) {
console.log('variables in mutate delete onSuccess', variables)
await Promise.all([queryClient.invalidateQueries(integrationKeys.list(variables.orgId))])
-
await onSuccess?.(data, variables, context)
},
...options,
diff --git a/studio/data/integrations/integrations-vercel-projects-query.ts b/studio/data/integrations/integrations-vercel-projects-query.ts
index 2f3307b373b..1e63ee1f6a3 100644
--- a/studio/data/integrations/integrations-vercel-projects-query.ts
+++ b/studio/data/integrations/integrations-vercel-projects-query.ts
@@ -3,6 +3,7 @@ import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { useCallback } from 'react'
import { integrationKeys } from './keys'
+import { VercelFramework } from './integrations-query'
export type VercelProjectsVariables = {
orgId?: number
@@ -13,6 +14,7 @@ export type VercelProjectsVariables = {
export type VercelProjectsResponse = {
id: string
name: string
+ framework: VercelFramework
metadata: {
id: string
name: string
diff --git a/studio/state/github-connection-config-panel.ts b/studio/state/github-connection-config-panel.ts
index 021d5c54846..915c6ec5fe8 100644
--- a/studio/state/github-connection-config-panel.ts
+++ b/studio/state/github-connection-config-panel.ts
@@ -1,9 +1,13 @@
import { proxy, snapshot, useSnapshot } from 'valtio'
export const githubConnectionConfigPanelState = proxy({
- visible: false as boolean,
- setVisible: (visible: boolean) => {
- githubConnectionConfigPanelState.visible = visible
+ open: false as boolean,
+ setOpen: (open: boolean) => {
+ githubConnectionConfigPanelState.open = open
+ },
+ organizationIntegrationId: '' as string,
+ setOrganizationIntegrationId: (organizationInterationId: string) => {
+ githubConnectionConfigPanelState.organizationIntegrationId = organizationInterationId
},
})