The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update notifications to use new types
Joshen Lim5b839c4d5373
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationActions.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationActions.tsxnew file mode 100644index 00000000000..ee9cac8fd42--- /dev/null+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationActions.tsx@@ -0,0 +1,30 @@+import { FC } from 'react'+import { Button } from '@supabase/ui'++interface Props {+ availableActions: any[]+}++const NotificationActions: FC<Props> = ({ availableActions }) => {+ return (+ <div className="space-y-2">+ {availableActions.map((action: any) => {+ if (action.action_type === 'project.upgrade') {+ return (+ <Button key={action.action_type} type="default">+ Upgrade project+ </Button>+ )+ } else if (action.action_type === 'postgresql.restart') {+ return (+ <Button key={action.action_type} type="default">+ Restart project+ </Button>+ )+ }+ })}+ </div>+ )+}++export default NotificationActionsdiff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsxnew file mode 100644index 00000000000..88a89373271--- /dev/null+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx@@ -0,0 +1,42 @@+import dayjs from 'dayjs'+import { FC } from 'react'+import { Notification, NotificationStatus } from '@supabase/shared-types/out/notifications'++import { useStore } from 'hooks'+import { Project } from 'types'+import { formatNotificationText } from './NotificationRows.utils'+import NotificationActions from './NotificationActions'++interface Props {+ notification: Notification+}++const NotificationRow: FC<Props> = ({ notification }) => {+ const { app } = useStore()+ const [project] = app.projects.list((project: Project) => project.id === notification.project_id)++ const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma')+ const availableActions = notification.meta?.actions_available ?? []++ return (+ <div className="grid grid-cols-12 py-2">+ <div className="col-span-1 flex justify-center">+ {notification.notification_status !== NotificationStatus.Seen && (+ <div className="mt-1.5 h-2 w-2 rounded-full bg-green-900" />+ )}+ </div>+ <div className={availableActions.length > 0 ? 'col-span-7' : 'col-span-10'}>+ <div className="space-y-1">+ <p className="text-sm">{formatNotificationText(project, notification)}</p>+ <p className="text-scale-1000 text-sm">{insertedAt}</p>+ </div>+ </div>+ <div className="col-span-3 flex items-center justify-end">+ {availableActions.length > 0 && <NotificationActions availableActions={availableActions} />}+ </div>+ <div className="col-span-1" />+ </div>+ )+}++export default NotificationRowdiff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRows.utils.ts b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRows.utils.tsnew file mode 100644index 00000000000..8c4499e3928--- /dev/null+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRows.utils.ts@@ -0,0 +1,42 @@+import { Project } from 'types'+import { Notification, NotificationName } from '@supabase/shared-types/out/notifications'++// Switch to proper typing with NotificationName after PR is in+export const formatNotificationText = (project: Project, notification: Notification) => {+ const projectName = project.name+ const notificationName = notification.notification_name++ if (notificationName === NotificationName.ProjectExceedingTierLimit) {+ const { violations } = notification.data+ const violationsText = violations+ .map((violation: any) => violation.dimension)+ .reduce((a: string, b: string) => `${a}, ${b}`)++ return `Your project "${projectName}" has exceeded its limits in the following areas: ${violationsText}. Please upgrade your project to ensure continued availability.`+ } else if (notificationName === 'postgresql.upgrade-available') {+ const { upgrade_type, additional } = notification.data+ const { name, version_to } = additional+ if (upgrade_type === 'postgresql-server') {+ return `A new version of Postgres (${version_to}) is now available for project "${projectName}". You may restart your project to get this update.`+ } else if (upgrade_type === 'extensions') {+ return `A new version of the extension "${name}" (${version_to}) is now available for project "${projectName}". You may restart your project to get this update.`+ }+ return ''+ } else if (notificationName === 'postgresql.upgrade-completed') {+ const { upgrade_type, additional } = notification.data+ const { name, version_to } = additional+ if (upgrade_type === 'postgresql-server') {+ return `Postgres (${version_to}) has been successfully updated to ${version_to} for project "${projectName}".`+ } else if (upgrade_type === 'extensions') {+ return `The extension "${name}" has been successfully updated to ${version_to} for project "${projectName}`+ }+ } else if (notificationName === 'project.update-completed') {+ const { upgrades } = notification.data+ const upgradesText = upgrades+ .map((upgrade: any) => upgrade.name)+ .reduce((a: string, b: string) => `${a}, ${b}`)+ return `The following services have been successfully updated for project "${projectName}": ${upgradesText}`+ } else {+ return `Unknown notification type: ${notification.notification_name} - Please reach out to support for more information`+ }+}diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlBugfixNotification.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlBugfixNotification.tsxdeleted file mode 100644index 7decd8711eb..00000000000--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlBugfixNotification.tsx+++ /dev/null@@ -1,33 +0,0 @@-import dayjs from 'dayjs'-import { FC } from 'react'-import {- Button,- Dropdown,- IconCheck,- IconXSquare,- IconRefreshCw,- IconMoreVertical,-} from '@supabase/ui'-import { Notification } from '@supabase/shared-types/out/notifications'--interface Props {- notification: Notification-}--const PostgresqlBugfixNotification: FC<Props> = ({ notification }) => {- const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma')-- return (- <div className="flex items-center justify-between space-x-4">- <div className="space-y-1">- <p className="text-sm">- A fix for {'{extension}'} is now available! Restart your project for changes to take- place.- </p>- <p className="text-scale-1000 text-sm">{insertedAt}</p>- </div>- </div>- )-}--export default PostgresqlBugfixNotificationdiff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlInfoNotification.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlInfoNotification.tsxdeleted file mode 100644index 9bf744605ac..00000000000--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlInfoNotification.tsx+++ /dev/null@@ -1,36 +0,0 @@-import dayjs from 'dayjs'-import { FC } from 'react'-import {- Button,- Dropdown,- IconCheck,- IconMoreVertical,- IconRefreshCw,- IconXSquare,-} from '@supabase/ui'-import { Notification } from '@supabase/shared-types/out/notifications'-import { PostgreslInformationalNotification } from './Notifications.types'--interface Props {- notification: Notification-}--const PostgresqlInfoNotification: FC<Props> = ({ notification }) => {- const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma')- const { new_version, extension_name } = notification.data as PostgreslInformationalNotification-- return (- <div className="flex items-center justify-between space-x-4">- <div className="space-y-1">- <p className="text-sm">- A new version ({new_version}) for {extension_name} is now available!{' '}- <span className="text-brand-900 cursor-pointer">Restart</span> your project for changes to- take place.- </p>- <p className="text-scale-1000 text-sm">{insertedAt}</p>- </div>- </div>- )-}--export default PostgresqlInfoNotificationdiff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/TierLimitExceededNotification.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/TierLimitExceededNotification.tsxdeleted file mode 100644index 844947a27bf..00000000000--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/TierLimitExceededNotification.tsx+++ /dev/null@@ -1,47 +0,0 @@-import dayjs from 'dayjs'-import { FC } from 'react'-import {- Button,- Dropdown,- IconCheck,- IconMoreVertical,- IconRefreshCw,- IconXSquare,-} from '@supabase/ui'-import { Notification } from '@supabase/shared-types/out/notifications'--import { useStore } from 'hooks'-import { Project } from 'types'--interface Props {- notification: Notification-}--const DIMENSION: any = {- db_storage: 'storage',-}--const TierLimitExceededNotification: FC<Props> = ({ notification }) => {- const { app } = useStore()- const [project] = app.projects.list((project: Project) => project.id === notification.project_id)-- const { dimension, first_violated_at } = notification.data- const projectName = project?.name ?? 'Unknown'- const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma')- const firstViolatedAt = dayjs(first_violated_at).format('DD MMM YYYY')-- return (- <div className="flex items-center justify-between space-x-4">- <div className="space-y-1">- <p className="text-sm">- Your project {projectName} has exceeded it's {DIMENSION[dimension]} limit since{' '}- {firstViolatedAt}. <span className="text-brand-900 cursor-pointer">Upgrade</span> your- project to ensure its continued availability.- </p>- <p className="text-scale-1000 text-sm">{insertedAt}</p>- </div>- </div>- )-}--export default TierLimitExceededNotificationdiff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsxindex 35cc551c0cd..f975b387fe5 100644--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx@@ -1,26 +1,14 @@import { FC, Fragment } from 'react'-import {- Button,- IconBell,- Popover,- Dropdown,- IconCheck,- IconMoreVertical,- IconXSquare,-} from '@supabase/ui'-import {- Notification,- NotificationName,- NotificationStatus,-} from '@supabase/shared-types/out/notifications'+import { Button, IconBell, Popover } from '@supabase/ui'+import { NotificationStatus } from '@supabase/shared-types/out/notifications'import { useNotifications } from 'hooks'-import TierLimitExceededNotification from './TierLimitExceededNotification'-import PostgresqlInfoNotification from './PostgresqlInfoNotification'-import PostgresqlBugfixNotification from './PostgresqlBugfixNotification'+import NotificationRow from './NotificationRow'interface Props {}+const MAX_NOTIFICATIONS_TO_SHOW = 4+const NotificationsPopover: FC<Props> = () => {const { notifications } = useNotifications()@@ -30,54 +18,33 @@ const NotificationsPopover: FC<Props> = () => {(notification) => notification.notification_status === NotificationStatus.New)- const renderNotification = (notification: Notification) => {- switch (notification.notification_name) {- case NotificationName.ProjectExceedingTierLimit:- return <TierLimitExceededNotification key={notification.id} notification={notification} />- case NotificationName.PostgresqlInformational:- return <PostgresqlInfoNotification key={notification.id} notification={notification} />- case NotificationName.PostgresqlBugfix:- return <PostgresqlBugfixNotification key={notification.id} notification={notification} />- default:- return <div key={notification.id}>Unknown</div>+ const onOpenChange = (open: boolean) => {+ if (!open) {+ // Mark notifications as seen}}+ if (!notifications) return <div />+return (<Popoversize="content"align="end"side="bottom"sideOffset={8}+ onOpenChange={onOpenChange}overlay={- <div className="my-2 w-[500px]">+ <div className="mb-2 w-[550px]">+ <div className="mb-2 flex items-center justify-between border-b border-gray-500 bg-gray-400 px-4 py-2">+ <p className="text-sm">Notifications</p>+ <p className="text-scale-1000 hover:text-scale-1200 cursor-pointer text-sm transition">+ See all{' '}+ {notifications.length > MAX_NOTIFICATIONS_TO_SHOW && `(${notifications.length})`}+ </p>+ </div>{notifications?.map((notification, i: number) => (<Fragment key={notification.id}>- <div className="grid grid-cols-12 py-2">- <div className="col-span-1 flex items-center justify-center">- {notification.notification_status !== NotificationStatus.Seen && (- <div className="h-2 w-2 rounded-full bg-green-900" />- )}- </div>- <div className="col-span-9">{renderNotification(notification)}</div>- <div className="col-span-2 flex items-center justify-center">- <Dropdown- side="bottom"- align="end"- size="small"- overlay={[- <Dropdown.Item key="mark-read" icon={<IconCheck size={14} />}>- Mark as read- </Dropdown.Item>,- <Dropdown.Item key="dismiss" icon={<IconXSquare size={14} />}>- Dismiss notification- </Dropdown.Item>,- ]}- >- <IconMoreVertical size={16} />- </Dropdown>- </div>- </div>+ <NotificationRow notification={notification} />{i !== notifications.length - 1 && <Popover.Seperator />}</Fragment>))}@@ -87,7 +54,7 @@ const NotificationsPopover: FC<Props> = () => {<div className="relative"><Buttonas="span"- type={hasNewNotifications ? 'default' : 'text'}+ type="default"icon={<IconBell size={16} strokeWidth={1.5} className="text-scale-1200" />}/>{hasNewNotifications && (