Skip to content

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

Support archiving all notifications, and unarchiving a notification (#20376)

Joshen Limade4b3492d2a
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationRow.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationRow.tsx
index 6c21a613791..9eafab5e39f 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationRow.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationRow.tsx
@@ -11,6 +11,7 @@ import { Notification, NotificationData } from 'data/notifications/notifications
import { Project } from 'data/projects/project-detail-query'
import { Organization } from 'types'
import { CriticalIcon, WarningIcon } from './NotificationsPopover.constants'
+import { ArchiveRestoreIcon } from 'lucide-react'
interface NotificationRowProps {
index: number
@@ -19,7 +20,7 @@ interface NotificationRowProps {
setRowHeight: (idx: number, height: number) => void
getProject: (ref: string) => Project
getOrganization: (id: number) => Organization
- onArchiveNotification: (id: string) => void
+ onUpdateNotificationStatus: (id: string, status: 'archived' | 'seen') => void
queueMarkRead: (id: string) => void
}
@@ -30,7 +31,7 @@ const NotificationRow = ({
setRowHeight,
getProject,
getOrganization,
- onArchiveNotification,
+ onUpdateNotificationStatus,
queueMarkRead,
}: NotificationRowProps) => {
const ref = useRef<HTMLDivElement>(null)
@@ -164,14 +165,40 @@ const NotificationRow = ({
<div className="flex flex-col items-center gap-y-2">
{priority === 'Warning' && <WarningIcon className="w-5 h-5" />}
{priority === 'Critical' && <CriticalIcon className="w-5 h-5" />}
- {notification.status !== 'archived' && (
+ {notification.status === 'archived' ? (
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger asChild>
+ <Button
+ type="outline"
+ icon={
+ <ArchiveRestoreIcon size={13} strokeWidth={2} className="text-foreground-light" />
+ }
+ className="p-1.5 group-hover:opacity-100 opacity-0 transition rounded-full"
+ onClick={() => onUpdateNotificationStatus(notification.id, 'seen')}
+ />
+ </Tooltip.Trigger>
+ <Tooltip.Portal>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-alternative py-1 px-2 leading-none shadow',
+ 'border border-background',
+ ].join(' ')}
+ >
+ <span className="text-xs text-foreground">Unarchive</span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Portal>
+ </Tooltip.Root>
+ ) : (
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger asChild>
<Button
type="outline"
icon={<IconArchive size={13} strokeWidth={2} className="text-foreground-light" />}
className="p-1.5 group-hover:opacity-100 opacity-0 transition rounded-full"
- onClick={() => onArchiveNotification(notification.id)}
+ onClick={() => onUpdateNotificationStatus(notification.id, 'archived')}
/>
</Tooltip.Trigger>
<Tooltip.Portal>
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx
index af89698dad2..a6acb360aca 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx
@@ -2,6 +2,7 @@ import clsx from 'clsx'
import { useMemo, useRef, useState } from 'react'
import {
Button,
+ IconArchive,
IconInbox,
PopoverContent_Shadcn_,
PopoverTrigger_Shadcn_,
@@ -21,6 +22,8 @@ import { useNotificationsStateSnapshot } from 'state/notifications'
import NotificationRow from './NotificationRow'
import { NotificationsFilter } from './NotificationsFilter'
import { CriticalIcon, WarningIcon } from './NotificationsPopover.constants'
+import { useNotificationsArchiveAllMutation } from 'data/notifications/notifications-v2-archive-all-mutation'
+import toast from 'react-hot-toast'
const NotificationsPopoverV2 = () => {
const [open, setOpen] = useState(false)
@@ -62,6 +65,10 @@ const NotificationsPopoverV2 = () => {
})
const { data: summary, isSuccess: isSuccessSummary } = useNotificationsSummaryQuery()
const { mutate: updateNotifications } = useNotificationsV2UpdateMutation()
+ const { mutate: archiveAllNotifications, isLoading: isArchiving } =
+ useNotificationsArchiveAllMutation({
+ onSuccess: () => toast.success('Successfully archived all notifications'),
+ })
const notifications = useMemo(() => data?.pages.flatMap((page) => page) ?? [], [data?.pages])
const hasNewNotifications = summary?.unread_count ?? 0 > 0
@@ -75,167 +82,183 @@ const NotificationsPopoverV2 = () => {
}
return (
- <Popover_Shadcn_
- modal={false}
- open={open}
- onOpenChange={(open) => {
- setOpen(open)
- if (!open) markNotificationsRead()
- }}
- >
- <PopoverTrigger_Shadcn_ asChild>
- <Button
- type={hasNewNotifications ? 'outline' : 'text'}
- className={clsx(
- 'group',
- hasNewNotifications ? 'rounded-full px-1.5' : 'px-1',
- hasCritical
- ? 'border-destructive-500 hover:border-destructive-600 hover:bg-destructive-300'
- : hasWarning
- ? 'border-warning-500 hover:border-warning-600 hover:bg-warning-300'
- : ''
- )}
- icon={
- hasCritical ? (
- <CriticalIcon className="transition-all -mr-3.5 group-hover:-mr-1 z-10" />
- ) : hasWarning ? (
- <WarningIcon className="transition-all -mr-3.5 group-hover:-mr-1 z-10" />
- ) : hasNewNotifications ? (
- <div
- className={clsx(
- 'transition-all -mr-3 group-hover:-mr-1',
- 'z-10 h-4 flex items-center justify-center rounded-full bg-black dark:bg-white',
- (summary?.unread_count ?? 0) > 9 ? 'px-0.5 w-auto' : 'w-4'
- )}
- >
- <p className="text-xs text-background-alternative">{summary?.unread_count}</p>
- </div>
- ) : null
- }
- iconRight={
- <IconInbox
- size={18}
- strokeWidth={1.5}
- className="transition group-hover:text-foreground text-foreground-light"
- />
- }
- />
- </PopoverTrigger_Shadcn_>
- <PopoverContent_Shadcn_ className="p-0 w-[450px] overflow-hidden" side="bottom" align="end">
- <div className="px-4">
- <p className="pt-4 pb-1 text-sm">Notifications</p>
- <div className="flex items-center">
- <Tabs
- size="medium"
- type="underlined"
- baseClassNames="!space-y-0"
- listClassNames="[&>button>span]:text-xs"
- activeId={activeTab}
- onChange={(tab: 'inbox' | 'archived') => {
- setActiveTab(tab)
- if (tab === 'archived' && snap.filterStatuses.includes('unread')) {
- snap.setFilters('unread', 'status')
- }
- }}
- >
- <Tabs.Panel
- id="inbox"
- label="Inbox"
- iconRight={
- isSuccessSummary ? (
- <div
- className={clsx([
- 'flex items-center justify-center text-xs rounded-full bg-surface-300 h-4',
- (summary?.unread_count ?? 0) > 9 ? 'px-0.5 w-auto' : 'w-4',
- ])}
- >
- {summary?.unread_count}
- </div>
- ) : null
- }
+ <>
+ <Popover_Shadcn_
+ modal={false}
+ open={open}
+ onOpenChange={(open) => {
+ setOpen(open)
+ if (!open) markNotificationsRead()
+ }}
+ >
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button
+ type={hasNewNotifications ? 'outline' : 'text'}
+ className={clsx(
+ 'group',
+ hasNewNotifications ? 'rounded-full px-1.5' : 'px-1',
+ hasCritical
+ ? 'border-destructive-500 hover:border-destructive-600 hover:bg-destructive-300'
+ : hasWarning
+ ? 'border-warning-500 hover:border-warning-600 hover:bg-warning-300'
+ : ''
+ )}
+ icon={
+ hasCritical ? (
+ <CriticalIcon className="transition-all -mr-3.5 group-hover:-mr-1 z-10" />
+ ) : hasWarning ? (
+ <WarningIcon className="transition-all -mr-3.5 group-hover:-mr-1 z-10" />
+ ) : hasNewNotifications ? (
+ <div
+ className={clsx(
+ 'transition-all -mr-3 group-hover:-mr-1',
+ 'z-10 h-4 flex items-center justify-center rounded-full bg-black dark:bg-white',
+ (summary?.unread_count ?? 0) > 9 ? 'px-0.5 w-auto' : 'w-4'
+ )}
+ >
+ <p className="text-xs text-background-alternative">{summary?.unread_count}</p>
+ </div>
+ ) : null
+ }
+ iconRight={
+ <IconInbox
+ size={18}
+ strokeWidth={1.5}
+ className="transition group-hover:text-foreground text-foreground-light"
/>
- <Tabs.Panel id="archived" label="Archived" />
- </Tabs>
+ }
+ />
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_ className="p-0 w-[450px] overflow-hidden" side="bottom" align="end">
+ <div className="px-4">
+ <p className="pt-4 pb-1 text-sm">Notifications</p>
+ <div className="flex items-center">
+ <Tabs
+ size="medium"
+ type="underlined"
+ baseClassNames="!space-y-0"
+ listClassNames="[&>button>span]:text-xs"
+ activeId={activeTab}
+ onChange={(tab: 'inbox' | 'archived') => {
+ setActiveTab(tab)
+ if (tab === 'archived' && snap.filterStatuses.includes('unread')) {
+ snap.setFilters('unread', 'status')
+ }
+ }}
+ >
+ <Tabs.Panel
+ id="inbox"
+ label="Inbox"
+ iconRight={
+ isSuccessSummary ? (
+ <div
+ className={clsx([
+ 'flex items-center justify-center text-xs rounded-full bg-surface-300 h-4',
+ (summary?.unread_count ?? 0) > 9 ? 'px-0.5 w-auto' : 'w-4',
+ ])}
+ >
+ {summary?.unread_count}
+ </div>
+ ) : null
+ }
+ />
+ <Tabs.Panel id="archived" label="Archived" />
+ </Tabs>
- <NotificationsFilter activeTab={activeTab} />
- </div>
- </div>
- <div className="border-t">
- {isLoading && (
- <div className="p-4">
- <GenericSkeletonLoader />
- </div>
- )}
- {isError && (
- <div className="p-4">
- <AlertError subject="Failed to retrieve notifications" error={error} />
+ <NotificationsFilter activeTab={activeTab} />
</div>
- )}
- {isSuccess && (
- <div className="flex flex-1 h-[400px]">
- {notifications.length > 0 &&
- !(activeTab === 'archived' && snap.filterStatuses.includes('unread')) ? (
- <InfiniteList
- items={notifications}
- ItemComponent={NotificationRow}
- LoaderComponent={
- <div className="p-4">
- <ShimmeringLoader />
+ </div>
+ <div className="border-t">
+ {isLoading && (
+ <div className="p-4">
+ <GenericSkeletonLoader />
+ </div>
+ )}
+ {isError && (
+ <div className="p-4">
+ <AlertError subject="Failed to retrieve notifications" error={error} />
+ </div>
+ )}
+ {isSuccess && (
+ <div className="flex flex-1 h-[400px]">
+ {notifications.length > 0 &&
+ !(activeTab === 'archived' && snap.filterStatuses.includes('unread')) ? (
+ <InfiniteList
+ items={notifications}
+ ItemComponent={NotificationRow}
+ LoaderComponent={
+ <div className="p-4">
+ <ShimmeringLoader />
+ </div>
+ }
+ itemProps={{
+ setRowHeight: (idx: number, height: number) => {
+ if (rowHeights.current) {
+ rowHeights.current = { ...rowHeights.current, [idx]: height }
+ }
+ },
+ getProject: (ref: string) => projects?.find((project) => project.ref === ref),
+ getOrganization: (id: number) => organizations?.find((org) => org.id === id),
+ onUpdateNotificationStatus: (id: string, status: 'archived' | 'seen') => {
+ updateNotifications({ ids: [id], status })
+ },
+ queueMarkRead: (id: string) => {
+ if (markedRead.current && !markedRead.current.includes(id)) {
+ markedRead.current.push(id)
+ }
+ },
+ }}
+ getItemSize={(idx: number) => rowHeights?.current?.[idx] ?? 56}
+ hasNextPage={hasNextPage}
+ isLoadingNextPage={isFetchingNextPage}
+ onLoadNextPage={() => fetchNextPage()}
+ />
+ ) : (
+ <div className="flex flex-col gap-y-4 items-center flex-grow justify-center">
+ <IconInbox size={32} className="text-foreground-light" />
+ <div className="flex flex-col gap-y-1">
+ <p className="text-foreground-light text-sm mx-auto text-center">
+ {activeTab === 'archived'
+ ? `No archived notifications${
+ snap.numFiltersApplied > 0
+ ? ` based on the ${snap.numFiltersApplied} filter${
+ snap.numFiltersApplied > 1 ? 's' : ''
+ } applied`
+ : ''
+ }`
+ : snap.numFiltersApplied > 0
+ ? `No notifications based on the ${snap.numFiltersApplied} filter${
+ snap.numFiltersApplied > 1 ? 's' : ''
+ } applied`
+ : 'All caught up'}
+ </p>
+ <p className="text-foreground-lighter text-xs w-60 mx-auto text-center">
+ {activeTab === 'archived'
+ ? 'Notifications that you have previously archived will be shown here'
+ : 'You will be notified here for any notices on your organizations and projects'}
+ </p>
</div>
- }
- itemProps={{
- setRowHeight: (idx: number, height: number) => {
- if (rowHeights.current) {
- rowHeights.current = { ...rowHeights.current, [idx]: height }
- }
- },
- getProject: (ref: string) => projects?.find((project) => project.ref === ref),
- getOrganization: (id: number) => organizations?.find((org) => org.id === id),
- onArchiveNotification: (id: string) =>
- updateNotifications({ ids: [id], status: 'archived' }),
- queueMarkRead: (id: string) => {
- if (markedRead.current && !markedRead.current.includes(id)) {
- markedRead.current.push(id)
- }
- },
- }}
- getItemSize={(idx: number) => rowHeights?.current?.[idx] ?? 56}
- hasNextPage={hasNextPage}
- isLoadingNextPage={isFetchingNextPage}
- onLoadNextPage={() => fetchNextPage()}
- />
- ) : (
- <div className="flex flex-col gap-y-4 items-center flex-grow justify-center">
- <IconInbox size={32} className="text-foreground-light" />
- <div className="flex flex-col gap-y-1">
- <p className="text-foreground-light text-sm mx-auto text-center">
- {activeTab === 'archived'
- ? `No archived notifications${
- snap.numFiltersApplied > 0
- ? ` based on the ${snap.numFiltersApplied} filter${
- snap.numFiltersApplied > 1 ? 's' : ''
- } applied`
- : ''
- }`
- : snap.numFiltersApplied > 0
- ? `No notifications based on the ${snap.numFiltersApplied} filter${
- snap.numFiltersApplied > 1 ? 's' : ''
- } applied`
- : 'All caught up'}
- </p>
- <p className="text-foreground-lighter text-xs w-60 mx-auto text-center">
- {activeTab === 'archived'
- ? 'Notifications that you have previously archived will be shown here'
- : 'You will be notified here for any notices on your organizations and projects'}
- </p>
</div>
- </div>
- )}
+ )}
+ </div>
+ )}
+ </div>
+ {notifications.length > 0 && activeTab === 'inbox' && (
+ <div className="flex items-center justify-center p-1.5 border-t">
+ <Button
+ disabled={isArchiving}
+ loading={isArchiving}
+ type="text"
+ icon={<IconArchive />}
+ onClick={() => archiveAllNotifications()}
+ >
+ Archive all
+ </Button>
</div>
)}
- </div>
- </PopoverContent_Shadcn_>
- </Popover_Shadcn_>
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
+ </>
)
}
diff --git a/apps/studio/data/api.d.ts b/apps/studio/data/api.d.ts
index e0e09be4a33..8ee070e8757 100644
--- a/apps/studio/data/api.d.ts
+++ b/apps/studio/data/api.d.ts
@@ -25,6 +25,10 @@ export interface paths {
/** Get an aggregated data of interest across all notifications for the user */
get: operations['NotificationsController_getNotificationsSummary']
}
+ '/platform/notifications/archive-all': {
+ /** Archives all notifications */
+ patch: operations['NotificationsController_archiveAllNotifications']
+ }
'/platform/reset-password': {
/** Reset password for email */
post: operations['ResetPasswordController_resetPassword']
@@ -938,6 +942,10 @@ export interface paths {
/** Get an aggregated data of interest across all notifications for the user */
get: operations['NotificationsController_getNotificationsSummary']
}
+ '/v0/notifications/archive-all': {
+ /** Archives all notifications */
+ patch: operations['NotificationsController_archiveAllNotifications']
+ }
'/v0/status': {
/** Get infrastructure status */
get: operations['StatusController_getStatus']
@@ -5072,8 +5080,8 @@ export interface operations {
query: {
status: 'new' | 'seen' | 'archived'
priority: 'Critical' | 'Warning' | 'Info'
- org_slug: string[]
- project_ref: string[]
+ org_slug?: string[]
+ project_ref?: string[]
offset: number
limit: number
}
@@ -5138,6 +5146,18 @@ export interface operations {
}
}
}
+ /** Archives all notifications */
+ NotificationsController_archiveAllNotifications: {
+ responses: {
+ 200: {
+ content: never
+ }
+ /** @description Failed to archive all notifications */
+ 500: {
+ content: never
+ }
+ }
+ }
/** Reset password for email */
ResetPasswordController_resetPassword: {
requestBody: {
diff --git a/apps/studio/data/notifications/notifications-v2-archive-all-mutation.ts b/apps/studio/data/notifications/notifications-v2-archive-all-mutation.ts
new file mode 100644
index 00000000000..02d0a507551
--- /dev/null
+++ b/apps/studio/data/notifications/notifications-v2-archive-all-mutation.ts
@@ -0,0 +1,38 @@
+import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
+import { toast } from 'react-hot-toast'
+
+import { patch } from 'data/fetchers'
+import { ResponseError } from 'types'
+import { notificationKeys } from './keys'
+
+export async function archiveAllNotifications() {
+ const { data, error } = await patch('/platform/notifications/archive-all', {
+ headers: { Version: '2' },
+ })
+ if (error) throw error
+ return data
+}
+
+type NotificationsArchiveAllData = Awaited<ReturnType<typeof archiveAllNotifications>>
+
+export const useNotificationsArchiveAllMutation = ({
+ onSuccess,
+ onError,
+ ...options
+}: Omit<UseMutationOptions<NotificationsArchiveAllData, ResponseError>, 'mutationFn'> = {}) => {
+ const queryClient = useQueryClient()
+ return useMutation<NotificationsArchiveAllData, ResponseError>(() => archiveAllNotifications(), {
+ async onSuccess(data, variables, context) {
+ await queryClient.invalidateQueries(notificationKeys.list())
+ await onSuccess?.(data, variables, context)
+ },
+ async onError(data, variables, context) {
+ if (onError === undefined) {
+ toast.error(`Failed to archive all notifications: ${data.message}`)
+ } else {
+ onError(data, variables, context)
+ }
+ },
+ ...options,
+ })
+}