Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/studio/components/interfaces/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
21 changes: 2 additions & 19 deletions apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
52 changes: 8 additions & 44 deletions apps/studio/pages/project/[ref]/logs/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions packages/common/constants/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading