Database.Commands.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import { useParams } from 'common'
  2. import { Blocks, Code, Database, History, Search } from 'lucide-react'
  3. import type { CommandOptions } from 'ui-patterns/CommandMenu'
  4. import { useRegisterCommands } from 'ui-patterns/CommandMenu'
  5. import { IRouteCommand } from 'ui-patterns/CommandMenu/internal/types'
  6. import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'
  7. import { orderCommandSectionsByPriority } from '@/components/interfaces/App/CommandMenu/ordering'
  8. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  9. export function useDatabaseGotoCommands(options?: CommandOptions) {
  10. let { ref } = useParams()
  11. ref ||= '_'
  12. const { databaseReplication, databaseRoles, integrationsWrappers } = useIsFeatureEnabled([
  13. 'database:replication',
  14. 'database:roles',
  15. 'integrations:wrappers',
  16. ])
  17. useRegisterCommands(
  18. COMMAND_MENU_SECTIONS.QUERY,
  19. [
  20. {
  21. id: 'run-sql',
  22. name: 'Run SQL',
  23. route: `/project/${ref}/sql/new`,
  24. icon: () => <Code />,
  25. },
  26. ],
  27. {
  28. ...options,
  29. deps: [ref],
  30. orderSection: orderCommandSectionsByPriority,
  31. sectionMeta: { priority: 2 },
  32. }
  33. )
  34. useRegisterCommands(
  35. COMMAND_MENU_SECTIONS.NAVIGATE,
  36. [
  37. {
  38. id: 'nav-database-tables',
  39. name: 'Tables',
  40. value: 'Database: Tables',
  41. route: `/project/${ref}/database/tables`,
  42. defaultHidden: true,
  43. },
  44. {
  45. id: 'nav-database-triggers',
  46. name: 'Triggers',
  47. value: 'Database: Triggers',
  48. route: `/project/${ref}/database/triggers`,
  49. defaultHidden: true,
  50. },
  51. {
  52. id: 'nav-database-functions',
  53. name: 'Functions',
  54. value: 'Database: Functions',
  55. route: `/project/${ref}/database/functions`,
  56. defaultHidden: true,
  57. },
  58. {
  59. id: 'nav-database-extensions',
  60. name: 'Extensions',
  61. value: 'Database: Extensions',
  62. route: `/project/${ref}/database/extensions`,
  63. defaultHidden: true,
  64. },
  65. ...(databaseRoles
  66. ? [
  67. {
  68. id: 'nav-database-roles',
  69. name: 'Roles',
  70. value: 'Database: Roles',
  71. route: `/project/${ref}/database/roles`,
  72. defaultHidden: true,
  73. } as IRouteCommand,
  74. ]
  75. : []),
  76. ...(databaseReplication
  77. ? [
  78. {
  79. id: 'nav-database-replication',
  80. name: 'Replication',
  81. value: 'Database: Replication',
  82. route: `/project/${ref}/database/replication`,
  83. defaultHidden: true,
  84. } as IRouteCommand,
  85. ]
  86. : []),
  87. {
  88. id: 'nav-database-backups',
  89. name: 'Backups',
  90. value: 'Database: Backups',
  91. route: `/project/${ref}/database/backups/scheduled`,
  92. defaultHidden: true,
  93. },
  94. ...(integrationsWrappers
  95. ? [
  96. {
  97. id: 'nav-database-wrappers',
  98. name: 'Wrappers',
  99. value: 'Database: Wrappers',
  100. route: `/project/${ref}/integrations?category=wrappers`,
  101. defaultHidden: true,
  102. } as IRouteCommand,
  103. ]
  104. : []),
  105. {
  106. id: 'nav-database-migrations',
  107. name: 'Migrations',
  108. value: 'Database: Migrations',
  109. route: `/project/${ref}/database/migrations`,
  110. defaultHidden: true,
  111. },
  112. ],
  113. { ...options, deps: [ref] }
  114. )
  115. useRegisterCommands(
  116. COMMAND_MENU_SECTIONS.DATABASE,
  117. [
  118. {
  119. id: 'run-schema-visualizer',
  120. name: 'View your schemas',
  121. route: `/project/${ref}/database/schemas`,
  122. icon: () => <Search />,
  123. },
  124. {
  125. id: 'run-view-database-functions',
  126. name: 'View and create functions',
  127. route: `/project/${ref}/database/functions`,
  128. icon: () => <Database />,
  129. },
  130. {
  131. id: 'run-view-database-triggers',
  132. name: 'View and create triggers',
  133. route: `/project/${ref}/database/triggers`,
  134. icon: () => <Database />,
  135. },
  136. {
  137. id: 'run-view-database-enumerated-types',
  138. name: 'View and create enumerated types',
  139. route: `/project/${ref}/database/types`,
  140. icon: () => <Database />,
  141. },
  142. {
  143. id: 'run-view-database-extensions',
  144. name: 'View your extensions',
  145. route: `/project/${ref}/database/extensions`,
  146. icon: () => <Blocks />,
  147. },
  148. {
  149. id: 'run-view-database-indexes',
  150. name: 'View and create indexes',
  151. route: `/project/${ref}/database/indexes`,
  152. icon: () => <Database />,
  153. },
  154. ...(databaseRoles
  155. ? [
  156. {
  157. id: 'run-view-database-roles',
  158. name: 'View your roles',
  159. route: `/project/${ref}/database/roles`,
  160. icon: () => <Database />,
  161. } as IRouteCommand,
  162. ]
  163. : []),
  164. {
  165. id: 'run-view-database-backups',
  166. name: 'View your backups',
  167. route: `/project/${ref}/database/backups/scheduled`,
  168. icon: () => <Database />,
  169. },
  170. {
  171. id: 'run-view-database-migrations',
  172. name: 'View your migrations',
  173. route: `/project/${ref}/database/migrations`,
  174. icon: () => <History />,
  175. },
  176. ],
  177. {
  178. ...options,
  179. deps: [ref],
  180. orderSection: orderCommandSectionsByPriority,
  181. sectionMeta: { priority: 3 },
  182. }
  183. )
  184. }