The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Chore/custom content connect UI frameworks (#38090)
Joshen Limf9027a29cdab
diff --git a/apps/studio/components/interfaces/Connect/Connect.constants.ts b/apps/studio/components/interfaces/Connect/Connect.constants.tsindex 926d2151ce2..80f82d9560a 100644--- a/apps/studio/components/interfaces/Connect/Connect.constants.ts+++ b/apps/studio/components/interfaces/Connect/Connect.constants.ts@@ -64,6 +64,10 @@ export type ConnectionType = {label: stringguideLink?: stringchildren: ConnectionType[]+ files?: {+ name: string+ content: string+ }[]}export const FRAMEWORKS: ConnectionType[] = [diff --git a/apps/studio/components/interfaces/Connect/Connect.tsx b/apps/studio/components/interfaces/Connect/Connect.tsxindex 6d3065c670a..cbbcd64a943 100644--- a/apps/studio/components/interfaces/Connect/Connect.tsx+++ b/apps/studio/components/interfaces/Connect/Connect.tsx@@ -9,6 +9,7 @@ import { ButtonTooltip } from 'components/ui/ButtonTooltip'import Panel from 'components/ui/Panel'import { getKeys, useAPIKeysQuery } from 'data/api-keys/api-keys-query'import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'+import { useCustomContent } from 'hooks/custom-content/useCustomContent'import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { PROJECT_STATUS } from 'lib/constants'@@ -30,20 +31,31 @@ import {} from 'ui'import { CONNECTION_TYPES, ConnectionType, FRAMEWORKS, MOBILES, ORMS } from './Connect.constants'import { getContentFilePath } from './Connect.utils'-import ConnectDropdown from './ConnectDropdown'-import ConnectTabContent from './ConnectTabContent'+import { ConnectDropdown } from './ConnectDropdown'+import { ConnectTabContent } from './ConnectTabContent'+import { ConnectTabContentCustom } from './ConnectTabContentCustom'export const Connect = () => {const { ref: projectRef } = useParams()const { data: selectedProject } = useSelectedProjectQuery()const isActiveHealthy = selectedProject?.status === PROJECT_STATUS.ACTIVE_HEALTHY+ const { connectFrameworks } = useCustomContent(['connect:frameworks'])+ const connectionTypes = !connectFrameworks+ ? CONNECTION_TYPES+ : [+ { key: 'direct', label: 'Connection String', obj: [] },+ connectFrameworks,+ { key: 'orms', label: 'ORMs', obj: ORMS },+ ]+ const frameworks = !connectFrameworks ? FRAMEWORKS : connectFrameworks.obj+const [showConnect, setShowConnect] = useQueryState('showConnect',parseAsBoolean.withDefault(false))- const [connectionObject, setConnectionObject] = useState<ConnectionType[]>(FRAMEWORKS)+ const [connectionObject, setConnectionObject] = useState<ConnectionType[]>(frameworks)const [selectedParent, setSelectedParent] = useState(connectionObject[0].key) // aka nextjsconst [selectedChild, setSelectedChild] = useState(connectionObject.find((item) => item.key === selectedParent)?.children[0]?.key ?? ''@@ -54,6 +66,8 @@ export const Connect = () => {?.children.find((child) => child.key === selectedChild)?.children[0]?.key || '')+ const isFrameworkSelected = frameworks.some((x) => x.key === selectedParent)+const { data: settings } = useProjectSettingsV2Query({ projectRef }, { enabled: showConnect })const { can: canReadAPIKeys } = useAsyncCheckProjectPermissions(PermissionAction.READ,@@ -109,8 +123,8 @@ export const Connect = () => {function handleConnectionType(type: string) {if (type === 'frameworks') {- setConnectionObject(FRAMEWORKS)- handleConnectionTypeChange(FRAMEWORKS)+ setConnectionObject(frameworks)+ handleConnectionTypeChange(frameworks)}if (type === 'mobiles') {@@ -207,14 +221,14 @@ export const Connect = () => {<Tabs_Shadcn_ defaultValue="direct" onValueChange={(value) => handleConnectionType(value)}><TabsList_Shadcn_ className={cn('flex overflow-x-scroll gap-x-4', DIALOG_PADDING_X)}>- {CONNECTION_TYPES.map((type) => (+ {connectionTypes.map((type) => (<TabsTrigger_Shadcn_ key={type.key} value={type.key} className="px-0">{type.label}</TabsTrigger_Shadcn_>))}</TabsList_Shadcn_>- {CONNECTION_TYPES.map((type) => {+ {connectionTypes.map((type) => {const hasChildOptions =(connectionObject.find((parent) => parent.key === selectedParent)?.children.length ||0) > 0@@ -290,11 +304,18 @@ export const Connect = () => {<p className="text-xs text-foreground-lighter my-3">Add the following files below to your application</p>- <ConnectTabContent- projectKeys={projectKeys}- filePath={filePath}- className="rounded-b-none"- />+ {!!connectFrameworks && isFrameworkSelected ? (+ <ConnectTabContentCustom+ projectKeys={projectKeys}+ framework={frameworks.find((x) => x.key === selectedParent)}+ />+ ) : (+ <ConnectTabContent+ projectKeys={projectKeys}+ filePath={filePath}+ className="rounded-b-none"+ />+ )}<Panel.NoticeclassName="border border-t-0 rounded-lg rounded-t-none"title="New API keys coming 2025"diff --git a/apps/studio/components/interfaces/Connect/ConnectDropdown.tsx b/apps/studio/components/interfaces/Connect/ConnectDropdown.tsxindex 3a17f63e659..bb965f2dae5 100644--- a/apps/studio/components/interfaces/Connect/ConnectDropdown.tsx+++ b/apps/studio/components/interfaces/Connect/ConnectDropdown.tsx@@ -14,16 +14,17 @@ import {Popover_Shadcn_,cn,} from 'ui'+import { ConnectionType } from './Connect.constants'import { ConnectionIcon } from './ConnectionIcon'interface ConnectDropdownProps {state: stringupdateState: (state: string) => voidlabel: string- items: any[]+ items: ConnectionType[]}-const ConnectDropdown = ({+export const ConnectDropdown = ({state,updateState,label,@@ -53,11 +54,7 @@ const ConnectDropdown = ({iconRight={<ChevronDown strokeWidth={1.5} />}><div className="flex items-center gap-2">- {selectedItem?.icon ? (- <ConnectionIcon connection={selectedItem.icon} />- ) : (- <Box size={12} />- )}+ {selectedItem?.icon ? <ConnectionIcon icon={selectedItem.icon} /> : <Box size={12} />}{selectedItem?.label}</div></Button>@@ -79,7 +76,7 @@ const ConnectDropdown = ({}}className="flex gap-2 items-center">- {item.icon ? <ConnectionIcon connection={item.icon} /> : <Box size={12} />}+ {item.icon ? <ConnectionIcon icon={item.icon} /> : <Box size={12} />}{item.label}<Checksize={15}@@ -94,5 +91,3 @@ const ConnectDropdown = ({</Popover_Shadcn_>)}--export default ConnectDropdowndiff --git a/apps/studio/components/interfaces/Connect/ConnectTabContent.tsx b/apps/studio/components/interfaces/Connect/ConnectTabContent.tsxindex 890ceb58df6..3667d93dd48 100644--- a/apps/studio/components/interfaces/Connect/ConnectTabContent.tsx+++ b/apps/studio/components/interfaces/Connect/ConnectTabContent.tsx@@ -27,7 +27,7 @@ interface ConnectContentTabProps extends HTMLAttributes<HTMLDivElement> {}}-const ConnectTabContent = forwardRef<HTMLDivElement, ConnectContentTabProps>(+export const ConnectTabContent = forwardRef<HTMLDivElement, ConnectContentTabProps>(({ projectKeys, filePath, ...props }, ref) => {const { ref: projectRef } = useParams()const { data: selectedOrg } = useSelectedOrganizationQuery()@@ -102,5 +102,3 @@ const ConnectTabContent = forwardRef<HTMLDivElement, ConnectContentTabProps>()ConnectTabContent.displayName = 'ConnectTabContent'--export default ConnectTabContentdiff --git a/apps/studio/components/interfaces/Connect/ConnectTabContentCustom.tsx b/apps/studio/components/interfaces/Connect/ConnectTabContentCustom.tsxnew file mode 100644index 00000000000..c56c8e194d0--- /dev/null+++ b/apps/studio/components/interfaces/Connect/ConnectTabContentCustom.tsx@@ -0,0 +1,56 @@+import { useEffect, useState } from 'react'++import { cn, SimpleCodeBlock } from 'ui'+import { ConnectionType } from './Connect.constants'+import { projectKeys } from './Connect.types'+import {+ ConnectTabContent,+ ConnectTabs,+ ConnectTabTrigger,+ ConnectTabTriggers,+} from './ConnectTabs'++interface ConnectTabContentCustomProps {+ projectKeys: projectKeys+ framework?: ConnectionType+}++export const ConnectTabContentCustom = ({+ projectKeys,+ framework,+}: ConnectTabContentCustomProps) => {+ const { files = [] } = framework ?? {}++ const [selectedTab, setSelectedTab] = useState<string>()++ useEffect(() => {+ if (framework?.files) setSelectedTab(framework.files[0].name)+ }, [framework])++ return (+ <div className={cn('border rounded-lg rounded-b-none')}>+ <ConnectTabs value={selectedTab} onValueChange={setSelectedTab}>+ <ConnectTabTriggers>+ {files.map((x) => (+ <ConnectTabTrigger key={`${x.name}-tab`} value={x.name} />+ ))}+ </ConnectTabTriggers>++ {files.map((x) => {+ const format = x.name.split('.')[1] ?? 'bash'+ const content = x.content+ .replaceAll('{{apiUrl}}', projectKeys.apiUrl ?? '')+ .replaceAll('{{anonKey}}', projectKeys.anonKey ?? '')+ .replaceAll('{{publishableKey}}', projectKeys.publishableKey ?? '')+ return (+ <ConnectTabContent key={`${x.name}-content`} value={x.name}>+ <SimpleCodeBlock className={format} parentClassName="min-h-72">+ {content}+ </SimpleCodeBlock>+ </ConnectTabContent>+ )+ })}+ </ConnectTabs>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/Connect/ConnectTabs.tsx b/apps/studio/components/interfaces/Connect/ConnectTabs.tsxindex ec7b1b5a61f..1443c7abfbe 100644--- a/apps/studio/components/interfaces/Connect/ConnectTabs.tsx+++ b/apps/studio/components/interfaces/Connect/ConnectTabs.tsx@@ -12,20 +12,26 @@ interface ConnectTabTriggersProps {interface ConnectFileTabProps {children: ReactNode[]+ value?: string+ onValueChange?: (value: string) => void}interface ConnectTabContentProps {children: ReactNodevalue: string}-const ConnectTabs = ({ children }: ConnectFileTabProps) => {+const ConnectTabs = ({ children, value, onValueChange }: ConnectFileTabProps) => {const firstChild = children[0]const defaultValue = isValidElement(firstChild)? (firstChild.props as any)?.children[0]?.props?.value || '': null- return <Tabs_Shadcn_ defaultValue={defaultValue}>{children}</Tabs_Shadcn_>+ return (+ <Tabs_Shadcn_ defaultValue={defaultValue} value={value} onValueChange={onValueChange}>+ {children}+ </Tabs_Shadcn_>+ )}const ConnectTabTrigger = ({ value }: ConnectTabTriggerProps) => {diff --git a/apps/studio/components/interfaces/Connect/ConnectionIcon.tsx b/apps/studio/components/interfaces/Connect/ConnectionIcon.tsxindex fd2452d2961..27e93521dc8 100644--- a/apps/studio/components/interfaces/Connect/ConnectionIcon.tsx+++ b/apps/studio/components/interfaces/Connect/ConnectionIcon.tsx@@ -4,26 +4,29 @@ import Image from 'next/image'import { BASE_PATH } from 'lib/constants'interface ConnectionIconProps {- connection: any+ icon: string}-export const ConnectionIcon = ({ connection }: ConnectionIconProps) => {+export const ConnectionIcon = ({ icon }: ConnectionIconProps) => {const { resolvedTheme } = useTheme()- const imageFolder = ['ionic-angular'].includes(connection) ? 'icons/frameworks' : 'libraries'+ const imageFolder = ['ionic-angular'].includes(icon) ? 'icons/frameworks' : 'libraries'const imageExtension = imageFolder === 'icons/frameworks' ? '' : '-icon'-- return (- <Image- className="transition-all group-hover:scale-110"- src={`${BASE_PATH}/img/${imageFolder}/${connection.toLowerCase()}${- ['expo', 'nextjs', 'prisma', 'drizzle', 'astro', 'remix'].includes(connection.toLowerCase())+ const iconImgSrc = icon.startsWith('http')+ ? icon+ : `${BASE_PATH}/img/${imageFolder}/${icon.toLowerCase()}${+ ['expo', 'nextjs', 'prisma', 'drizzle', 'astro', 'remix'].includes(icon.toLowerCase())? resolvedTheme?.includes('dark')? '-dark': '': ''- }${imageExtension}.svg`}- alt={`${connection} logo`}+ }${imageExtension}.svg`++ return (+ <Image+ className="transition-all group-hover:scale-110"+ src={iconImgSrc}+ alt={`${icon} logo`}width={14}height={14}/>diff --git a/apps/studio/components/interfaces/Connect/content/nextjs/app/supabasejs/content.tsx b/apps/studio/components/interfaces/Connect/content/nextjs/app/supabasejs/content.tsxindex 8108b197f09..8c56900d9e4 100644--- a/apps/studio/components/interfaces/Connect/content/nextjs/app/supabasejs/content.tsx+++ b/apps/studio/components/interfaces/Connect/content/nextjs/app/supabasejs/content.tsx@@ -1,10 +1,10 @@import type { ContentFileProps } from 'components/interfaces/Connect/Connect.types'import {+ ConnectTabContent,ConnectTabs,ConnectTabTrigger,ConnectTabTriggers,- ConnectTabContent,} from 'components/interfaces/Connect/ConnectTabs'import { SimpleCodeBlock } from 'ui'@@ -154,4 +154,6 @@ export const createClient = (request: NextRequest) => {)}+// [Joshen] Used as a dynamic import+// eslint-disable-next-line no-restricted-exportsexport default ContentFilediff --git a/apps/studio/hooks/custom-content/CustomContent.types.ts b/apps/studio/hooks/custom-content/CustomContent.types.tsindex 94634447b3c..66816dffa96 100644--- a/apps/studio/hooks/custom-content/CustomContent.types.ts+++ b/apps/studio/hooks/custom-content/CustomContent.types.ts@@ -1,3 +1,5 @@+import { ConnectionType } from 'components/interfaces/Connect/Connect.constants'+export type CustomContentTypes = {organizationLegalDocuments: {id: string@@ -5,6 +7,7 @@ export type CustomContentTypes = {description: stringaction: { text: string; url: string }}[]+projectHomepageExampleProjects: {title: stringdescription: string@@ -13,4 +16,18 @@ export type CustomContentTypes = {}[]logsDefaultQuery: string++ /**+ * When declaring files for each framework, there are 3 properties that can be dynamically rendered into the file content using handlebar notation:+ * - {{apiUrl}}: The API URL of the project+ * - {{anonKey}}: The anonymous key of the project (if still using legacy API keys)+ * - {{publishableKey}}: The publishable API key of the project (if using new API keys)+ *+ * These could be helpful in rendering, for e.g an environment file like `.env`+ */+ connectFrameworks: {+ key: string+ label: string+ obj: ConnectionType[]+ }}diff --git a/apps/studio/hooks/custom-content/custom-content.json b/apps/studio/hooks/custom-content/custom-content.jsonindex db8c9a471b8..1378a1822a9 100644--- a/apps/studio/hooks/custom-content/custom-content.json+++ b/apps/studio/hooks/custom-content/custom-content.json@@ -5,5 +5,7 @@"project_homepage:example_projects": null,- "logs:default_query": null+ "logs:default_query": null,++ "connect:frameworks": null}diff --git a/apps/studio/hooks/custom-content/custom-content.sample.json b/apps/studio/hooks/custom-content/custom-content.sample.jsonindex 4fd040f0cc0..7992201514d 100644--- a/apps/studio/hooks/custom-content/custom-content.sample.json+++ b/apps/studio/hooks/custom-content/custom-content.sample.json@@ -37,5 +37,40 @@}],- "logs:default_query": "This is a sample query"+ "logs:default_query": "This is a sample query",++ "connect:frameworks": {+ "key": "frameworks",+ "label": "Frameworks",+ "obj": [+ {+ "key": "framework-1",+ "label": "Framework 1",+ "icon": "https://supabase.com/dashboard/img/supabase-logo.svg",+ "guideLink": "https://supabase.com/docs",+ "children": [],+ "files": [+ {+ "name": "sample_env",+ "content": "NEXT_PUBLIC_SUPABASE_URL={{apiUrl}}\nNEXT_PUBLIC_SUPABASE_ANON_KEY={{anonKey}}"+ },+ {+ "name": "sample.ts",+ "content": "import { createClient } from \"@supabase/supabase-js\";\n\nconst supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;\nconst supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;\n\nexport const supabase = createClient(supabaseUrl, supabaseKey);"+ }+ ]+ },+ {+ "key": "framework-2",+ "label": "Framework 2",+ "icon": "https://supabase.com/dashboard/img/supabase-logo.svg",+ "guideLink": "https://supabase.com/docs",+ "children": [],+ "files": [+ { "name": "file3.tsx", "content": "Content of File 3" },+ { "name": "file4.tsx", "content": "Content of File 4" }+ ]+ }+ ]+ }}diff --git a/apps/studio/hooks/custom-content/custom-content.schema.json b/apps/studio/hooks/custom-content/custom-content.schema.jsonindex c3e5c5919f8..6d7020a3447 100644--- a/apps/studio/hooks/custom-content/custom-content.schema.json+++ b/apps/studio/hooks/custom-content/custom-content.schema.json@@ -25,6 +25,7 @@}}},+"project_homepage:example_projects": {"type": ["array", "null"],"description": "Renders a provided set of example projects under the project's home page",@@ -42,12 +43,42 @@"logs:default_query": {"type": ["string", "null"],"description": "Renders a default query when landing on the logs explorer"+ },++ "connect:frameworks": {+ "type": ["object", "null"],+ "description": "Replaces the frameworks tab in the Connect modal when a defined set of frameworks",+ "properties": {+ "key": { "type": "string" },+ "label": { "type": "string" },+ "obj": {+ "type": "array",+ "items": {+ "type": "object",+ "properties": {+ "key": { "type": "string" },+ "icon": { "type": "string" },+ "label": { "type": "string" },+ "guideLink": { "type": "string" },+ "children": { "type": "array" },+ "files": {+ "type": "array",+ "properties": {+ "name": { "type": "string" },+ "content": { "type": "string" }+ }+ }+ }+ }+ }+ }}},"required": ["organization:legal_documents","project_homepage:example_projects",- "logs:default_query"+ "logs:default_query",+ "connect:frameworks"],"additionalProperties": false}