ProjectSettings.Commands.tsx182 lines · main
| 1 | import { useParams } from 'common' |
| 2 | import { useRouter } from 'next/router' |
| 3 | import type { CommandOptions, ICommand } from 'ui-patterns/CommandMenu' |
| 4 | import { useRegisterCommands, useSetCommandMenuOpen } 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 { useIsPlatformWebhooksEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext' |
| 9 | import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' |
| 10 | |
| 11 | export function useProjectSettingsGotoCommands(options?: CommandOptions) { |
| 12 | const router = useRouter() |
| 13 | const setIsOpen = useSetCommandMenuOpen() |
| 14 | let { ref, slug } = useParams() |
| 15 | const platformWebhooksEnabled = useIsPlatformWebhooksEnabled() |
| 16 | ref ||= '_' |
| 17 | const hasOrgSlug = typeof slug === 'string' && slug.length > 0 && slug !== '_' |
| 18 | |
| 19 | const { projectSettingsLogDrains, projectSettingsCustomDomains, authenticationSignInProviders } = |
| 20 | useIsFeatureEnabled([ |
| 21 | 'project_settings:log_drains', |
| 22 | 'project_settings:custom_domains', |
| 23 | 'authentication:sign_in_providers', |
| 24 | ]) |
| 25 | |
| 26 | useRegisterCommands( |
| 27 | COMMAND_MENU_SECTIONS.NAVIGATE, |
| 28 | [ |
| 29 | { |
| 30 | id: 'nav-project-settings-add-ons', |
| 31 | name: 'Add-ons', |
| 32 | value: 'Add-ons addons add ons add on add-on', |
| 33 | route: `/project/${ref}/settings/addons`, |
| 34 | defaultHidden: true, |
| 35 | }, |
| 36 | { |
| 37 | id: 'nav-project-settings-general', |
| 38 | name: 'General Settings', |
| 39 | route: `/project/${ref}/settings/general`, |
| 40 | defaultHidden: true, |
| 41 | }, |
| 42 | { |
| 43 | id: 'nav-project-settings-database', |
| 44 | name: 'Database Settings', |
| 45 | route: `/project/${ref}/database/settings`, |
| 46 | defaultHidden: true, |
| 47 | }, |
| 48 | { |
| 49 | id: 'nav-project-settings-auth', |
| 50 | name: 'Auth Settings', |
| 51 | route: authenticationSignInProviders |
| 52 | ? `/project/${ref}/auth/providers` |
| 53 | : `/project/${ref}/auth/policies`, |
| 54 | defaultHidden: true, |
| 55 | }, |
| 56 | ...(platformWebhooksEnabled |
| 57 | ? [ |
| 58 | { |
| 59 | id: 'nav-project-settings-webhooks', |
| 60 | name: 'Project Webhooks', |
| 61 | route: `/project/${ref}/settings/webhooks`, |
| 62 | defaultHidden: true, |
| 63 | } as IRouteCommand, |
| 64 | ...(hasOrgSlug |
| 65 | ? [ |
| 66 | { |
| 67 | id: 'nav-organization-settings-webhooks', |
| 68 | name: 'Organization Webhooks', |
| 69 | route: `/org/${slug}/webhooks`, |
| 70 | defaultHidden: true, |
| 71 | } as IRouteCommand, |
| 72 | ] |
| 73 | : []), |
| 74 | ] |
| 75 | : []), |
| 76 | { |
| 77 | id: 'nav-project-settings-api', |
| 78 | name: 'API Settings', |
| 79 | route: `/project/${ref}/integrations/data_api/settings`, |
| 80 | defaultHidden: true, |
| 81 | }, |
| 82 | { |
| 83 | id: 'nav-project-settings-storage', |
| 84 | name: 'Storage Settings', |
| 85 | route: `/project/${ref}/storage/settings`, |
| 86 | defaultHidden: true, |
| 87 | }, |
| 88 | ...(projectSettingsCustomDomains |
| 89 | ? [ |
| 90 | { |
| 91 | id: 'nav-project-settings-custom-domains', |
| 92 | name: 'Custom Domains', |
| 93 | route: `/project/${ref}/settings/general#custom-domains`, |
| 94 | defaultHidden: true, |
| 95 | } as IRouteCommand, |
| 96 | ] |
| 97 | : []), |
| 98 | { |
| 99 | id: 'nav-project-settings-restart-project', |
| 100 | name: 'Project availability', |
| 101 | value: 'project availability restart project pause project resume project', |
| 102 | route: `/project/${ref}/settings/general#restart-project`, |
| 103 | defaultHidden: true, |
| 104 | }, |
| 105 | { |
| 106 | id: 'nav-project-settings-pause-project', |
| 107 | name: 'Pause project', |
| 108 | route: `/project/${ref}/settings/general#pause-project`, |
| 109 | defaultHidden: true, |
| 110 | }, |
| 111 | { |
| 112 | id: 'nav-project-settings-transfer-project', |
| 113 | name: 'Transfer project', |
| 114 | route: `/project/${ref}/settings/general#transfer-project`, |
| 115 | defaultHidden: true, |
| 116 | }, |
| 117 | { |
| 118 | id: 'nav-project-settings-delete-project', |
| 119 | name: 'Delete project', |
| 120 | route: `/project/${ref}/settings/general#delete-project`, |
| 121 | defaultHidden: true, |
| 122 | }, |
| 123 | { |
| 124 | id: 'nav-project-settings-database-password', |
| 125 | name: 'Database password', |
| 126 | route: `/project/${ref}/database/settings#database-password`, |
| 127 | defaultHidden: true, |
| 128 | }, |
| 129 | { |
| 130 | id: 'nav-project-settings-connection-string', |
| 131 | name: 'Connection string', |
| 132 | action: () => { |
| 133 | router.push( |
| 134 | { |
| 135 | pathname: router.pathname, |
| 136 | query: { ...router.query, showConnect: 'true' }, |
| 137 | }, |
| 138 | undefined, |
| 139 | { shallow: true } |
| 140 | ) |
| 141 | setIsOpen(false) |
| 142 | }, |
| 143 | defaultHidden: true, |
| 144 | } as ICommand, |
| 145 | { |
| 146 | id: 'nav-project-settings-connection-pooling', |
| 147 | name: 'Connection pooling', |
| 148 | route: `/project/${ref}/database/settings#connection-pooler`, |
| 149 | defaultHidden: true, |
| 150 | }, |
| 151 | { |
| 152 | id: 'nav-project-settings-ssl-configuration', |
| 153 | name: 'SSL configuration', |
| 154 | route: `/project/${ref}/database/settings#ssl-configuration`, |
| 155 | defaultHidden: true, |
| 156 | }, |
| 157 | { |
| 158 | id: 'nav-project-settings-network-restrictions', |
| 159 | name: 'Network restrictions', |
| 160 | route: `/project/${ref}/database/settings#network-restrictions`, |
| 161 | defaultHidden: true, |
| 162 | }, |
| 163 | { |
| 164 | id: 'nav-project-settings-banned-ips', |
| 165 | name: 'Banned IPs', |
| 166 | route: `/project/${ref}/database/settings#banned-ips`, |
| 167 | defaultHidden: true, |
| 168 | }, |
| 169 | ...(projectSettingsLogDrains |
| 170 | ? [ |
| 171 | { |
| 172 | id: 'nav-project-settings-log-drains', |
| 173 | name: 'Log drains', |
| 174 | route: `/project/${ref}/settings/log-drains`, |
| 175 | defaultHidden: true, |
| 176 | } as IRouteCommand, |
| 177 | ] |
| 178 | : []), |
| 179 | ], |
| 180 | { ...options, deps: [platformWebhooksEnabled, ref, slug] } |
| 181 | ) |
| 182 | } |