The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
adds integrations query
Alaister Young7e6ac5dc8908
diff --git a/studio/components/interfaces/Organization/IntegrationSettings/Integration.tsx b/studio/components/interfaces/Organization/IntegrationSettings/Integration.tsxindex 0e746edd52e..835d58a42ff 100644--- a/studio/components/interfaces/Organization/IntegrationSettings/Integration.tsx+++ b/studio/components/interfaces/Organization/IntegrationSettings/Integration.tsx@@ -1,38 +1,29 @@+import { Integration as TIntegration } from 'data/integrations/integrations-query'import dayjs from 'dayjs'import { pluralize } from 'lib/helpers'import { EMPTY_ARR } from 'lib/void'+import { useMemo } from 'react'import { Button, IconArrowRight } from 'ui'--export interface OrganizationConnection {- id: string- orgName: string- addedByUser: string-}--export interface ProjectConnection {- id: string- createdAt: string- /** External resource name */- fromProjectName: string- /** Supabase project name */- toProjectName: string-}-export interface IntegrationProps {title: string+ orgName?: stringdescription?: stringnote?: string- organizationConnections?: OrganizationConnection[]- projectConnections?: ProjectConnection[]+ integrations?: TIntegration[]}const Integration = ({title,+ orgName,description,note,- organizationConnections = EMPTY_ARR,- projectConnections = EMPTY_ARR,+ integrations = EMPTY_ARR,}: IntegrationProps) => {+ const projectConnections = useMemo(+ () => integrations.flatMap((integration) => integration.connections),+ [integrations]+ )+return (<><div>@@ -47,18 +38,18 @@ const Integration = ({</div>)}- {organizationConnections.length > 0 && (+ {integrations.length > 0 && (<ul className="flex flex-col gap-2">- {organizationConnections.map((connection) => (+ {integrations.map((connection) => (<likey={connection.id}className="flex justify-between items-center px-6 py-4 rounded-lg border border-scale-500 bg-panel-body-light dark:bg-panel-body-dark"><div className="flex flex-col gap-1">- <span className="text-scale-1100 font-medium">- {title} integration connection | {connection.orgName}+ <span className="text-scale-1200 font-medium">+ {title} integration connection | {orgName}</span>- <span className="text-scale-900 text-sm">Added by {connection.addedByUser}</span>+ <span className="text-scale-900 text-sm">Added by {connection.createdBy}</span></div><div>@@ -86,9 +77,9 @@ const Integration = ({><div className="flex flex-col gap-1"><div className="flex gap-2">- <span>{connection.fromProjectName}</span>+ <span>{connection.from.name}</span><IconArrowRight />- <span>{connection.toProjectName}</span>+ <span>{connection.to.name}</span></div><span className="text-scale-900 text-sm">diff --git a/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx b/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsxindex e4564cf6a7e..154a869bf6c 100644--- a/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx+++ b/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx@@ -1,30 +1,30 @@+import { observer } from 'mobx-react-lite'++import { useParams } from 'common'+import { useIntegrationsQuery } from 'data/integrations/integrations-query'+import { useStore } from 'hooks'import Integration from './Integration'const IntegrationSettings = () => {+ const { ui } = useStore()+ const { slug } = useParams()+ const { data } = useIntegrationsQuery({ orgSlug: slug })++ const org = ui.selectedOrganization++ const vercelIntegrations = data?.filter((integration) => integration.type === 'VERCEL')+return (<div className="grid grid-cols-2 gap-y-8 mt-8"><Integrationtitle="Vercel"+ orgName={org?.name}description="Supabase will keep the right environment variables up to date in each of the projects you assign to a Supabase project. You can also link multiple Vercel Projects to the same Supabase project."note="Your Vercel connection has access to 7 Vercel Projects. You can change the scope of the access for Supabase by configuring here."- organizationConnections={[- {- id: '1',- orgName: "Alaister's Org",- addedByUser: 'Alaister',- },- ]}- projectConnections={[- {- id: '1',- createdAt: '2021-08-12T00:00:00.000Z',- fromProjectName: 'supabase-vercel',- toProjectName: 'alaister',- },- ]}+ integrations={vercelIntegrations}/></div>)}-export default IntegrationSettings+export default observer(IntegrationSettings)diff --git a/studio/data/integrations/integrations-query.ts b/studio/data/integrations/integrations-query.tsnew file mode 100644index 00000000000..a15a6c0d55d--- /dev/null+++ b/studio/data/integrations/integrations-query.ts@@ -0,0 +1,78 @@+import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'+import { get } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import { integrationKeys } from './keys'++export type IntegrationsVariables = {+ orgSlug?: string+}++export type IntegrationProjectConnection = {+ id: string+ createdAt: string+ from: {+ name: string+ }+ to: {+ name: string+ }+}++export type Integration = {+ id: string+ type: 'VERCEL' | 'NETLIFY' | 'GITHUB'+ createdBy: string+ createdAt: string+ connections: IntegrationProjectConnection[]+}++export type IntegrationsResponse = Integration[]++export async function getIntegrations({ orgSlug }: IntegrationsVariables, signal?: AbortSignal) {+ if (!orgSlug) {+ throw new Error('orgSlug is required')+ }++ const response: IntegrationsResponse = [+ {+ id: '1',+ type: 'VERCEL',+ createdBy: 'Alaister',+ createdAt: '2023-06-05T06:56:25.565Z',+ connections: [+ {+ id: '1.1',+ createdAt: '2023-06-05T06:56:25.565Z',+ from: {+ name: 'supabase-vercel',+ },+ to: {+ name: 'alaister',+ },+ },+ ],+ },+ ]++ // const response = await get(`${API_URL}/projects/${orgSlug}/integrations`, {+ // signal,+ // })+ // if (response.error) {+ // throw response.error+ // }++ return response as IntegrationsResponse+}++export type IntegrationsData = Awaited<ReturnType<typeof getIntegrations>>+export type IntegrationsError = unknown++export const useIntegrationsQuery = <TData = IntegrationsData>(+ { orgSlug }: IntegrationsVariables,+ { enabled = true, ...options }: UseQueryOptions<IntegrationsData, IntegrationsError, TData> = {}+) =>+ useQuery<IntegrationsData, IntegrationsError, TData>(+ integrationKeys.list(orgSlug),+ ({ signal }) => getIntegrations({ orgSlug }, signal),+ { enabled: enabled && typeof orgSlug !== 'undefined', ...options }+ )diff --git a/studio/data/integrations/keys.ts b/studio/data/integrations/keys.tsindex 6859ecd3b0c..f317710e2b3 100644--- a/studio/data/integrations/keys.ts+++ b/studio/data/integrations/keys.ts@@ -1,4 +1,5 @@export const integrationKeys = {+ list: (orgSlug: string | undefined) => ['organizations', orgSlug, 'integrations'] as const,vercelProjectList: (orgSlug: string | undefined) =>['organizations', orgSlug, 'vercel-projects'] as const,}