The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: functions store now has project ref set synchronously
Jonathan Summers-Muir9bd4f231041a
diff --git a/studio/components/interfaces/Functions/FunctionLayout.tsx b/studio/components/interfaces/Functions/FunctionLayout.tsxdeleted file mode 100644index 24a3d5d4fd5..00000000000--- a/studio/components/interfaces/Functions/FunctionLayout.tsx+++ /dev/null@@ -1,118 +0,0 @@-import BaseLayout from 'components/layouts'-import { observer } from 'mobx-react-lite'-import { useStore, withAuth } from 'hooks'-import { IconAlertCircle, IconCode, IconSlash, Loading, Tabs } from '@supabase/ui'-import { Tab } from '@headlessui/react'-import FunctionsNav from './FunctionsNav'-import React, { useEffect } from 'react'-import { useRouter } from 'next/router'-import Link from 'next/link'-import WarningBanner from 'components/ui/WarningBanner'-import { WARNING_MESSAGE } from './Functions.constants'--const PageLayout = ({ children }: { children?: React.ReactNode }) => {- const { functions, ui } = useStore()-- const router = useRouter()- const { id, ref } = router.query-- useEffect(() => {- functions.load()- }, [ui.selectedProject])-- if (!functions.isLoaded) {- return (- <BaseLayout>- <Loading active={true}>loading</Loading>- </BaseLayout>- )- }-- const item = functions.byId(id)-- const name = item?.name || ''-- return (- <BaseLayout>- <WarningBanner title={WARNING_MESSAGE.title} description={WARNING_MESSAGE.description} />-- <div className="h-full flex flex-col flex-grow py-10">- <div- className="- w-full mx-auto-- transition-all-- px-5- lg:px-20- xl:px-24- 1xl:px-28- 2xl:px-32-- flex flex-col- gap-8- "- >- <div className="flex items-center gap-3">- <div- className="w-6 h-6 bg-brand-300 border border-brand-600 rounded text-brand-900- flex items-center justify-center- "- >- <IconCode size={14} strokeWidth={3} />- </div>- <Link href={`/project/${ref}/functions`}>- <h1- className="- transition-colors- text-2xl text-scale-1200- cursor-pointer- hover:text-scale-1100"- >- Functions- </h1>- </Link>-- <span className="text-scale-800 dark:text-scale-700">- <svg- viewBox="0 0 24 24"- width="16"- height="16"- stroke="currentColor"- strokeWidth="1"- strokeLinecap="round"- strokeLinejoin="round"- fill="none"- shapeRendering="geometricPrecision"- >- <path d="M16 3.549L7.12 20.600"></path>- </svg>- </span>- <h5 className="text-2xl text-scale-1200">{name}</h5>- </div>- <FunctionsNav item={item} />- </div>- <div- // weird repetative styling- className="- h-full flex flex-col flex-grow-- w-full mx-auto-- transition-all-- px-5- lg:px-20- xl:px-24- 1xl:px-28- 2xl:px-32- "- >- {children}- </div>- </div>- </BaseLayout>- )-}--export default withAuth(observer(PageLayout))diff --git a/studio/components/interfaces/Functions/FunctionsLayout.tsx b/studio/components/interfaces/Functions/FunctionsLayout.tsxindex 6fa68e99e36..a539500390c 100644--- a/studio/components/interfaces/Functions/FunctionsLayout.tsx+++ b/studio/components/interfaces/Functions/FunctionsLayout.tsx@@ -1,23 +1,26 @@import BaseLayout from 'components/layouts'import { observer } from 'mobx-react-lite'import { useStore, withAuth } from 'hooks'-import { IconCode, IconSlash, Loading, Tabs } from '@supabase/ui'+import { IconAlertCircle, IconCode, IconSlash, Loading, Tabs } from '@supabase/ui'import { Tab } from '@headlessui/react'import FunctionsNav from './FunctionsNav'import React, { useEffect } from 'react'import { useRouter } from 'next/router'+import Link from 'next/link'import WarningBanner from 'components/ui/WarningBanner'import { WARNING_MESSAGE } from './Functions.constants'const PageLayout = ({ children, centered }: { children?: React.ReactNode; centered?: boolean }) => {const { functions, ui } = useStore()-const router = useRouter()- const { id } = router.query++ const { id, ref } = router.queryuseEffect(() => {- functions.load()- }, [ui.selectedProject])+ if (ui.selectedProjectRef) {+ functions.load()+ }+ }, [ui.selectedProjectRef])if (!functions.isLoaded) {return (@@ -27,6 +30,9 @@ const PageLayout = ({ children, centered }: { children?: React.ReactNode; center)}+ const item = id ? functions.byId(id) : null+ const name = item?.name || ''+return (<BaseLayout><WarningBanner title={WARNING_MESSAGE.title} description={WARNING_MESSAGE.description} />@@ -48,9 +54,9 @@ const PageLayout = ({ children, centered }: { children?: React.ReactNode; center</div></>) : (- <div- className="- py-10+ <div className="h-full flex flex-col flex-grow py-10">+ <div+ className="w-full mx-autotransition-all@@ -64,19 +70,68 @@ const PageLayout = ({ children, centered }: { children?: React.ReactNode; centerflex flex-colgap-8"- >- <div className="flex items-center gap-3">- <div- className="w-6 h-6 bg-brand-300 border border-brand-600 rounded text-brand-900+ >+ <div className="flex items-center gap-3">+ <div+ className="w-6 h-6 bg-brand-300 border border-brand-600 rounded text-brand-900flex items-center justify-center"- >- <IconCode size={14} strokeWidth={3} />+ >+ <IconCode size={14} strokeWidth={3} />+ </div>+ <Link href={`/project/${ref}/functions`}>+ <h1+ className="+ transition-colors+ text-2xl text-scale-1200+ cursor-pointer+ hover:text-scale-1100"+ >+ Functions+ </h1>+ </Link>++ {name && (+ <>+ <span className="text-scale-800 dark:text-scale-700">+ <svg+ viewBox="0 0 24 24"+ width="16"+ height="16"+ stroke="currentColor"+ strokeWidth="1"+ strokeLinecap="round"+ strokeLinejoin="round"+ fill="none"+ shapeRendering="geometricPrecision"+ >+ <path d="M16 3.549L7.12 20.600"></path>+ </svg>+ </span>+ <h5 className="text-2xl text-scale-1200">{name}</h5>+ </>+ )}</div>- <h1 className="text-2xl text-scale-1200">Functions</h1>+ {item && <FunctionsNav item={item} />}</div>+ <div+ // weird repetative styling+ className="+ h-full flex flex-col flex-grow++ w-full mx-auto++ transition-all- {children}+ px-5+ lg:px-20+ xl:px-24+ 1xl:px-28+ 2xl:px-32+ "+ >+ {children}+ </div></div>)}</BaseLayout>diff --git a/studio/pages/project/[ref]/functions/[id]/details.tsx b/studio/pages/project/[ref]/functions/[id]/details.tsxindex 0d59bbb2e45..ca32036e925 100644--- a/studio/pages/project/[ref]/functions/[id]/details.tsx+++ b/studio/pages/project/[ref]/functions/[id]/details.tsx@@ -1,7 +1,7 @@import { observer } from 'mobx-react-lite'import { useStore, withAuth } from 'hooks'-import FunctionLayout from 'components/interfaces/Functions/FunctionLayout'+import FunctionsLayout from 'components/interfaces/Functions/FunctionsLayout'import CommandRender from 'components/interfaces/Functions/CommandRender'import { useRouter } from 'next/router'import { useEffect, useState } from 'react'@@ -95,7 +95,7 @@ const PageLayout = () => {]return (- <FunctionLayout>+ <FunctionsLayout><div className="grid gap-y-12 lg:grid-cols-2 lg:gap-x-16"><div><div@@ -203,7 +203,7 @@ const PageLayout = () => {</div></div></div>- </FunctionLayout>+ </FunctionsLayout>)}diff --git a/studio/pages/project/[ref]/functions/[id]/index.tsx b/studio/pages/project/[ref]/functions/[id]/index.tsxindex f6101704e26..88090571608 100644--- a/studio/pages/project/[ref]/functions/[id]/index.tsx+++ b/studio/pages/project/[ref]/functions/[id]/index.tsx@@ -14,7 +14,7 @@ import ChartHandler from 'components/to-be-cleaned/Charts/ChartHandler'import { get } from 'lib/common/fetch'import { API_URL, DATE_FORMAT } from 'lib/constants'-import FunctionLayout from 'components/interfaces/Functions/FunctionLayout'+import FunctionsLayout from 'components/interfaces/Functions/FunctionsLayout'const CHART_INTERVALS = [{@@ -91,7 +91,7 @@ const PageLayout = () => {}return (- <FunctionLayout>+ <FunctionsLayout><div className="space-y-6 py-2"><div className="flex flex-row items-center gap-2"><div className="flex items-center">@@ -206,7 +206,7 @@ const PageLayout = () => {)}</div></div>- </FunctionLayout>+ </FunctionsLayout>)}diff --git a/studio/pages/project/[ref]/functions/[id]/invocations.tsx b/studio/pages/project/[ref]/functions/[id]/invocations.tsxindex f79813d07c3..5217ba872bc 100644--- a/studio/pages/project/[ref]/functions/[id]/invocations.tsx+++ b/studio/pages/project/[ref]/functions/[id]/invocations.tsx@@ -5,7 +5,7 @@ import { observer } from 'mobx-react-lite'import { withAuth } from 'hooks'import { LOG_TYPE_LABEL_MAPPING } from 'components/interfaces/Settings/Logs'import LogsPreviewer from 'components/interfaces/Settings/Logs/LogsPreviewer'-import FunctionLayout from 'components/interfaces/Functions/FunctionLayout'+import FunctionsLayout from 'components/interfaces/Functions/FunctionsLayout'/*** Placeholder page for logs previewers until we figure out where to slot them@@ -19,13 +19,13 @@ export const LogPage: NextPage = () => {}`return (- <FunctionLayout title={title}>+ <FunctionsLayout title={title}><LogsPreviewerprojectRef={ref as string}queryType={'fn_edge'}override={{ key: 'function_id', value: id }}/>- </FunctionLayout>+ </FunctionsLayout>)}diff --git a/studio/pages/project/[ref]/functions/[id]/logs-old.tsx b/studio/pages/project/[ref]/functions/[id]/logs-old.tsxindex be74a2b0201..928f3fc59c6 100644--- a/studio/pages/project/[ref]/functions/[id]/logs-old.tsx+++ b/studio/pages/project/[ref]/functions/[id]/logs-old.tsx@@ -18,7 +18,7 @@ import {import { withAuth } from 'hooks'import Table from 'components/to-be-cleaned/Table'-import FunctionLayout from 'components/interfaces/Functions/FunctionLayout'+import FunctionsLayout from 'components/interfaces/Functions/FunctionsLayout'import FunctionLogsItem from 'components/interfaces/Functions/FunctionLogsItem'import { LOGS_DATA } from 'components/interfaces/Functions/Functions.data'@@ -325,9 +325,9 @@ const PageLayout = () => {)return (- <FunctionLayout>+ <FunctionsLayout><FunctionsList />- </FunctionLayout>+ </FunctionsLayout>)}diff --git a/studio/pages/project/[ref]/functions/[id]/logs.tsx b/studio/pages/project/[ref]/functions/[id]/logs.tsxindex 302732a41b4..4ac048890ea 100644--- a/studio/pages/project/[ref]/functions/[id]/logs.tsx+++ b/studio/pages/project/[ref]/functions/[id]/logs.tsx@@ -5,7 +5,7 @@ import { observer } from 'mobx-react-lite'import { withAuth } from 'hooks'import { LOG_TYPE_LABEL_MAPPING } from 'components/interfaces/Settings/Logs'import LogsPreviewer from 'components/interfaces/Settings/Logs/LogsPreviewer'-import FunctionLayout from 'components/interfaces/Functions/FunctionLayout'+import FunctionsLayout from 'components/interfaces/Functions/FunctionsLayout'/*** Placeholder page for logs previewers until we figure out where to slot them@@ -19,13 +19,13 @@ export const LogPage: NextPage = () => {}`return (- <FunctionLayout title={title}>+ <FunctionsLayout title={title}><LogsPreviewerprojectRef={ref as string}queryType={'functions'}override={{ key: 'metadata.function_id', value: id }}/>- </FunctionLayout>+ </FunctionsLayout>)}diff --git a/studio/pages/project/[ref]/functions/[id]/triggers.tsx b/studio/pages/project/[ref]/functions/[id]/triggers.tsxindex 49f235f0302..6a1bb91493c 100644--- a/studio/pages/project/[ref]/functions/[id]/triggers.tsx+++ b/studio/pages/project/[ref]/functions/[id]/triggers.tsx@@ -1,10 +1,10 @@import { observer } from 'mobx-react-lite'import { withAuth } from 'hooks'-import FunctionLayout from 'components/interfaces/Functions/FunctionLayout'+import FunctionsLayout from 'components/interfaces/Functions/FunctionsLayout'const PageLayout = () => {- return <FunctionLayout>Triggers</FunctionLayout>+ return <FunctionsLayout>Triggers</FunctionsLayout>}export default withAuth(observer(PageLayout))diff --git a/studio/pages/project/[ref]/functions/index.tsx b/studio/pages/project/[ref]/functions/index.tsxindex 81d69f91534..2154eb9ded4 100644--- a/studio/pages/project/[ref]/functions/index.tsx+++ b/studio/pages/project/[ref]/functions/index.tsx@@ -147,7 +147,7 @@ const EmptyFunctions = () => {const FunctionsList = ({ functions }: { functions: Function[] }) => {return (<>- <div className="flex flex-col gap-3">+ <div className="flex flex-col gap-3 py-12"><div className="flex justify-between items-center"><span className="text-sm text-scale-900">{`${functions.length} function${functions.length > 1 ? 's' : ''@@ -250,42 +250,14 @@ const FunctionsList = ({ functions }: { functions: Function[] }) => {}const PageLayout = () => {- const router = useRouter()- const { ui, functions } = useStore()-- const project = ui.selectedProject-- useEffect(() => {- if (project && project.status === PROJECT_STATUS.INACTIVE) {- post(`${API_URL}/projects/${ui.selectedProject}/restore`, {})- }- }, [project])-- useEffect(() => {- functions.load()- }, [ui.selectedProject])+ const { functions } = useStore()+ const hasFunctions = functions.list().length > 0- if (functions.isLoading)- return (- <FunctionsLayout>- <Loading active={true}>loading</Loading>- </FunctionsLayout>- )-- if (functions.list().length <= 0) {- // if (true) {- return (- <FunctionsLayout centered={true}>- <EmptyFunctions />- </FunctionsLayout>- )- } else {- return (- <FunctionsLayout>- <FunctionsList functions={functions.list()} />- </FunctionsLayout>- )- }+ return (+ <FunctionsLayout centered={!hasFunctions}>+ {hasFunctions ? <FunctionsList functions={functions.list()} /> : <EmptyFunctions />}+ </FunctionsLayout>+ )}export default withAuth(observer(PageLayout))diff --git a/studio/stores/RootStore.ts b/studio/stores/RootStore.tsindex 3b9386fab4d..6117098a77e 100644--- a/studio/stores/RootStore.ts+++ b/studio/stores/RootStore.ts@@ -52,7 +52,6 @@ export class RootStore implements IRootStore {if (selectedProject) {// @ts-ignorethis.content = new ProjectContentStore(this, { projectRef: selectedProject.ref })- this.functions = new ProjectFunctionsStore(this, { projectRef: selectedProject.ref })this.meta = new MetaStore(this, {projectRef: selectedProject.ref,connectionString: selectedProject.connectionString ?? '',@@ -60,7 +59,6 @@ export class RootStore implements IRootStore {} else {// @ts-ignorethis.content = new ProjectContentStore(this, { projectRef: '' })- this.functions = new ProjectFunctionsStore(this, { projectRef: '' })this.meta = new MetaStore(this, {projectRef: '',connectionString: '',@@ -73,6 +71,7 @@ export class RootStore implements IRootStore {setProjectRef(value?: string) {if (this.ui.selectedProject?.ref === value) returnthis.ui.setProjectRef(value)+ this.functions.setProjectRef(value)}setOrganizationSlug(value?: string) {diff --git a/studio/stores/UiStore.ts b/studio/stores/UiStore.tsindex 55c59c0b381..312e19bc336 100644--- a/studio/stores/UiStore.ts+++ b/studio/stores/UiStore.ts@@ -9,6 +9,7 @@ export interface IUiStore {theme: 'dark' | 'light'themeOption: 'dark' | 'light' | 'system'+ selectedProjectRef?: stringisDarkTheme: booleanselectedProject?: ProjectselectedOrganization?: Organizationdiff --git a/studio/stores/functions/ProjectFunctionsStore.ts b/studio/stores/functions/ProjectFunctionsStore.tsindex 72cb7930998..b8d9e564884 100644--- a/studio/stores/functions/ProjectFunctionsStore.ts+++ b/studio/stores/functions/ProjectFunctionsStore.ts@@ -14,11 +14,15 @@ export interface IProjectFunctionsStore {isLoaded: booleanerror: any+ baseUrl: string+ projectRef: string+load: () => voidlist: (filter?: any) => any[]byId: (id?: any) => anyreports: (filter?: any) => any[]sqlSnippets: (filter?: any) => any[]+ setProjectRef: (ref?: string) => void}export default class ProjectFunctionsStore implements IProjectFunctionsStore {@@ -32,6 +36,7 @@ export default class ProjectFunctionsStore implements IProjectFunctionsStore {}baseUrl: string+ projectRef: string// @ts-ignoredata: UserContentMap = []@@ -40,8 +45,9 @@ export default class ProjectFunctionsStore implements IProjectFunctionsStore {constructor(rootStore: IRootStore, options: { projectRef: string }) {const { projectRef } = options+ this.projectRef = projectRefthis.rootStore = rootStore- this.baseUrl = `${process.env.NEXT_PUBLIC_API_ADMIN_URL}/projects/${projectRef}/functions`+ this.baseUrl = ``makeAutoObservable(this)}@@ -189,4 +195,11 @@ export default class ProjectFunctionsStore implements IProjectFunctionsStore {return { data: false, error }}}++ setProjectRef(ref?: string) {+ if (ref) {+ this.projectRef = ref+ this.baseUrl = `${process.env.NEXT_PUBLIC_API_ADMIN_URL}/projects/${ref}/functions`+ }+ }}