Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/splinter notifications issue #25857

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const NotificationRow: ItemRenderer<Notification, NotificationRowProps> = ({
const ref = useRef<HTMLDivElement>(null)
const { ref: viewRef, inView } = useInView()
const { status, priority } = notification

console.log('the', { notification })
const data = notification.data as NotificationData
const project = data.project_ref !== undefined ? getProject(data.project_ref) : undefined
const organization =
Expand Down Expand Up @@ -133,6 +133,7 @@ const NotificationRow: ItemRenderer<Notification, NotificationRowProps> = ({
{data.actions.map((action, idx) => {
const key = `${notification.id}-action-${idx}`
if (action.url !== undefined) {
console.log({ action }, project)
const url = action.url.includes('[ref]')
? action.url.replace('[ref]', project?.ref ?? '_')
: action.url.includes('[slug]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const NotificationsPopoverV2 = () => {
const rowHeights = useRef<{ [key: number]: number }>({})

const { data: projects } = useProjectsQuery()
console.log({ projects })
const { data: organizations } = useOrganizationsQuery()
const {
data,
Expand Down Expand Up @@ -70,7 +71,7 @@ const NotificationsPopoverV2 = () => {
useNotificationsArchiveAllMutation({
onSuccess: () => toast.success('Successfully archived all notifications'),
})

console.log({ projects })
const notifications = useMemo(() => data?.pages.flatMap((page) => page) ?? [], [data?.pages])
const hasNewNotifications = summary?.unread_count ?? 0 > 0
const hasWarning = summary?.has_warning
Expand All @@ -81,7 +82,7 @@ const NotificationsPopoverV2 = () => {
updateNotifications({ ids: markedRead.current, status: 'seen' })
}
}

console.log({ notifications })
return (
<Popover_Shadcn_
modal={false}
Expand Down
70 changes: 56 additions & 14 deletions apps/studio/data/notifications/notifications-v2-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,65 @@ export type NotificationData = {

export async function getNotifications(options: NotificationVariables, signal?: AbortSignal) {
const { status, filters, page = 0, limit = NOTIFICATIONS_PAGE_LIMIT } = options
const { data, error } = await get('/platform/notifications', {
params: {
// @ts-ignore
query: {
offset: page * limit,
limit,
...(status !== undefined ? { status } : { status: ['new', 'seen'] }),
...(filters.priority.length > 0 ? { priority: filters.priority } : {}),
...(filters.organizations.length > 0 ? { org_slug: filters.organizations } : {}),
...(filters.projects.length > 0 ? { project_ref: filters.projects } : {}),
// const { data, error } = await get('/platform/notifications', {
// params: {
// // @ts-ignore
// query: {
// offset: page * limit,
// limit,
// ...(status !== undefined ? { status } : { status: ['new', 'seen'] }),
// ...(filters.priority.length > 0 ? { priority: filters.priority } : {}),
// ...(filters.organizations.length > 0 ? { org_slug: filters.organizations } : {}),
// ...(filters.projects.length > 0 ? { project_ref: filters.projects } : {}),
// },
// },
// headers: { Version: '2' },
// signal,
// })

// if (error) throw error

const data = [
{
id: '8cc59e3b-f3ee-466b-a1e6-963074dc26f6',
inserted_at: '2024-04-25T11:56:45.051518+00:00',
status: 'seen',
priority: 'Warning',
name: 'success.rls-misconfig-enterprise-team.20240425',
data: {
title: 'Security Recommendation',
actions: [{ url: '/project/[ref]/database/security-advisor', label: 'Security Advisor' }],
message:
'The way you have configured your database is open to the public, please check the notifications in the Security Advisor page.',
project_ref: 'pnlhfnllpxpapxrdkihw',
},
meta: null,
},
{
id: '8ce59e3b-f3ee-466b-a1e6-963074dc26f6',
inserted_at: '2024-04-25T11:56:45.051518+00:00',
status: 'seen',
priority: 'Warning',
name: 'success.rls-misconfig-enterprise-team.20240425',
data: {
title: 'Security Recommendation 2',
actions: [{ url: '/project/[ref]/database/security-advisor', label: 'Security Advisor' }],
message:
'The way you have configured your database is open to the public, please check the notifications in the Security Advisor page.',
project_ref: 'yxrbshyrkjhbbglmsqyj',
},
meta: null,
},
headers: { Version: '2' },
signal,
})

if (error) throw error
// {
// title: 'Security Recommendation',
// actions: [{ url: '/project/[ref]/database/security-advisor', label: 'Security Advisor' }],
// message:
// 'The way you have configured your database is open to the public, please check the notifications in the Security Advisor page.',
// project_ref: 'pnlhfnllpxpapxrdkihw',
// },
// Add more notifications as needed
]

return data
}
Expand Down