Skip to content

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

Use project services restart mutation in NotificationsPopover and leave comments on the other independent requests there

Joshen Lim1d7f51f51501
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
index d8f536d297e..d73abf69f85 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
@@ -21,6 +21,7 @@ import { delete_, post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { Project } from 'types'
import NotificationRow from './NotificationRow'
+import { useProjectRestartServicesMutation } from 'data/projects/project-restart-services-mutation'
interface NotificationsPopoverProps {
alt?: boolean
@@ -40,6 +41,17 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
const [projectToRollbackMigration, setProjectToRollbackMigration] = useState<Project>()
const [targetNotification, setTargetNotification] = useState<Notification>()
+ const { mutate: restartProjectServices } = useProjectRestartServicesMutation({
+ onSuccess: (res, variables) => {
+ setProjectToRestart(undefined)
+ setTargetNotification(undefined)
+
+ setProjectPostgrestStatus(queryClient, variables.ref, 'OFFLINE')
+ ui.setNotification({ category: 'success', message: `Restarting services` })
+ router.push(`/project/${variables.ref}`)
+ },
+ })
+
const newNotifications =
notifications?.filter(
(notification) => notification.notification_status === NotificationStatus.New
@@ -72,41 +84,22 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
.map((action) => action.action_type)
.filter((actionName) => Object.keys(serviceNamesByActionName).indexOf(actionName) !== -1)
.map((actionName) => serviceNamesByActionName[actionName])
- const { error } = await post(`${API_URL}/projects/${ref}/restart-services`, {
- restartRequest: {
- region,
- source_notification_id: id,
- services: services,
- },
- })
- if (error) {
- ui.setNotification({
- category: 'error',
- message: `Failed to restart project: ${error.message}`,
- error,
- })
- } else {
- setProjectPostgrestStatus(queryClient, ref, 'OFFLINE')
- ui.setNotification({ category: 'success', message: `Restarting services` })
- router.push(`/project/${ref}`)
- }
-
- setProjectToRestart(undefined)
- setTargetNotification(undefined)
+ restartProjectServices({ ref, region, services: services as any, source_notification_id: id })
}
const onConfirmProjectApplyMigration = async () => {
if (!projectToApplyMigration) return
+
const data = targetNotification?.data as PostgresqlUpgradeData
const { resource } = data.additional as any
if (!resource) return
+
+ // [Joshen] Leaving this as an exception for RQ due to dynamic URL
const res = await post(`${API_URL}/database/${projectToApplyMigration.ref}/${resource}`, {})
if (!res.error) {
const project = await getProjectDetail({ ref: projectToApplyMigration.ref })
- if (project) {
- meta.setProjectDetails(project)
- }
+ if (project) meta.setProjectDetails(project)
ui.setNotification({
category: 'success',
@@ -124,18 +117,19 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
const onConfirmProjectRollbackMigration = async () => {
if (!projectToRollbackMigration) return
+
const data = targetNotification?.data as PostgresqlUpgradeData
const { resource } = data.additional as any
if (!resource) return
+
+ // [Joshen] Leaving this as an exception for RQ due to dynamic URL
const res = await delete_(
`${API_URL}/database/${projectToRollbackMigration.ref}/${resource}`,
{}
)
if (!res.error) {
const project = await getProjectDetail({ ref: projectToRollbackMigration.ref })
- if (project) {
- meta.setProjectDetails(project)
- }
+ if (project) meta.setProjectDetails(project)
ui.setNotification({
category: 'success',
diff --git a/studio/data/projects/project-restart-services-mutation.ts b/studio/data/projects/project-restart-services-mutation.ts
index c3e0d4f3383..0739ab2e42b 100644
--- a/studio/data/projects/project-restart-services-mutation.ts
+++ b/studio/data/projects/project-restart-services-mutation.ts
@@ -22,12 +22,14 @@ export type ProjectRestartServicesVariables = {
| 'walg'
| 'autoshutdown'
)[]
+ source_notification_id?: string
}
export async function restartProjectServices({
ref,
region,
services = ['postgresql'],
+ source_notification_id,
}: ProjectRestartServicesVariables) {
const { data, error } = await post('/platform/projects/{ref}/restart-services', {
params: { path: { ref } },
@@ -35,6 +37,7 @@ export async function restartProjectServices({
restartRequest: {
region,
services,
+ source_notification_id,
},
},
})