Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Pull master and resolve conflicts

Joshen Lim2781b93f1964
diff --cc studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsx
index 00000000000,eab6ab727df..f34fc9b1bfe
mode 000000,100644..100644
--- a/studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsx
+++ b/studio/components/interfaces/Settings/General/Infrastructure/Infrastructure.tsx
@@@ -1,0 -1,76 +1,76 @@@
+ import { FC } from 'react'
+ import { Input } from '@supabase/ui'
+ import { observer } from 'mobx-react-lite'
+
+ import { useStore, useFlag } from 'hooks'
+ import { PRICING_TIER_PRODUCT_IDS } from 'lib/constants'
+ import {
+ FormHeader,
+ FormPanel,
+ FormSection,
+ FormSectionLabel,
+ FormSectionContent,
+ } from 'components/ui/Forms'
+ import PauseProjectButton from './PauseProjectButton'
+ import RestartServerButton from './RestartServerButton'
+
+ interface Props {}
+
+ const Infrastructure: FC<Props> = ({}) => {
+ const { ui } = useStore()
+ const isProjectPauseEnabled = useFlag('projectPausing')
+
+ const project = ui.selectedProject
+ const isFreeProject = project?.subscription_tier === PRICING_TIER_PRODUCT_IDS.FREE
+
+ return (
+ <div>
+ <FormHeader title="Infrastructure" description="" />
+ <FormPanel
+ footer={
+ <>
+ <div className="flex w-full items-center justify-between px-8 py-4">
+ <div>
+ <p className="text-sm">Restart server</p>
+ <div className="max-w-[420px]">
+ <p className="text-scale-1100 text-sm">
+ Your project will not be available for a few minutes.
+ </p>
+ </div>
+ </div>
- {project && <RestartServerButton projectId={project.id} projectRef={project.ref} />}
++ {project && <RestartServerButton project={project} />}
+ </div>
+
+ {isProjectPauseEnabled && isFreeProject && (
+ <>
+ <div className="border-t border-scale-400" />
+ <div className="flex w-full items-center justify-between px-8 py-4">
+ <div>
+ <p className="text-sm">Pause project</p>
+ <div className="max-w-[420px]">
+ <p className="text-scale-1100 text-sm">
+ Your project will not be accessible while it is paused.
+ </p>
+ </div>
+ </div>
+ {project && (
+ <PauseProjectButton projectId={project.id} projectRef={project.ref} />
+ )}
+ </div>
+ </>
+ )}
+ </>
+ }
+ >
+ <FormSection header={<FormSectionLabel>Configuration</FormSectionLabel>}>
+ <FormSectionContent loading={project === undefined}>
+ <Input readOnly disabled value={project?.cloud_provider} label="Cloud provider" />
+ <Input readOnly disabled value={project?.region} label="Region" />
+ </FormSectionContent>
+ </FormSection>
+ </FormPanel>
+ </div>
+ )
+ }
+
+ export default observer(Infrastructure)
diff --cc studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx
index 00000000000,39a53889548..8d7478a71d6
mode 000000,100644..100644
--- a/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx
+++ b/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx
@@@ -1,0 -1,99 +1,161 @@@
+ import { FC, useState } from 'react'
+ import { useRouter } from 'next/router'
+ import { observer } from 'mobx-react-lite'
+ import * as Tooltip from '@radix-ui/react-tooltip'
-import { Button, IconRefreshCcw } from '@supabase/ui'
+ import { PermissionAction } from '@supabase/shared-types/out/constants'
++import { Button, Dropdown, IconChevronDown } from '@supabase/ui'
+
++import { Project } from 'types'
+ import { useStore, checkPermissions } from 'hooks'
+ import { post } from 'lib/common/fetch'
+ import { API_URL } from 'lib/constants'
+ import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
+
+ interface Props {
- projectId: number
- projectRef: string
++ project: Project
+ }
+
-const RestartServerButton: FC<Props> = observer(({ projectRef, projectId }) => {
++const RestartServerButton: FC<Props> = ({ 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 openModal = () => setIsModalOpen(true)
- const closeModal = () => setIsModalOpen(false)
++ const projectId = project.id
++ const projectRef = project.ref
++ const projectRegion = project.region
+
+ const canRestartProject = checkPermissions(PermissionAction.INFRA_EXECUTE, 'reboot')
+
- const requestServerRestart = async () => {
++ const requestProjectRestart = async () => {
+ if (!canRestartProject) {
+ return ui.setNotification({
+ category: 'error',
+ message: 'You do not have the required permissions to restart this project',
+ })
+ }
-
+ setLoading(true)
+ const res = await post(`${API_URL}/projects/${projectRef}/restart`, {})
++ if (res.error) onRestartFailed(res.error, 'project')
++ else onRestartSuccess()
++ }
+
- 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 requestDatabaseRestart = async () => {
++ setLoading(true)
++ const res = await post(`${API_URL}/projects/${projectRef}/restart-services`, {
++ restartRequest: {
++ region: projectRegion,
++ 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)
++ }
++
++ const onRestartSuccess = () => {
++ app.onProjectPostgrestStatusUpdated(projectId, 'OFFLINE')
++ ui.setNotification({ category: 'success', message: 'Restarting server' })
++ router.push(`/project/${projectRef}`)
++ setLoading(false)
++ setServiceToRestart(undefined)
+ }
+
+ return (
+ <>
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger>
- <Button
- type="default"
- icon={<IconRefreshCcw />}
- onClick={openModal}
- loading={loading}
- disabled={!canRestartProject}
- >
- Restart server
- </Button>
++ <div className="flex items-center">
++ <Button
++ type="default"
++ className="rounded-r-none px-3"
++ disabled={!canRestartProject}
++ onClick={() => setServiceToRestart('project')}
++ >
++ Restart project
++ </Button>
++ {canRestartProject && (
++ <Dropdown
++ align="end"
++ side="bottom"
++ overlay={[
++ <Dropdown.Item
++ key="database"
++ disabled={loading}
++ onClick={() => {
++ setServiceToRestart('database')
++ }}
++ >
++ <div className="space-y-1">
++ <p className="text-scale-1200 block">Fast database reboot</p>
++ <p className="text-scale-1100 block">
++ Restarts only the database - faster but may not be able to recover from all
++ failure modes
++ </p>
++ </div>
++ </Dropdown.Item>,
++ ]}
++ >
++ <Button
++ type="default"
++ className="rounded-l-none px-[4px] py-[5px]"
++ icon={<IconChevronDown />}
++ disabled={!canRestartProject}
++ />
++ </Dropdown>
++ )}
++ </div>
+ </Tooltip.Trigger>
+ {!canRestartProject && (
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'bg-scale-100 rounded py-1 px-2 leading-none shadow', // background
+ 'border-scale-200 border ', //border
+ ].join(' ')}
+ >
+ <span className="text-scale-1200 text-xs">
+ You need additional permissions to restart this project
+ </span>
+ </div>
+ </Tooltip.Content>
+ )}
+ </Tooltip.Root>
+ <ConfirmModal
+ danger
- visible={isModalOpen}
- title="Restart Server"
- description={`Are you sure you want to restart the server? There will be a few minutes of downtime.`}
++ visible={serviceToRestart !== undefined}
++ title={`Restart ${serviceToRestart}`}
++ // @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()
++ }
++ }}
+ />
+ </>
+ )
-})
++}
+
-export default RestartServerButton
++export default observer(RestartServerButton)
diff --cc studio/pages/project/[ref]/settings/general.tsx
index 17246380a3c,7cced5a8f45..d5b6a739db6
--- a/studio/pages/project/[ref]/settings/general.tsx
+++ b/studio/pages/project/[ref]/settings/general.tsx
@@@ -1,23 -1,9 +1,8 @@@
import { observer } from 'mobx-react-lite'
- import { toJS } from 'mobx'
- import { projects } from 'stores/jsonSchema'
- import { AutoField } from 'uniforms-bootstrap4'
- import { Alert, Input } from '@supabase/ui'
--
- import { useFlag, useStore } from 'hooks'
import { NextPageWithLayout } from 'types'
- import { post } from 'lib/common/fetch'
- import { API_URL, PRICING_TIER_PRODUCT_IDS } from 'lib/constants'
- import { pluckJsonSchemaFields, pluckObjectFields } from 'lib/helpers'
import { SettingsLayout } from 'components/layouts'
- import {
- RestartServerButton,
- PauseProjectButton,
- DeleteProjectButton,
- } from 'components/interfaces/Settings/General'
-
- import Panel from 'components/ui/Panel'
- import SchemaFormPanel from 'components/to-be-cleaned/forms/SchemaFormPanel'
+ import { FormsContainer } from 'components/ui/Forms'
+ import { General, Infrastructure, DeleteProjectPanel } from 'components/interfaces/Settings/General'
const ProjectSettings: NextPageWithLayout = () => {
return (
@@@ -32,117 -16,5 +15,4 @@@
}
ProjectSettings.getLayout = (page) => <SettingsLayout title="General">{page}</SettingsLayout>
--
export default observer(ProjectSettings)
-
- const GeneralSettings = observer(() => {
- const { app, ui } = useStore()
- const isProjectPauseEnabled = useFlag('projectPausing')
-
- const project = ui.selectedProject
- const formModel = toJS(project)
- const BASIC_FIELDS = ['name']
-
- const isFreeProject = project?.subscription_tier === PRICING_TIER_PRODUCT_IDS.FREE
-
- const handleUpdateProject = async (model: any) => {
- const response = await post(`${API_URL}/projects/${project?.ref}/update`, model)
- if (response.error) {
- ui.setNotification({
- category: 'error',
- message: `Update project failed: ${response.error.message}`,
- })
- } else {
- const updatedProject = response
- app.onProjectUpdated(updatedProject)
- ui.setNotification({ category: 'success', message: 'Successfully saved settings' })
- }
- }
-
- return (
- <article className="max-w-4xl p-4">
- <section>
- <SchemaFormPanel
- title="General"
- schema={pluckJsonSchemaFields(projects, BASIC_FIELDS)}
- model={formModel}
- onSubmit={(model: any) => handleUpdateProject(pluckObjectFields(model, BASIC_FIELDS))}
- >
- <AutoField name="name" showInlineError errorMessage="Please enter a project name" />
- </SchemaFormPanel>
- </section>
-
- <section>
- <Panel
- title={
- <h5 key="panel-title" className="mb-0 text-base">
- Infrastructure
- </h5>
- }
- >
- <Panel.Content>
- <Input
- readOnly
- disabled
- value={project?.cloud_provider}
- label="Cloud provider"
- layout="horizontal"
- />
- </Panel.Content>
- <Panel.Content className="border-panel-border-interior-light dark:border-panel-border-interior-dark border-t">
- <Input readOnly disabled value={project?.region} label="Region" layout="horizontal" />
- </Panel.Content>
- <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 project</p>
- <div className="max-w-[420px]">
- <p className="text-scale-1100 text-sm">
- Your project will not be available for a few minutes.
- </p>
- </div>
- </div>
- {project && <RestartServerButton project={project} />}
- </div>
- </Panel.Content>
- {isProjectPauseEnabled && isFreeProject && (
- <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>Pause project</p>
- <div className="max-w-[420px]">
- <p className="text-scale-1100 text-sm">
- Your project will not be accessible while it is paused.
- </p>
- </div>
- </div>
- {project && <PauseProjectButton projectId={project.id} projectRef={project.ref} />}
- </div>
- </Panel.Content>
- )}
- </Panel>
- </section>
-
- {project !== undefined && (
- <section>
- <Panel title={<p className="uppercase">Danger Zone</p>}>
- <Panel.Content>
- <Alert
- variant="danger"
- withIcon
- title="Deleting this project will also remove your database."
- >
- <div className="flex flex-col">
- <p className="mb-4 block">
- Make sure you have made a backup if you want to keep your data.
- </p>
- <DeleteProjectButton project={project} />
- </div>
- </Alert>
- </Panel.Content>
- </Panel>
- </section>
- )}
- </article>
- )
- })