Skip to content

Commit

Permalink
chore: remove finalise migration action
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Aug 16, 2023
1 parent f8bb65e commit 745b0fa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface NotificationActionsProps {
onSelectRestartProject: () => void
onSelectApplyMigration: () => void
onSelectRollbackMigration: () => void
onSelectFinalizeMigration: () => void
}

const NotificationActions = ({
Expand All @@ -23,7 +22,6 @@ const NotificationActions = ({
onSelectRestartProject,
onSelectApplyMigration,
onSelectRollbackMigration,
onSelectFinalizeMigration,
}: NotificationActionsProps) => {
const router = useRouter()

Expand All @@ -48,13 +46,7 @@ const NotificationActions = ({
</Button>
)
case ActionType.MigratePostgresSchema:
if (action.reason === ActionReason.Finalize) {
return (
<Button type="default" onClick={onSelectFinalizeMigration}>
Finalize
</Button>
)
} else if (action.reason === ActionReason.Rollback) {
if (action.reason === ActionReason.Rollback) {
return (
<Button type="default" onClick={onSelectRollbackMigration}>
Rollback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ export interface NotificationRowProps {
onSelectRestartProject: (project: Project, notification: Notification) => void
onSelectApplyMigration: (project: Project, notification: Notification) => void
onSelectRollbackMigration: (project: Project, notification: Notification) => void
onSelectFinalizeMigration: (project: Project, notification: Notification) => void
}

const NotificationRow = ({
notification,
onSelectRestartProject,
onSelectApplyMigration,
onSelectRollbackMigration,
onSelectFinalizeMigration,
}: NotificationRowProps) => {
const { ui } = useStore()
const { data: projects } = useProjectsQuery()
Expand Down Expand Up @@ -95,7 +93,6 @@ const NotificationRow = ({
onSelectRestartProject={() => onSelectRestartProject(project, notification)}
onSelectApplyMigration={() => onSelectApplyMigration(project, notification)}
onSelectRollbackMigration={() => onSelectRollbackMigration(project, notification)}
onSelectFinalizeMigration={() => onSelectFinalizeMigration(project, notification)}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { useQueryClient } from '@tanstack/react-query'
import dayjs from 'dayjs'
import { useRouter } from 'next/router'
import { Fragment, useState } from 'react'
import { Alert, Button, IconArrowRight, IconBell, IconInbox, Popover } from 'ui'
import { Button, IconArrowRight, IconBell, IconInbox, Popover } from 'ui'

import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
import { useNotificationsQuery } from 'data/notifications/notifications-query'
import { useNotificationsUpdateMutation } from 'data/notifications/notifications-update-mutation'
import { getProjectDetail } from 'data/projects/project-detail-query'
import { setProjectPostgrestStatus } from 'data/projects/projects-query'
import { useStore } from 'hooks'
import { delete_, patch, post } from 'lib/common/fetch'
import { delete_, post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { Project } from 'types'
import NotificationRow from './NotificationRow'
Expand All @@ -38,7 +38,6 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
const [projectToRestart, setProjectToRestart] = useState<Project>()
const [projectToApplyMigration, setProjectToApplyMigration] = useState<Project>()
const [projectToRollbackMigration, setProjectToRollbackMigration] = useState<Project>()
const [projectToFinalizeMigration, setProjectToFinalizeMigration] = useState<Project>()
const [targetNotification, setTargetNotification] = useState<Notification>()

const newNotifications =
Expand Down Expand Up @@ -152,32 +151,6 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
setProjectToRollbackMigration(undefined)
}

const onConfirmProjectFinalizeMigration = async () => {
if (!projectToFinalizeMigration) return
const data = targetNotification?.data as PostgresqlUpgradeData
const { resource } = data.additional as any
if (!resource) return
const res = await patch(`${API_URL}/database/${projectToFinalizeMigration.ref}/${resource}`, {})
if (!res.error) {
const project = await getProjectDetail({ ref: projectToFinalizeMigration.ref })
if (project) {
meta.setProjectDetails(project)
}

ui.setNotification({
category: 'success',
message: `Successfully finalized migration for project "${projectToFinalizeMigration.name}"`,
})
} else {
ui.setNotification({
error: res.error,
category: 'error',
message: `Failed to finalize migration: ${res.error.message}`,
})
}
setProjectToFinalizeMigration(undefined)
}

if (!notifications || !Array.isArray(notifications)) return null

return (
Expand Down Expand Up @@ -221,10 +194,6 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
setProjectToRollbackMigration(project)
setTargetNotification(notification)
}}
onSelectFinalizeMigration={(project, notification) => {
setProjectToFinalizeMigration(project)
setTargetNotification(notification)
}}
/>
{i !== notifications.length - 1 && <Popover.Separator />}
</Fragment>
Expand Down Expand Up @@ -372,34 +341,6 @@ const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
onSelectCancel={() => setProjectToRollbackMigration(undefined)}
onSelectConfirm={onConfirmProjectRollbackMigration}
/>
<ConfirmModal
danger
size="small"
visible={projectToFinalizeMigration !== undefined}
title={`Finalize schema migration for "${projectToFinalizeMigration?.name}"`}
// @ts-ignore
description={
<div className="text-scale-1200 space-y-4">
<Alert withIcon variant="warning" title="This action canot be undone" />
<div className="space-y-1">
<p>The following schema migration will be finalized for the project</p>
<ol className="list-disc pl-6">
<li>
<div className="flex items-center space-x-1">
<p>{(targetNotification?.data as any)?.additional?.name}</p>
<IconArrowRight size={12} strokeWidth={2} />
<p>{(targetNotification?.data as any)?.additional?.version_to}</p>
</div>
</li>
</ol>
</div>
</div>
}
buttonLabel="Confirm"
buttonLoadingLabel="Confirm"
onSelectCancel={() => setProjectToFinalizeMigration(undefined)}
onSelectConfirm={onConfirmProjectFinalizeMigration}
/>
</>
)
}
Expand Down

0 comments on commit 745b0fa

Please sign in to comment.