Skip to content

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

Fix re-rendering of Account AuditLogs (#34994)

Joshen Limab2ac05f10a0
diff --git a/apps/studio/components/interfaces/Account/AuditLogs.tsx b/apps/studio/components/interfaces/Account/AuditLogs.tsx
index 63a96069040..eeef64ab8c9 100644
--- a/apps/studio/components/interfaces/Account/AuditLogs.tsx
+++ b/apps/studio/components/interfaces/Account/AuditLogs.tsx
@@ -38,23 +38,6 @@ const AuditLogs = () => {
iso_timestamp_end: dateRange.to,
})
- // This feature depends on the subscription tier of the user. Free user can view logs up to 1 day
- // in the past. The API limits the logs to maximum of 1 day and 5 minutes so when the page is
- // viewed for more than 5 minutes, the call parameters needs to be updated. This also works with
- // higher tiers (7 days of logs).The user will see a loading shimmer.
- useEffect(() => {
- const duration = dayjs(dateRange.from).diff(dayjs(dateRange.to))
- const interval = setInterval(() => {
- const currentTime = dayjs().utc().set('millisecond', 0)
- setDateRange({
- from: currentTime.add(duration).toISOString(),
- to: currentTime.toISOString(),
- })
- }, 5 * 60000)
-
- return () => clearInterval(interval)
- }, [dateRange.from, dateRange.to])
-
const retentionPeriod = data?.retention_period ?? 0
const logs = data?.result ?? []
const sortedLogs = logs
@@ -74,6 +57,23 @@ const AuditLogs = () => {
const minDate = dayjs().subtract(retentionPeriod, 'days')
const maxDate = dayjs()
+ // This feature depends on the subscription tier of the user. Free user can view logs up to 1 day
+ // in the past. The API limits the logs to maximum of 1 day and 5 minutes so when the page is
+ // viewed for more than 5 minutes, the call parameters needs to be updated. This also works with
+ // higher tiers (7 days of logs).The user will see a loading shimmer.
+ useEffect(() => {
+ const duration = dayjs(dateRange.from).diff(dayjs(dateRange.to))
+ const interval = setInterval(() => {
+ const currentTime = dayjs().utc().set('millisecond', 0)
+ setDateRange({
+ from: currentTime.add(duration).toISOString(),
+ to: currentTime.toISOString(),
+ })
+ }, 5 * 60000)
+
+ return () => clearInterval(interval)
+ }, [dateRange.from, dateRange.to])
+
return (
<>
<div className="space-y-4 flex flex-col pb-8">
diff --git a/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx b/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx
index 48a13aaa48c..92d8a0f2217 100644
--- a/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx
+++ b/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx
@@ -47,42 +47,42 @@ const AccountLayout = ({ children, title }: PropsWithChildren<AccountLayoutProps
}
}, [router])
- if (!newLayoutPreview) {
- return children
- }
-
return (
<>
<Head>
<title>{title ? `${title} | Supabase` : 'Supabase'}</title>
<meta name="description" content="Supabase Studio" />
</Head>
- <div className="flex flex-col h-screen w-screen">
- <ScaffoldContainerLegacy>
- <Link
- href={appSnap.lastRouteBeforeVisitingAccountPage ?? '/'}
- className="flex text-xs flex-row gap-2 items-center text-foreground-lighter focus-visible:text-foreground hover:text-foreground"
- >
- <ArrowLeft strokeWidth={1.5} size={14} />
- Back to dashboard
- </Link>
- <ScaffoldTitle>Account settings</ScaffoldTitle>
- </ScaffoldContainerLegacy>
- <div className="border-b">
- <NavMenu
- className={cn(PADDING_CLASSES, MAX_WIDTH_CLASSES, 'border-none')}
- aria-label="Organization menu navigation"
- >
- {accountLinks.map((item, i) => (
- <NavMenuItem
- key={`${item.key}-${i}`}
- active={(item.key === currentPath || item.keys?.includes(currentPath)) ?? false}
+ <div className={cn(newLayoutPreview ? 'flex flex-col h-screen w-screen' : '')}>
+ {newLayoutPreview && (
+ <>
+ <ScaffoldContainerLegacy>
+ <Link
+ href={appSnap.lastRouteBeforeVisitingAccountPage ?? '/'}
+ className="flex text-xs flex-row gap-2 items-center text-foreground-lighter focus-visible:text-foreground hover:text-foreground"
+ >
+ <ArrowLeft strokeWidth={1.5} size={14} />
+ Back to dashboard
+ </Link>
+ <ScaffoldTitle>Account settings</ScaffoldTitle>
+ </ScaffoldContainerLegacy>
+ <div className="border-b">
+ <NavMenu
+ className={cn(PADDING_CLASSES, MAX_WIDTH_CLASSES, 'border-none')}
+ aria-label="Organization menu navigation"
>
- <Link href={item.href}>{item.label}</Link>
- </NavMenuItem>
- ))}
- </NavMenu>
- </div>
+ {accountLinks.map((item, i) => (
+ <NavMenuItem
+ key={`${item.key}-${i}`}
+ active={(item.key === currentPath || item.keys?.includes(currentPath)) ?? false}
+ >
+ <Link href={item.href}>{item.label}</Link>
+ </NavMenuItem>
+ ))}
+ </NavMenu>
+ </div>
+ </>
+ )}
{children}
</div>
</>
diff --git a/apps/studio/components/layouts/OrganizationLayout.tsx b/apps/studio/components/layouts/OrganizationLayout.tsx
index 2dda649425c..af5290ef6f9 100644
--- a/apps/studio/components/layouts/OrganizationLayout.tsx
+++ b/apps/studio/components/layouts/OrganizationLayout.tsx
@@ -1,6 +1,6 @@
import { ExternalLink } from 'lucide-react'
import { useRouter } from 'next/router'
-import type { PropsWithChildren } from 'react'
+import { Fragment, type PropsWithChildren } from 'react'
import { useNewLayout } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import PartnerIcon from 'components/ui/PartnerIcon'
@@ -15,19 +15,12 @@ import { SidebarSection } from './AccountLayout/AccountLayout.types'
import WithSidebar from './AccountLayout/WithSidebar'
import LayoutHeader from './ProjectLayout/LayoutHeader/LayoutHeader'
-const OrganizationLayout = ({ children }: PropsWithChildren<{}>) => {
- const newLayoutPreview = useNewLayout()
-
+const OrganizationLayoutContent = ({ children }: PropsWithChildren<{}>) => {
const selectedOrganization = useSelectedOrganization()
- const { data: organizations } = useOrganizationsQuery()
-
- const router = useRouter()
-
const { data, isSuccess } = useVercelRedirectQuery({
installationId: selectedOrganization?.partner_id,
})
-
- const Content = () => (
+ return (
<div className={cn('w-full flex flex-col overflow-hidden')}>
{selectedOrganization && selectedOrganization?.managed_by !== 'supabase' && (
<Alert_Shadcn_
@@ -48,110 +41,115 @@ const OrganizationLayout = ({ children }: PropsWithChildren<{}>) => {
<main className="h-full w-full overflow-y-auto">{children}</main>
</div>
)
+}
- if (!newLayoutPreview) {
- const organizationsLinks = (organizations ?? [])
+const OrganizationLayout = ({ children }: PropsWithChildren<{}>) => {
+ const router = useRouter()
+ const newLayoutPreview = useNewLayout()
- .map((organization) => ({
- isActive:
- router.pathname.startsWith('/org/') && selectedOrganization?.slug === organization.slug,
- label: organization.name,
- href: `/org/${organization.slug}/general`,
- key: organization.slug,
- icon: <PartnerIcon organization={organization} />,
- }))
- .sort((a, b) => a.label.localeCompare(b.label))
+ const selectedOrganization = useSelectedOrganization()
+ const { data: organizations } = useOrganizationsQuery()
- const sectionsWithHeaders: SidebarSection[] = [
- {
- heading: 'Projects',
- key: 'projects',
- links: [
- {
- isActive: router.pathname === '/projects',
- label: 'All projects',
- href: '/projects',
- key: 'all-projects-item',
- },
- ],
- },
- ...(IS_PLATFORM && organizationsLinks?.length > 0
- ? [
- {
- heading: 'Organizations',
- key: 'organizations',
- links: organizationsLinks,
- },
- ]
- : []),
- ...(IS_PLATFORM
- ? [
- {
- heading: 'Account',
- key: 'account',
- links: [
- {
- isActive: router.pathname === `/account/me`,
- label: 'Preferences',
- href: `/account/me`,
- key: `/account/me`,
- },
- {
- isActive: router.pathname === `/account/tokens`,
- label: 'Access Tokens',
- href: `/account/tokens`,
- key: `/account/tokens`,
- },
+ const organizationsLinks = (organizations ?? [])
+ .map((organization) => ({
+ isActive:
+ router.pathname.startsWith('/org/') && selectedOrganization?.slug === organization.slug,
+ label: organization.name,
+ href: `/org/${organization.slug}/general`,
+ key: organization.slug,
+ icon: <PartnerIcon organization={organization} />,
+ }))
+ .sort((a, b) => a.label.localeCompare(b.label))
- {
- isActive: router.pathname === `/account/security`,
- label: 'Security',
- href: `/account/security`,
- key: `/account/security`,
- },
- {
- isActive: router.pathname === `/account/audit`,
- label: 'Audit Logs',
- href: `/account/audit`,
- key: `/account/audit`,
- },
- ],
- },
- ]
- : []),
- {
- heading: 'Documentation',
- key: 'documentation',
- links: [
+ const sectionsWithHeaders: SidebarSection[] = [
+ {
+ heading: 'Projects',
+ key: 'projects',
+ links: [
+ {
+ isActive: router.pathname === '/projects',
+ label: 'All projects',
+ href: '/projects',
+ key: 'all-projects-item',
+ },
+ ],
+ },
+ ...(IS_PLATFORM && organizationsLinks?.length > 0
+ ? [
{
- key: 'ext-guides',
- label: 'Guides',
- href: 'https://supabase.com/docs',
- isExternal: true,
+ heading: 'Organizations',
+ key: 'organizations',
+ links: organizationsLinks,
},
+ ]
+ : []),
+ ...(IS_PLATFORM
+ ? [
{
- key: 'ext-guides',
- label: 'API Reference',
- href: 'https://supabase.com/docs/guides/api',
- isExternal: true,
+ heading: 'Account',
+ key: 'account',
+ links: [
+ {
+ isActive: router.pathname === `/account/me`,
+ label: 'Preferences',
+ href: `/account/me`,
+ key: `/account/me`,
+ },
+ {
+ isActive: router.pathname === `/account/tokens`,
+ label: 'Access Tokens',
+ href: `/account/tokens`,
+ key: `/account/tokens`,
+ },
+
+ {
+ isActive: router.pathname === `/account/security`,
+ label: 'Security',
+ href: `/account/security`,
+ key: `/account/security`,
+ },
+ {
+ isActive: router.pathname === `/account/audit`,
+ label: 'Audit Logs',
+ href: `/account/audit`,
+ key: `/account/audit`,
+ },
+ ],
},
- ],
- },
- ]
+ ]
+ : []),
+ {
+ heading: 'Documentation',
+ key: 'documentation',
+ links: [
+ {
+ key: 'ext-guides',
+ label: 'Guides',
+ href: 'https://supabase.com/docs',
+ isExternal: true,
+ },
+ {
+ key: 'ext-guides',
+ label: 'API Reference',
+ href: 'https://supabase.com/docs/guides/api',
+ isExternal: true,
+ },
+ ],
+ },
+ ]
- return (
- <WithSidebar
- title={selectedOrganization?.name ?? 'Supabase'}
- breadcrumbs={[{ key: `org-settings`, label: 'Settings' }]}
- sections={sectionsWithHeaders}
- >
- {!newLayoutPreview && <LayoutHeader />}
- <Content />
- </WithSidebar>
- )
- } else {
- return <Content />
- }
+ const OrganizationLayoutContentWrapper = !newLayoutPreview ? WithSidebar : Fragment
+
+ return (
+ <OrganizationLayoutContentWrapper
+ title={selectedOrganization?.name ?? 'Supabase'}
+ breadcrumbs={[{ key: `org-settings`, label: 'Settings' }]}
+ sections={sectionsWithHeaders}
+ >
+ {!newLayoutPreview && <LayoutHeader />}
+ <OrganizationLayoutContent>{children}</OrganizationLayoutContent>
+ </OrganizationLayoutContentWrapper>
+ )
}
export default withAuth(OrganizationLayout)
diff --git a/apps/studio/data/profile/profile-audit-logs-query.ts b/apps/studio/data/profile/profile-audit-logs-query.ts
index daf17be0ed8..241933fe195 100644
--- a/apps/studio/data/profile/profile-audit-logs-query.ts
+++ b/apps/studio/data/profile/profile-audit-logs-query.ts
@@ -2,6 +2,7 @@ import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import type { AuditLog } from 'data/organizations/organization-audit-logs-query'
+import { IS_PLATFORM } from 'lib/constants'
import type { ResponseError } from 'types'
import { profileKeys } from './keys'
@@ -43,6 +44,7 @@ export const useProfileAuditLogsQuery = <TData = ProfileAuditLogsData>(
profileKeys.auditLogs({ date_start: iso_timestamp_start, date_end: iso_timestamp_end }),
({ signal }) => getProfileAuditLogs(vars, signal),
{
+ enabled: IS_PLATFORM && options.enabled,
...options,
}
)
diff --git a/apps/studio/pages/account/audit.tsx b/apps/studio/pages/account/audit.tsx
index 0a97eb8a3b4..0a95edfefa0 100644
--- a/apps/studio/pages/account/audit.tsx
+++ b/apps/studio/pages/account/audit.tsx
@@ -6,32 +6,26 @@ import DefaultLayout from 'components/layouts/DefaultLayout'
import OrganizationLayout from 'components/layouts/OrganizationLayout'
import {
ScaffoldContainer,
- ScaffoldContainerLegacy,
ScaffoldDescription,
ScaffoldHeader,
ScaffoldTitle,
} from 'components/layouts/Scaffold'
import type { NextPageWithLayout } from 'types'
+import { cn } from 'ui'
const Audit: NextPageWithLayout = () => {
const newLayoutPreview = useNewLayout()
- if (newLayoutPreview) {
- return (
- <ScaffoldContainerLegacy className="gap-0">
- <AuditLogs />
- </ScaffoldContainerLegacy>
- )
- }
-
return (
- <ScaffoldContainer>
- <ScaffoldHeader>
- <ScaffoldTitle>Account Audit Logs</ScaffoldTitle>
- <ScaffoldDescription>
- View the audit log trail of actions made from your account
- </ScaffoldDescription>
- </ScaffoldHeader>
+ <ScaffoldContainer className={cn(newLayoutPreview ? '[&>div]:mt-8' : '')}>
+ {!newLayoutPreview && (
+ <ScaffoldHeader>
+ <ScaffoldTitle>Account Audit Logs</ScaffoldTitle>
+ <ScaffoldDescription>
+ View the audit log trail of actions made from your account
+ </ScaffoldDescription>
+ </ScaffoldHeader>
+ )}
<AuditLogs />
</ScaffoldContainer>
)