Skip to content

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

remove effect for logs redirection (#37898)

Jordi Enricc03dcc1eadb9
diff --git a/apps/studio/components/interfaces/Sidebar.tsx b/apps/studio/components/interfaces/Sidebar.tsx
index 0727be8436c..2f6c7ca7c01 100644
--- a/apps/studio/components/interfaces/Sidebar.tsx
+++ b/apps/studio/components/interfaces/Sidebar.tsx
@@ -41,7 +41,10 @@ import {
Sidebar as SidebarPrimitive,
useSidebar,
} from 'ui'
-import { useIsAPIDocsSidePanelEnabled } from './App/FeaturePreview/FeaturePreviewContext'
+import {
+ useIsAPIDocsSidePanelEnabled,
+ useUnifiedLogsPreview,
+} from './App/FeaturePreview/FeaturePreviewContext'
export const ICON_SIZE = 32
export const ICON_STROKE_WIDTH = 1.5
@@ -243,7 +246,12 @@ const ProjectLinks = () => {
storage: storageEnabled,
realtime: realtimeEnabled,
})
- const otherRoutes = generateOtherRoutes(ref, project)
+
+ const { isEnabled: isUnifiedLogsEnabled } = useUnifiedLogsPreview()
+
+ const otherRoutes = generateOtherRoutes(ref, project, {
+ unifiedLogs: isUnifiedLogsEnabled,
+ })
const settingsRoutes = generateSettingsRoutes(ref, project)
return (
diff --git a/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx b/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
index 2edee7ba163..30c4ae8bbf4 100644
--- a/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
+++ b/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
@@ -1,11 +1,9 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useRouter } from 'next/router'
-import { PropsWithChildren, useEffect } from 'react'
-import { LOCAL_STORAGE_KEYS } from 'common'
+import { PropsWithChildren } from 'react'
+
import NoPermission from 'components/ui/NoPermission'
import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
-import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { withAuth } from 'hooks/misc/withAuth'
import ProjectLayout from '../ProjectLayout/ProjectLayout'
import { LogsSidebarMenuV2 } from './LogsSidebarMenuV2'
@@ -20,21 +18,6 @@ const LogsLayout = ({ title, children }: PropsWithChildren<LogsLayoutProps>) =>
'logflare'
)
- const router = useRouter()
- const [_, setLastLogsPage] = useLocalStorageQuery(
- LOCAL_STORAGE_KEYS.LAST_VISITED_LOGS_PAGE,
- router.pathname.split('/logs/')[1] || ''
- )
-
- useEffect(() => {
- if (router.pathname.includes('/logs/')) {
- const path = router.pathname.split('/logs/')[1]
- if (path) {
- setLastLogsPage(path)
- }
- }
- }, [router, setLastLogsPage])
-
if (!canUseLogsExplorer) {
if (isLoading) {
return <ProjectLayout isLoading></ProjectLayout>
diff --git a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx
index 48faa8be673..503d3c8d973 100644
--- a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx
@@ -116,10 +116,16 @@ export const generateProductRoutes = (
]
}
-export const generateOtherRoutes = (ref?: string, project?: Project, features?: {}): Route[] => {
+export const generateOtherRoutes = (
+ ref?: string,
+ project?: Project,
+ features?: { unifiedLogs?: boolean }
+): Route[] => {
const isProjectBuilding = project?.status === PROJECT_STATUS.COMING_UP
const buildingUrl = `/project/${ref}`
+ const unifiedLogsEnabled = features?.unifiedLogs ?? false
+
return [
{
key: 'advisors',
@@ -141,7 +147,13 @@ export const generateOtherRoutes = (ref?: string, project?: Project, features?:
key: 'logs',
label: 'Logs',
icon: <List size={ICON_SIZE} strokeWidth={ICON_STROKE_WIDTH} />,
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/logs`),
+ link:
+ ref &&
+ (isProjectBuilding
+ ? buildingUrl
+ : unifiedLogsEnabled
+ ? `/project/${ref}/logs`
+ : `/project/${ref}/logs/explorer`),
},
{
key: 'api',
diff --git a/apps/studio/pages/project/[ref]/logs/index.tsx b/apps/studio/pages/project/[ref]/logs/index.tsx
index 16e56270226..2c04272a4c1 100644
--- a/apps/studio/pages/project/[ref]/logs/index.tsx
+++ b/apps/studio/pages/project/[ref]/logs/index.tsx
@@ -1,54 +1,25 @@
import { useRouter } from 'next/router'
-import { useContext, useEffect } from 'react'
+import { useEffect } from 'react'
-import { FeatureFlagContext, LOCAL_STORAGE_KEYS, useParams } from 'common'
+import { useParams } from 'common'
import { useUnifiedLogsPreview } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { UnifiedLogs } from 'components/interfaces/UnifiedLogs/UnifiedLogs'
import DefaultLayout from 'components/layouts/DefaultLayout'
-import LogsLayout from 'components/layouts/LogsLayout/LogsLayout'
import ProjectLayout from 'components/layouts/ProjectLayout/ProjectLayout'
-import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
-import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
-import { IS_PLATFORM } from 'lib/constants'
-import type { NextPageWithLayout } from 'types'
+import { NextPageWithLayout } from 'types'
export const LogPage: NextPageWithLayout = () => {
const router = useRouter()
const { ref } = useParams()
- const { hasLoaded } = useContext(FeatureFlagContext)
- const { data: org } = useSelectedOrganizationQuery()
const { isEnabled: isUnifiedLogsEnabled } = useUnifiedLogsPreview()
- const [lastVisitedLogsPage] = useLocalStorageQuery(
- LOCAL_STORAGE_KEYS.LAST_VISITED_LOGS_PAGE,
- 'explorer'
- )
-
useEffect(() => {
- if (hasLoaded && !!org && !isUnifiedLogsEnabled) {
- router.replace(`/project/${ref}/logs/${lastVisitedLogsPage}`)
- }
- }, [router, hasLoaded, org, lastVisitedLogsPage, ref, isUnifiedLogsEnabled])
-
- // Handle redirects when unified logs preview flag changes
- useEffect(() => {
- // Only handle redirects if we're currently on a logs page
- if (!router.asPath.includes('/logs') || (IS_PLATFORM && !hasLoaded)) return
-
- if (IS_PLATFORM && isUnifiedLogsEnabled) {
- // If unified logs preview is enabled and we're not already on the main logs page
- if (router.asPath !== `/project/${ref}/logs` && router.asPath.includes('/logs/')) {
- router.push(`/project/${ref}/logs`)
- }
- } else {
- // If unified logs preview is disabled and admin flag is also off
- // and we're on the main logs page, redirect to explorer
- if (router.asPath === `/project/${ref}/logs`) {
- router.push(`/project/${ref}/logs/explorer`)
- }
+ if (!isUnifiedLogsEnabled && ref) {
+ router.replace(`/project/${ref}/logs/explorer`)
}
- }, [isUnifiedLogsEnabled, router, ref, hasLoaded])
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [isUnifiedLogsEnabled, ref])
if (isUnifiedLogsEnabled) {
return (
@@ -60,14 +31,7 @@ export const LogPage: NextPageWithLayout = () => {
)
}
- return (
- <DefaultLayout>
- <LogsLayout>
- {/* Empty placeholder - the useEffect will handle redirect */}
- <div></div>
- </LogsLayout>
- </DefaultLayout>
- )
+ return null
}
// Don't use getLayout since we're handling layouts conditionally within the component
diff --git a/packages/common/constants/local-storage.ts b/packages/common/constants/local-storage.ts
index 449ea259bb9..db05c8dd204 100644
--- a/packages/common/constants/local-storage.ts
+++ b/packages/common/constants/local-storage.ts
@@ -62,8 +62,6 @@ export const LOCAL_STORAGE_KEYS = {
// api keys view switcher for new and legacy api keys
API_KEYS_VIEW: (ref: string) => `supabase-api-keys-view-${ref}`,
- // last visited logs page
- LAST_VISITED_LOGS_PAGE: 'supabase-last-visited-logs-page',
LAST_VISITED_ORGANIZATION: 'last-visited-organization',
// user impersonation selector previous searches