index.tsx54 lines · main
| 1 | import { useParams } from 'common' |
| 2 | import { useRouter } from 'next/router' |
| 3 | import { useEffect } from 'react' |
| 4 | |
| 5 | import { useUnifiedLogsPreview } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext' |
| 6 | import { UnifiedLogs } from '@/components/interfaces/UnifiedLogs/UnifiedLogs' |
| 7 | import DefaultLayout from '@/components/layouts/DefaultLayout' |
| 8 | import { ProjectLayout } from '@/components/layouts/ProjectLayout' |
| 9 | import { UnknownInterface } from '@/components/ui/UnknownInterface' |
| 10 | import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' |
| 11 | import type { NextPageWithLayout } from '@/types' |
| 12 | |
| 13 | export 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 |
| 52 | LogPage.getLayout = (page) => page |
| 53 | |
| 54 | export default LogPage |