The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Show a clear indication of when project fails to connect on the dashboard, in particular for restart server
Joshen Limd4b5c58efd2e
diff --git a/studio/components/layouts/LogsExplorerLayout/LogsExplorerLayout.tsx b/studio/components/layouts/LogsExplorerLayout/LogsExplorerLayout.tsxindex 67572ad3c8b..58571839c1b 100644--- a/studio/components/layouts/LogsExplorerLayout/LogsExplorerLayout.tsx+++ b/studio/components/layouts/LogsExplorerLayout/LogsExplorerLayout.tsx@@ -30,20 +30,10 @@ const PageLayout = ({<BaseLayout><div className="h-full flex flex-col flex-grow py-6"><div- className="- w-full mx-auto-- transition-all- flex flex-col-- px-5- lg:px-16- xl:px-24- 1xl:px-28- 2xl:px-32-- gap-4- "+ className={[+ 'w-full mx-auto flex flex-col transition-all gap-4 px-5',+ 'lg:px-16 xl:px-24 1xl:px-28 2xl:px-32',+ ].join(' ')}><div className="flex items-center gap-3"><div@@ -59,20 +49,10 @@ const PageLayout = ({<LogsNavigation /></div><div- // weird repetitive styling- className="- h-full flex flex-col flex-grow- w-full mx-auto- transition-all-- px-5- lg:px-16- xl:px-24- 1xl:px-28- 2xl:px-32-- gap-4- "+ className={[+ 'h-full w-full flex flex-col flex-grow mx-auto gap-4 transition-all',+ 'px-5 lg:px-16 1xl:px-28 2xl:px-32',+ ].join(' ')}>{children}</div>diff --git a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/studio/components/layouts/ProjectLayout/ProjectLayout.tsxindex 38de7719bf5..9cc1ca2ea1b 100644--- a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx+++ b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx@@ -3,6 +3,10 @@ import { FC, ReactNode } from 'react'import { observer } from 'mobx-react-lite'import { useRouter } from 'next/router'import { useStore } from 'hooks'+import { Button } from '@supabase/ui'++import { get, head } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'import Connecting from 'components/ui/Loading'import NavigationBar from './NavigationBar/NavigationBar'@@ -29,6 +33,8 @@ const ProjectLayout: FC<Props> = ({hideHeader = false,hideIconBar = false,}) => {+ const { ui } = useStore()+return (<><Head>diff --git a/studio/components/layouts/ProjectLayout/RestartingState.tsx b/studio/components/layouts/ProjectLayout/RestartingState.tsxnew file mode 100644index 00000000000..f49731c3b21--- /dev/null+++ b/studio/components/layouts/ProjectLayout/RestartingState.tsx@@ -0,0 +1,81 @@+import Link from 'next/link'+import { FC, useEffect, useRef } from 'react'+import { Badge, IconLoader, IconMonitor, IconServer } from '@supabase/ui'++import { Project } from 'types'+import { API_URL } from 'lib/constants'+import { get, head } from 'lib/common/fetch'+import ShimmerLine from 'components/ui/ShimmerLine'++interface Props {+ project: Project+ autoApiService: any+}++const ProjectRestartingState: FC<Props> = ({ project, autoApiService }) => {+ const checkProjectConnectionIntervalRef = useRef<number>()++ useEffect(() => {+ if (!autoApiService) return++ // Check project connection status every 4 seconds+ checkProjectConnectionIntervalRef.current = window.setInterval(testProjectConnection, 4000)+ return () => {+ clearInterval(checkProjectConnectionIntervalRef.current)+ }+ }, [autoApiService])++ const testProjectConnection = async () => {+ const API_KEY = autoApiService?.internalApiKey+ const swaggerUrl = autoApiService?.restUrl++ const headers: any = { apikey: API_KEY }+ if (API_KEY?.length > 40) headers['Authorization'] = `Bearer ${API_KEY}`++ const { error } = await head(swaggerUrl, [], { headers, credentials: 'omit' })+ if (error === undefined) {+ clearInterval(checkProjectConnectionIntervalRef.current)+ // We force a page refresh to retrigger TestConnection because+ // there's no specific state for "RESTARTING" that TestConnection can listen to yet+ window.location.replace(`/project/${project.ref}`)+ }+ }++ return (+ <div className="max-w-7xl mx-auto w-full my-16 space-y-16">+ <div className="mx-6 space-y-16">+ <div className="flex flex-col space-y-4 lg:space-y-0 lg:flex-row lg:space-x-6 lg:items-center">+ <h1 className="text-3xl">{project.name}</h1>+ <div>+ <Badge color="brand">+ <div className="flex items-center gap-2">+ <IconLoader className="animate-spin" size={12} />+ <span>Connecting to project</span>+ </div>+ </Badge>+ </div>+ </div>+ <div className="rounded bg-scale-300 border border-scale-400 p-8 flex items-center justify-center h-[500px]">+ <div className="w-[420px] space-y-4">+ <div className="max-w-[300px] mx-auto flex items-center justify-center space-x-4 lg:space-x-8">+ <IconMonitor className="text-scale-1100" size={50} strokeWidth={1.5} />+ <ShimmerLine active />+ <IconServer className="text-scale-1100" size={50} strokeWidth={1.5} />+ </div>+ <p className="text-center">Connecting to {project.name}</p>+ <p className="text-center text-scale-1100 text-sm">+ This may take a few minutes, but if your dashboard hasn't connected within 2 minutes,+ you can open a support ticket{' '}+ <span className="text-green-1000">+ <Link href={`/support/new?ref=${project.ref}`}>here</Link>+ </span>+ .+ </p>+ </div>+ </div>+ </div>+ </div>+ )+}++export default ProjectRestartingStatediff --git a/studio/components/layouts/ProjectLayout/TestConnection.tsx b/studio/components/layouts/ProjectLayout/TestConnection.tsxindex 7543fd5388e..85cef20a125 100644--- a/studio/components/layouts/ProjectLayout/TestConnection.tsx+++ b/studio/components/layouts/ProjectLayout/TestConnection.tsx@@ -1,9 +1,12 @@import { useRouter } from 'next/router'import { observer } from 'mobx-react-lite'-import { FC, ReactNode } from 'react'+import { FC, ReactNode, useEffect, useState } from 'react'+import { Project } from 'types'-import { PROJECT_STATUS } from 'lib/constants'+import { get, head } from 'lib/common/fetch'+import { API_URL, PROJECT_STATUS } from 'lib/constants'import BuildingState from './BuildingState'+import RestartingState from './RestartingState'interface Props {project: Project@@ -15,9 +18,24 @@ interface Props {** TODO: how can we test project connection properly?* ex: the status is ACTIVE_HEALTHY but the project instance is down.+ *+ * [Joshen] As of 210422: Current testing connection by pinging postgres+ * Ideally we'd have a more specific monitoring of the project such as during restarts+ * But that will come later: https://supabase.slack.com/archives/C01D6TWFFFW/p1650427619665549+ *+ * Just note that this logic does not differentiate between a "restarting" state and+ * a "something is wrong and can't connect to project" state.+ *+ * [TODO] Next iteration should scrape long polling and just listen to the project's status*/const TestConnection: FC<Props> = ({ project, children }) => {const router = useRouter()++ // [Joshen] I'm gonna default it to true for now so that it doesn't block the UI+ // Figured this could be more of a check in the background+ const [projectProps, setProjectProps] = useState<any>()+ const [isProjectOnline, setIsProjectOnline] = useState(true)+const isBuilding = [PROJECT_STATUS.COMING_UP, PROJECT_STATUS.RESTORING].includes(project?.status)const isProjectActive = project.status === PROJECT_STATUS.ACTIVE_HEALTHY@@ -25,9 +43,34 @@ const TestConnection: FC<Props> = ({ project, children }) => {router.push(`/project/${project.ref}/building`, undefined, { shallow: true })}+ if (!isProjectOnline && router.asPath !== `/project/${project.ref}`) {+ router.push(`/project/${project.ref}`, undefined, { shallow: true })+ }++ useEffect(() => {+ testProjectConnection()+ }, [project.status])++ // Ping Postgrest to check if project's DB and KPS are both online+ const testProjectConnection = async () => {+ const projectProps = await get(`${API_URL}/props/project/${project.ref}/api`)+ setProjectProps(projectProps)++ const API_KEY = projectProps?.autoApiService?.internalApiKey+ const swaggerUrl = projectProps?.autoApiService?.restUrl++ const headers: any = { apikey: API_KEY }+ if (API_KEY?.length > 40) headers['Authorization'] = `Bearer ${API_KEY}`++ const { error } = await head(swaggerUrl, [], { headers, credentials: 'omit' })+ setIsProjectOnline(error === undefined)+ }+return (<>- {isProjectActive ? (+ {!isProjectOnline ? (+ <RestartingState project={project} autoApiService={projectProps?.autoApiService} />+ ) : isProjectActive ? (children) : isBuilding ? (<BuildingState project={project} />diff --git a/studio/pages/project/[ref]/settings/general.tsx b/studio/pages/project/[ref]/settings/general.tsxindex 8875bfac2a6..05701fccc4b 100644--- a/studio/pages/project/[ref]/settings/general.tsx+++ b/studio/pages/project/[ref]/settings/general.tsx@@ -4,7 +4,7 @@ import { observer } from 'mobx-react-lite'import { toJS } from 'mobx'import { projects } from 'stores/jsonSchema'import { AutoField } from 'uniforms-bootstrap4'-import { Alert, Button, Input, Typography, IconRefreshCcw } from '@supabase/ui'+import { Alert, Button, Input, IconRefreshCcw } from '@supabase/ui'import { API_URL } from 'lib/constants'import { pluckJsonSchemaFields, pluckObjectFields } from 'lib/helpers'@@ -42,8 +42,8 @@ const RestartServerButton: FC<any> = ({ projectRef }: any) => {setLoading(true)try {await post(`${API_URL}/projects/${projectRef}/restart`, {})- ui.setNotification({ category: 'info', message: 'Requested server restart' })- setLoading(false)+ ui.setNotification({ category: 'success', message: 'Restarting server' })+ window.location.replace(`/project/${projectRef}`)} catch (error) {ui.setNotification({ error, category: 'error', message: 'Unable to restart server' })setLoading(false)@@ -106,9 +106,9 @@ const GeneralSettings = observer(() => {<section><Paneltitle={- <Typography.Title key="panel-title" level={5} className="mb-0">+ <h5 key="panel-title" className="text-base mb-0">Infrastructure- </Typography.Title>+ </h5>}><Panel.Content>@@ -126,7 +126,7 @@ const GeneralSettings = observer(() => {<Panel.Content className="border-t border-panel-border-interior-light dark:border-panel-border-interior-dark"><div className="w-full flex items-center justify-between"><div>- <Typography.Text className="block">Restart Server</Typography.Text>+ <p>Restart server</p><div style={{ maxWidth: '420px' }}><p className="opacity-50 text-sm">Your project will not be available for a few minutes.@@ -140,22 +140,17 @@ const GeneralSettings = observer(() => {</section><section>- <Panel title={<Typography.Text className="uppercase">Danger Zone</Typography.Text>}>+ <Panel title={<p className="uppercase">Danger Zone</p>}><Panel.Content><Alertvariant="danger"withIcon- // @ts-ignore- title={- <Typography.Text>- Deleting this project will also remove your database.- </Typography.Text>- }+ title="Deleting this project will also remove your database."><div className="flex flex-col">- <Typography.Text className="block mb-4">+ <p className="block mb-4">Make sure you have made a backup if you want to keep your data.- </Typography.Text>+ </p><ProjectDeleteModal project={project} /></div></Alert>