index.tsx54 lines · main
1import { useParams } from 'common'
2import { useRouter } from 'next/router'
3import { useEffect } from 'react'
4
5import { useUnifiedLogsPreview } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
6import { UnifiedLogs } from '@/components/interfaces/UnifiedLogs/UnifiedLogs'
7import DefaultLayout from '@/components/layouts/DefaultLayout'
8import { ProjectLayout } from '@/components/layouts/ProjectLayout'
9import { UnknownInterface } from '@/components/ui/UnknownInterface'
10import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
11import type { NextPageWithLayout } from '@/types'
12
13export const LogPage: NextPageWithLayout = () => {
14 const router = useRouter()
15 const { ref } = useParams()
16
17 const logsEnabled = useIsFeatureEnabled('logs:all')
18 const { isEnabled: isUnifiedLogsEnabled, isLoading } = useUnifiedLogsPreview()
19
20 useEffect(() => {
21 if (logsEnabled && !isLoading && !isUnifiedLogsEnabled && ref) {
22 router.replace(`/project/${ref}/logs/explorer`)
23 }
24 // eslint-disable-next-line react-hooks/exhaustive-deps
25 }, [logsEnabled, isLoading, isUnifiedLogsEnabled, ref])
26
27 if (!logsEnabled) {
28 return (
29 <DefaultLayout>
30 <ProjectLayout browserTitle={{ section: 'logs' }}>
31 <UnknownInterface urlBack={`/project/${ref}`} />
32 </ProjectLayout>
33 </DefaultLayout>
34 )
35 }
36
37 if (isUnifiedLogsEnabled) {
38 return (
39 <DefaultLayout>
40 {/* Omit the generic product segment here; project/org context already makes the route clear. */}
41 <ProjectLayout browserTitle={{ section: 'unified logs' }}>
42 <UnifiedLogs />
43 </ProjectLayout>
44 </DefaultLayout>
45 )
46 }
47
48 return null
49}
50
51// Don't use getLayout since we're handling layouts conditionally within the component
52LogPage.getLayout = (page) => page
53
54export default LogPage