EdgeFunctionsLayout.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { useParams } from 'common'
  2. import { useRouter } from 'next/router'
  3. import { useMemo, type ComponentProps, type PropsWithChildren } from 'react'
  4. import { ProjectLayout } from '../ProjectLayout'
  5. import { ProductMenu } from '@/components/ui/ProductMenu'
  6. import type { ProductMenuGroup } from '@/components/ui/ProductMenu/ProductMenu.types'
  7. import { ProductMenuShortcuts } from '@/components/ui/ProductMenu/ProductMenuShortcuts'
  8. import { withAuth } from '@/hooks/misc/withAuth'
  9. import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
  10. const useGenerateEdgeFunctionsMenu = (): ProductMenuGroup[] => {
  11. const { ref: projectRef = 'default' } = useParams()
  12. return useMemo(
  13. () => [
  14. {
  15. title: 'Manage',
  16. items: [
  17. {
  18. name: 'Functions',
  19. key: 'main',
  20. pages: ['', '[functionSlug]', 'new'],
  21. url: `/project/${projectRef}/functions`,
  22. items: [],
  23. shortcutId: SHORTCUT_IDS.NAV_FUNCTIONS_OVERVIEW,
  24. },
  25. {
  26. name: 'Secrets',
  27. key: 'secrets',
  28. url: `/project/${projectRef}/functions/secrets`,
  29. items: [],
  30. shortcutId: SHORTCUT_IDS.NAV_FUNCTIONS_SECRETS,
  31. },
  32. ],
  33. },
  34. ],
  35. [projectRef]
  36. )
  37. }
  38. export const EdgeFunctionsProductMenu = () => {
  39. const router = useRouter()
  40. const page = router.pathname.split('/')[4]
  41. const menu = useGenerateEdgeFunctionsMenu()
  42. return <ProductMenu page={page} menu={menu} />
  43. }
  44. interface EdgeFunctionsLayoutProps {
  45. title: string
  46. browserTitle?: ComponentProps<typeof ProjectLayout>['browserTitle']
  47. }
  48. const EdgeFunctionsLayout = ({
  49. children,
  50. title,
  51. browserTitle,
  52. }: PropsWithChildren<EdgeFunctionsLayoutProps>) => {
  53. const menu = useGenerateEdgeFunctionsMenu()
  54. return (
  55. <ProjectLayout
  56. product="Edge Functions"
  57. browserTitle={{ ...browserTitle, section: title }}
  58. productMenu={<EdgeFunctionsProductMenu />}
  59. isBlocking={false}
  60. >
  61. <ProductMenuShortcuts menu={menu} />
  62. {children}
  63. </ProjectLayout>
  64. )
  65. }
  66. export default withAuth(EdgeFunctionsLayout)