The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update restart button to provide more options of specific services to restart
Joshen Limca1c159d5947
diff --git a/studio/components/interfaces/Settings/General/RestartServerButton.tsx b/studio/components/interfaces/Settings/General/RestartServerButton.tsxindex dcd90ef9ad0..344ad287877 100644--- a/studio/components/interfaces/Settings/General/RestartServerButton.tsx+++ b/studio/components/interfaces/Settings/General/RestartServerButton.tsx@@ -1,7 +1,7 @@import { FC, useState } from 'react'import { useRouter } from 'next/router'import { observer } from 'mobx-react-lite'-import { Button, IconRefreshCcw } from '@supabase/ui'+import { Button, Dropdown, IconChevronDown, IconRefreshCcw } from '@supabase/ui'import { Project } from 'types'import { useStore } from 'hooks'@@ -17,16 +17,20 @@ const RestartServerButton: FC<Props> = observer(({ project }) => {const { ui, app } = useStore()const router = useRouter()const [loading, setLoading] = useState(false)- const [isModalOpen, setIsModalOpen] = useState(false)+ const [serviceToRestart, setServiceToRestart] = useState<'project' | 'database'>()const projectId = project.idconst projectRef = project.refconst projectRegion = project.region- const openModal = () => setIsModalOpen(true)- const closeModal = () => setIsModalOpen(false)+ const requestProjectRestart = async () => {+ setLoading(true)+ const res = await post(`${API_URL}/projects/${projectRef}/restart`, {})+ if (res.error) onRestartFailed(res.error, 'project')+ else onRestartSuccess()+ }- const requestServerRestart = async () => {+ const requestDatabaseRestart = async () => {setLoading(true)const res = await post(`${API_URL}/projects/${projectRef}/restart-services`, {restartRequest: {@@ -34,37 +38,84 @@ const RestartServerButton: FC<Props> = observer(({ project }) => {services: ['postgresql'],},})+ if (res.error) onRestartFailed(res.error, 'database')+ else onRestartSuccess()+ }++ const onRestartFailed = (error: any, type: string) => {+ ui.setNotification({+ error,+ category: 'error',+ message: `Unable to restart ${type}`,+ })+ setLoading(false)+ setServiceToRestart(undefined)+ }- if (res.error) {- ui.setNotification({- error: res.error,- category: 'error',- message: 'Unable to restart server',- })- setLoading(false)- } else {- app.onProjectPostgrestStatusUpdated(projectId, 'OFFLINE')- ui.setNotification({ category: 'success', message: 'Restarting server' })- router.push(`/project/${projectRef}`)- }- closeModal()+ const onRestartSuccess = () => {+ app.onProjectPostgrestStatusUpdated(projectId, 'OFFLINE')+ ui.setNotification({ category: 'success', message: 'Restarting server' })+ router.push(`/project/${projectRef}`)+ setLoading(false)+ setServiceToRestart(undefined)}return (<><ConfirmModaldanger- visible={isModalOpen}+ visible={serviceToRestart !== undefined}title="Restart Server"- description={`Are you sure you want to restart the server? There will be a few minutes of downtime.`}+ // @ts-ignore+ description={+ <>+ Are you sure you want to restart the{' '}+ <span className="text-scale-1200">{serviceToRestart}</span>? There will be a few minutes+ of downtime.+ </>+ }buttonLabel="Restart"buttonLoadingLabel="Restarting"- onSelectCancel={closeModal}- onSelectConfirm={requestServerRestart}+ onSelectCancel={() => setServiceToRestart(undefined)}+ onSelectConfirm={async () => {+ if (serviceToRestart === 'project') {+ await requestProjectRestart()+ } else if (serviceToRestart === 'database') {+ await requestDatabaseRestart()+ }+ }}/>- <Button type="default" icon={<IconRefreshCcw />} onClick={openModal} loading={loading}>+ {/* <Button type="default" icon={<IconRefreshCcw />} onClick={openModal} loading={loading}>Restart server- </Button>+ </Button> */}+ <Dropdown+ align="end"+ side="bottom"+ overlay={[+ <Dropdown.Item+ key="project"+ disabled={loading}+ onClick={() => {+ setServiceToRestart('project')+ }}+ >+ Restart project+ </Dropdown.Item>,+ <Dropdown.Item+ key="database"+ disabled={loading}+ onClick={() => {+ setServiceToRestart('database')+ }}+ >+ Restart database only+ </Dropdown.Item>,+ ]}+ >+ <Button type="default" iconRight={<IconChevronDown />}>+ Restart services+ </Button>+ </Dropdown></>)})diff --git a/studio/pages/project/[ref]/settings/general.tsx b/studio/pages/project/[ref]/settings/general.tsxindex 235cb3e8ccd..dd6235ce416 100644--- a/studio/pages/project/[ref]/settings/general.tsx+++ b/studio/pages/project/[ref]/settings/general.tsx@@ -95,7 +95,7 @@ const GeneralSettings = observer(() => {<Panel.Content className="border-panel-border-interior-light dark:border-panel-border-interior-dark border-t"><div className="flex w-full items-center justify-between"><div>- <p>Restart server</p>+ <p>Restart services</p><div className="max-w-[420px]"><p className="text-scale-1100 text-sm">Your project will not be available for a few minutes.