LogsLayout.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { PermissionAction } from '@supabase/shared-types/out/constants'
  2. import { useParams } from 'common'
  3. import { PropsWithChildren } from 'react'
  4. import { ProjectLayout } from '../ProjectLayout'
  5. import { LogsSidebarMenuV2 } from './LogsSidebarMenuV2'
  6. import NoPermission from '@/components/ui/NoPermission'
  7. import { UnknownInterface } from '@/components/ui/UnknownInterface'
  8. import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
  9. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  10. import { withAuth } from '@/hooks/misc/withAuth'
  11. interface LogsLayoutProps {
  12. title: string
  13. }
  14. const LogsLayout = ({ title, children }: PropsWithChildren<LogsLayoutProps>) => {
  15. const { ref } = useParams()
  16. const logsEnabled = useIsFeatureEnabled('logs:all')
  17. const { isLoading, can: canUseLogsExplorer } = useAsyncCheckPermissions(
  18. PermissionAction.ANALYTICS_READ,
  19. 'logflare'
  20. )
  21. if (!logsEnabled) {
  22. return (
  23. <ProjectLayout product="logs" browserTitle={{ section: title }}>
  24. <UnknownInterface urlBack={`/project/${ref}`} />
  25. </ProjectLayout>
  26. )
  27. }
  28. if (!canUseLogsExplorer) {
  29. if (isLoading) {
  30. return (
  31. <ProjectLayout isLoading product="logs" browserTitle={{ section: title }} />
  32. )
  33. }
  34. if (!isLoading && !canUseLogsExplorer) {
  35. return (
  36. <ProjectLayout product="logs" browserTitle={{ section: title }}>
  37. <NoPermission isFullPage resourceText="access your project's logs" />
  38. </ProjectLayout>
  39. )
  40. }
  41. }
  42. return (
  43. <ProjectLayout
  44. product="logs"
  45. browserTitle={{ section: title }}
  46. productMenu={<LogsSidebarMenuV2 />}
  47. >
  48. {children}
  49. </ProjectLayout>
  50. )
  51. }
  52. export default withAuth(LogsLayout)