The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update edge functions home page
Joshen Lim747cb3d02e7f
diff --git a/studio/components/interfaces/Functions/EdgeFunctionsList.tsx b/studio/components/interfaces/Functions/EdgeFunctionsList.tsxnew file mode 100644index 00000000000..0ff6d7aa81b--- /dev/null+++ b/studio/components/interfaces/Functions/EdgeFunctionsList.tsx@@ -0,0 +1,123 @@+import dayjs from 'dayjs'+import { FC, useState } from 'react'+import * as Tooltip from '@radix-ui/react-tooltip'++import { useParams, useStore } from 'hooks'+import Table from 'components/to-be-cleaned/Table'+import FunctionsListItem from './FunctionsListItem'+import { Function } from 'components/interfaces/Functions/Functions.types'+import { IconUpload, IconCheck, IconClipboard, IconClock } from 'ui'+import { useRouter } from 'next/router'++interface Props {}++const EdgeFunctionsList: FC<Props> = () => {+ const router = useRouter()+ const { ref } = useParams()+ const { ui, functions: functionsStore } = useStore()+ const functions: Function[] = functionsStore.list() ?? []++ const restUrl = ui.selectedProject?.restUrl+ const restUrlTld = new URL(restUrl as string).hostname.split('.').pop()++ return (+ <div className="space-y-4">+ <div>+ {functions.map((fn) => {+ const [isCopied, setIsCopied] = useState(false)+ const functionUrl = `https://${ref}.functions.supabase.${restUrlTld}/${fn.slug}`++ return (+ <div+ key={fn.id}+ className={[+ 'border border-scale-500 border-t-0 first:rounded-t first:border-t last:rounded-b',+ 'bg-scale-100 dark:bg-scale-300 py-6 px-6 flex items-center justify-between',+ 'hover:border-t hover:-mt-[1px] first:!mt-0 cursor-pointer',+ 'hover:bg-scale-200 dark:hover:bg-scale-500 hover:border-scale-500 dark:hover:border-scale-700',+ ].join(' ')}+ onClick={() => router.push(`/project/${ref}/functions/${fn.id}`)}+ >+ <div className="space-y-1">+ <p className="text-sm">{fn.name}</p>+ <div className="flex items-center space-x-2">+ <p className="text-sm text-scale-1000">{functionUrl}</p>+ <button+ type="button"+ className="text-scale-900 hover:text-scale-1200 transition"+ onClick={(event: any) => {+ function onCopy(value: any) {+ setIsCopied(true)+ navigator.clipboard.writeText(value).then()+ setTimeout(function () {+ setIsCopied(false)+ }, 3000)+ }+ event.stopPropagation()+ onCopy(functionUrl)+ }}+ >+ {isCopied ? (+ <div className="text-brand-900">+ <IconCheck size={14} strokeWidth={3} />+ </div>+ ) : (+ <div className="relative">+ <div className="block">+ <IconClipboard size={14} />+ </div>+ </div>+ )}+ </button>+ </div>+ </div>+ <div className="space-y-1 flex flex-col items-end">+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger>+ <p className="text-sm">Deployment {fn.version}</p>+ </Tooltip.Trigger>+ <Tooltip.Content side="bottom">+ <Tooltip.Arrow className="radix-tooltip-arrow" />+ <div+ className={[+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',+ 'border border-scale-200',+ ].join(' ')}+ >+ <span className="text-xs text-scale-1200">+ Deployment history coming soon+ </span>+ </div>+ </Tooltip.Content>+ </Tooltip.Root>+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger>+ <div className="flex items-center space-x-2">+ <IconUpload size={14} strokeWidth={1.5} className="text-scale-1000" />+ <p className="text-sm text-scale-1000">{dayjs(fn.updated_at).fromNow()}</p>+ </div>+ </Tooltip.Trigger>+ <Tooltip.Content side="bottom">+ <Tooltip.Arrow className="radix-tooltip-arrow" />+ <div+ className={[+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',+ 'border border-scale-200',+ ].join(' ')}+ >+ <span className="text-xs text-scale-1200">+ Last updated on {dayjs(fn.updated_at).format('DD MMM, YYYY HH:mm')}+ </span>+ </div>+ </Tooltip.Content>+ </Tooltip.Root>+ </div>+ </div>+ )+ })}+ </div>+ </div>+ )+}++export default EdgeFunctionsListdiff --git a/studio/components/interfaces/Functions/TerminalInstructions.tsx b/studio/components/interfaces/Functions/TerminalInstructions.tsxindex f8f30b523ab..16a2e2eea21 100644--- a/studio/components/interfaces/Functions/TerminalInstructions.tsx+++ b/studio/components/interfaces/Functions/TerminalInstructions.tsx@@ -10,19 +10,16 @@ import { Commands } from './Functions.types'interface Props {closable?: boolean+ removeBorder?: boolean}-const TerminalInstructions: FC<Props> = ({ closable = false }) => {+const TerminalInstructions: FC<Props> = ({ closable = false, removeBorder = false }) => {const router = useRouter()const { ref: projectRef } = useParams()-const [showInstructions, setShowInstructions] = useState(!closable)-const { data: tokens } = useAccessTokensQuery()+ const { data: settings } = useProjectApiQuery({ projectRef })- const { data: settings } = useProjectApiQuery({- projectRef,- })const apiService = settings?.autoApiServiceconst anonKey = apiService?.service_api_keys.find((x) => x.name === 'anon key')? apiService.defaultApiKey@@ -86,7 +83,9 @@ const TerminalInstructions: FC<Props> = ({ closable = false }) => {return (<div- className="col-span-7 overflow-hidden transition-all border rounded shadow bg-scale-100 dark:bg-scale-300"+ className={`col-span-7 overflow-hidden transition-all rounded bg-scale-100 dark:bg-scale-300 ${+ removeBorder ? '' : 'border shadow'+ }`}style={{ maxHeight: showInstructions ? 500 : 80 }}><div className="px-8 py-6 space-y-6">@@ -107,7 +106,7 @@ const TerminalInstructions: FC<Props> = ({ closable = false }) => {</div>)}</div>- <div className="space-y-4">+ <div><CommandRender commands={commands} /></div></div>diff --git a/studio/components/interfaces/Functions/index.ts b/studio/components/interfaces/Functions/index.tsindex b096ff5e604..e2d3d9dda40 100644--- a/studio/components/interfaces/Functions/index.ts+++ b/studio/components/interfaces/Functions/index.ts@@ -1,5 +1,6 @@+import EdgeFunctionsList from './EdgeFunctionsList'import FunctionsListItem from './FunctionsListItem'import FunctionsEmptyState from './FunctionsEmptyState'import TerminalInstructions from './TerminalInstructions'-export { FunctionsListItem, FunctionsEmptyState, TerminalInstructions }+export { EdgeFunctionsList, FunctionsListItem, FunctionsEmptyState, TerminalInstructions }diff --git a/studio/components/layouts/FunctionsLayout.tsx b/studio/components/layouts/FunctionsLayout.tsxindex 511d401da95..67d65717dea 100644--- a/studio/components/layouts/FunctionsLayout.tsx+++ b/studio/components/layouts/FunctionsLayout.tsx@@ -1,14 +1,15 @@import Link from 'next/link'import { useRouter } from 'next/router'-import { FC, useEffect, ReactNode } from 'react'+import { FC, useEffect, ReactNode, useState } from 'react'import { observer } from 'mobx-react-lite'-import { IconCode } from 'ui'+import { Button, IconExternalLink, IconCode, Modal, IconTerminal } from 'ui'-import { checkPermissions, useStore, withAuth } from 'hooks'+import { checkPermissions, useParams, useStore, withAuth } from 'hooks'import FunctionsNav from '../interfaces/Functions/FunctionsNav'import BaseLayout from 'components/layouts'import NoPermission from 'components/ui/NoPermission'import { PermissionAction } from '@supabase/shared-types/out/constants'+import { TerminalInstructions } from 'components/interfaces/Functions'interface Props {title?: string@@ -16,10 +17,10 @@ interface Props {}const FunctionsLayout: FC<Props> = ({ title, children }) => {- const { functions, ui } = useStore()const router = useRouter()-- const { id, ref } = router.query+ const { id, ref } = useParams()+ const { functions, ui } = useStore()+ const [showTerminalInstructions, setShowTerminalInstructions] = useState(false)useEffect(() => {if (ui.selectedProjectRef) functions.load()@@ -87,7 +88,7 @@ const FunctionsLayout: FC<Props> = ({ title, children }) => {].join(' ')}><div className="item-center flex flex-col justify-between gap-y-4 xl:flex-row">- <div className="flex items-center gap-3">+ <div className="flex items-center gap-3 w-full"><divclassName={['h-6 w-6 rounded border border-brand-600 bg-brand-300',@@ -97,16 +98,37 @@ const FunctionsLayout: FC<Props> = ({ title, children }) => {<IconCode size={14} strokeWidth={3} /></div>- <div className="flex items-center space-x-4">- <Link href={`/project/${ref}/functions`}>- <h1 className="cursor-pointer text-2xl text-scale-1200 transition-colors hover:text-scale-1100">- Edge Functions- </h1>- </Link>- <p className="mt-1 text-scale-1000">Beta</p>+ <div className="flex items-center justify-between w-full">+ <div className="flex items-center space-x-4">+ <Link href={`/project/${ref}/functions`}>+ <h1 className="cursor-pointer text-2xl text-scale-1200 transition-colors hover:text-scale-1100">+ Edge Functions+ </h1>+ </Link>+ <p className="mt-1 text-scale-1000">Beta</p>+ </div>+ <div className="flex items-center space-x-2">+ <Button+ type="default"+ icon={<IconTerminal size={14} strokeWidth={1.5} />}+ onClick={() => setShowTerminalInstructions(true)}+ >+ Terminal Instructions+ </Button>+ <Link href="https://supabase.com/docs/guides/functions">+ <a target="_link">+ <Button+ type="default"+ icon={<IconExternalLink size={14} strokeWidth={1.5} />}+ >+ Documentation+ </Button>+ </a>+ </Link>+ </div></div>- {name && (+ {/* {name && (<><span className="text-scale-800 dark:text-scale-700"><svg@@ -125,7 +147,7 @@ const FunctionsLayout: FC<Props> = ({ title, children }) => {</span><h5 className="text-2xl text-scale-1200">{name}</h5></>- )}+ )} */}</div></div>{item && <FunctionsNav item={item} />}@@ -140,6 +162,24 @@ const FunctionsLayout: FC<Props> = ({ title, children }) => {</div></div>)}++ <Modal+ size="xlarge"+ visible={showTerminalInstructions}+ onCancel={() => setShowTerminalInstructions(false)}+ header={<h3>Deploying an edge function to your project</h3>}+ customFooter={+ <div className="w-full flex items-center justify-end">+ <Button type="primary" size="tiny" onClick={() => setShowTerminalInstructions(false)}>+ Confirm+ </Button>+ </div>+ }+ >+ <div className="py-4">+ <TerminalInstructions removeBorder />+ </div>+ </Modal></BaseLayout>)}diff --git a/studio/pages/_app.tsx b/studio/pages/_app.tsxindex d97675d69ef..f542d30ca75 100644--- a/studio/pages/_app.tsx+++ b/studio/pages/_app.tsx@@ -16,6 +16,7 @@ import dayjs from 'dayjs'import customParseFormat from 'dayjs/plugin/customParseFormat'import timezone from 'dayjs/plugin/timezone'import utc from 'dayjs/plugin/utc'+import relativeTime from 'dayjs/plugin/relativeTime'// @ts-ignoreimport Prism from 'prism-react-renderer/prism'@@ -44,6 +45,7 @@ import useAutoAuthRedirect from 'hooks/misc/useAutoAuthRedirect'dayjs.extend(customParseFormat)dayjs.extend(utc)dayjs.extend(timezone)+dayjs.extend(relativeTime)dart(Prism)diff --git a/studio/pages/project/[ref]/functions/index.tsx b/studio/pages/project/[ref]/functions/index.tsxindex f8778eb09f5..7848cff03fe 100644--- a/studio/pages/project/[ref]/functions/index.tsx+++ b/studio/pages/project/[ref]/functions/index.tsx@@ -1,50 +1,8 @@import { observer } from 'mobx-react-lite'--import { NextPageWithLayout } from 'types'import { useStore } from 'hooks'+import { NextPageWithLayout } from 'types'import FunctionsLayout from 'components/layouts/FunctionsLayout'--import Table from 'components/to-be-cleaned/Table'-import { Function } from 'components/interfaces/Functions/Functions.types'-import {- FunctionsListItem,- FunctionsEmptyState,- TerminalInstructions,-} from 'components/interfaces/Functions'--const FunctionsList = ({ functions }: { functions: Function[] }) => {- return (- <>- <div className="flex flex-col gap-3 py-6">- <div className="flex justify-between items-center">- <span className="text-sm text-scale-900">{`${functions.length} function${- functions.length > 1 ? 's' : ''- } deployed`}</span>- </div>- <div>- <Table- head={- <>- <Table.th>Name</Table.th>- <Table.th>URL</Table.th>- <Table.th className="hidden lg:table-cell">Created</Table.th>- <Table.th className="hidden 2xl:table-cell">Last updated</Table.th>- <Table.th className="hidden 2xl:table-cell">Version</Table.th>- <Table.th className="text-right">Status</Table.th>- </>- }- body={- <>- {functions.length > 0 &&- functions.map((item: any) => <FunctionsListItem key={item.id} function={item} />)}- </>- }- />- </div>- </div>- </>- )-}+import { EdgeFunctionsList, FunctionsEmptyState } from 'components/interfaces/Functions'const PageLayout: NextPageWithLayout = () => {const { functions } = useStore()@@ -52,8 +10,7 @@ const PageLayout: NextPageWithLayout = () => {return hasFunctions ? (<div className="py-6">- <TerminalInstructions closable />- <FunctionsList functions={functions.list()} />+ <EdgeFunctionsList /></div>) : (<FunctionsEmptyState />