DocsLayout.utils.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { ArrowUpRight, Book, BookOpen } from 'lucide-react'
  2. import SVG from 'react-inlinesvg'
  3. import type { ProductMenuGroup } from '@/components/ui/ProductMenu/ProductMenu.types'
  4. import { BASE_PATH, DOCS_URL } from '@/lib/constants'
  5. export const getActivePage = (params: {
  6. page?: string
  7. resource?: string
  8. rpc?: string
  9. }): string => {
  10. const { page, resource, rpc } = params
  11. if (!page && !resource && !rpc) return 'introduction'
  12. return (page || rpc || resource) as string
  13. }
  14. export const generateDocsMenu = (
  15. ref: string,
  16. tables: Array<string>,
  17. functions: Array<string>,
  18. flags?: { authEnabled: boolean },
  19. basePath?: string
  20. ): Array<ProductMenuGroup> => {
  21. const docsBasePath = basePath ?? `/project/${ref}/integrations/data_api/docs`
  22. return [
  23. {
  24. title: 'Getting Started',
  25. items: [
  26. { name: 'Introduction', key: 'introduction', url: docsBasePath, items: [] },
  27. {
  28. name: 'Authentication',
  29. key: 'auth',
  30. url: `${docsBasePath}?page=auth`,
  31. items: [],
  32. },
  33. ...(flags?.authEnabled
  34. ? [
  35. {
  36. name: 'User Management',
  37. key: 'users-management',
  38. url: `${docsBasePath}?page=users-management`,
  39. items: [],
  40. },
  41. ]
  42. : []),
  43. ],
  44. },
  45. {
  46. title: 'Tables and Views',
  47. items: [
  48. {
  49. name: 'Introduction',
  50. key: 'tables-intro',
  51. url: `${docsBasePath}?page=tables-intro`,
  52. items: [],
  53. },
  54. ...tables.sort().map((table) => {
  55. return {
  56. name: table,
  57. key: table,
  58. url: `${docsBasePath}?resource=${table}`,
  59. items: [],
  60. }
  61. }),
  62. ],
  63. },
  64. {
  65. title: 'Functions',
  66. items: [
  67. {
  68. name: 'Introduction',
  69. key: 'rpc-intro',
  70. url: `${docsBasePath}?page=rpc-intro`,
  71. items: [],
  72. },
  73. ...functions.map((fn) => {
  74. return { name: fn, key: fn, url: `${docsBasePath}?rpc=${fn}`, items: [] }
  75. }),
  76. ],
  77. },
  78. {
  79. title: 'GraphQL',
  80. items: [
  81. {
  82. name: 'GraphiQL',
  83. key: 'graphiql',
  84. url: `/project/${ref}/integrations/graphiql`,
  85. icon: (
  86. <SVG
  87. src={`${BASE_PATH}/img/graphql.svg`}
  88. style={{ width: `${16}px`, height: `${16}px` }}
  89. className="text-foreground"
  90. preProcessor={(code) => code.replace(/svg/, 'svg class="m-auto text-color-inherit"')}
  91. />
  92. ),
  93. items: [],
  94. rightIcon: <ArrowUpRight strokeWidth={1} className="h-4 w-4" />,
  95. },
  96. ],
  97. },
  98. {
  99. title: 'More Resources',
  100. items: [
  101. {
  102. name: 'Guides',
  103. key: 'guides',
  104. url: DOCS_URL,
  105. icon: <Book size={14} strokeWidth={2} />,
  106. items: [],
  107. isExternal: true,
  108. },
  109. {
  110. name: 'API Reference',
  111. key: 'api-reference',
  112. url: `${DOCS_URL}/guides/api`,
  113. icon: <BookOpen size={14} strokeWidth={2} />,
  114. items: [],
  115. isExternal: true,
  116. },
  117. ],
  118. },
  119. ]
  120. }