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