Files
supabase/apps/studio/components/layouts/ProjectSettingsLayout/ProjectSettings.Commands.tsx
T
Joshen Lim 1de298ff31 Reinstate https://github.com/supabase/supabase/pull/45143 into latest master (#47433)
## Context

Previous PR was [here](https://github.com/supabase/supabase/pull/45143)
but it got stale with lots of conflicts so figured it'll be easier redo
it off the latest master

Moves policies page from Auth to Database under an Access Control
section along with Roles. This moves all existing files, applies
redirects, and updates urls to point to the new route

<img width="274" height="412" alt="image"
src="https://github.com/user-attachments/assets/7952c185-64ae-4355-ba36-45397efe1787"
/>

<img width="453" height="471" alt="image"
src="https://github.com/user-attachments/assets/04b3dcb3-48a5-4049-9893-d01109fb46a9"
/>


## To test
- [ ] Verify that policies now live under Database correctly

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a quick navigation shortcut to open **Database > Policies
(RLS)**.
* **Bug Fixes**
* Updated Policies and RLS-related links across the product to open the
**Database policies** area (menus, command palette, context actions,
alerts, and link-outs).
* Added a permanent redirect from the old **auth policies** URL to the
new **database policies** URL.
* **Documentation**
* Updated RLS Dashboard and security checklist instructions to reference
**Database > Policies**.
* **Tests**
  * Adjusted automated tests to validate the new Policies route.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-30 18:49:33 +08:00

197 lines
6.4 KiB
TypeScript

import { useParams } from 'common'
import { useRouter } from 'next/router'
import type { CommandOptions, ICommand } from 'ui-patterns/CommandMenu'
import { useRegisterCommands, useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'
import { IRouteCommand } from 'ui-patterns/CommandMenu/internal/types'
import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'
import { useIsPlatformWebhooksEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
export function useProjectSettingsGotoCommands(options?: CommandOptions) {
const router = useRouter()
const setIsOpen = useSetCommandMenuOpen()
let { ref, slug } = useParams()
const platformWebhooksEnabled = useIsPlatformWebhooksEnabled()
ref ||= '_'
const hasOrgSlug = typeof slug === 'string' && slug.length > 0 && slug !== '_'
const {
logsAll,
projectSettingsLogDrains,
projectSettingsCustomDomains,
authenticationSignInProviders,
} = useIsFeatureEnabled([
'logs:all',
'project_settings:log_drains',
'project_settings:custom_domains',
'authentication:sign_in_providers',
])
// Log drains depend on the analytics backend, gated by logs:all (see SettingsMenu.utils).
const showLogDrains = logsAll && projectSettingsLogDrains
useRegisterCommands(
COMMAND_MENU_SECTIONS.NAVIGATE,
[
{
id: 'nav-project-settings-add-ons',
name: 'Add-ons',
value: 'Add-ons addons add ons add on add-on',
route: `/project/${ref}/settings/addons`,
defaultHidden: true,
},
{
id: 'nav-project-settings-general',
name: 'General Settings',
route: `/project/${ref}/settings/general`,
defaultHidden: true,
},
{
id: 'nav-project-settings-database',
name: 'Database Settings',
route: `/project/${ref}/database/settings`,
defaultHidden: true,
},
{
id: 'nav-project-settings-auth',
name: 'Auth Settings',
route: authenticationSignInProviders
? `/project/${ref}/auth/providers`
: `/project/${ref}/database/policies`,
defaultHidden: true,
},
...(platformWebhooksEnabled
? [
{
id: 'nav-project-settings-webhooks',
name: 'Project Webhooks',
route: `/project/${ref}/settings/webhooks`,
defaultHidden: true,
} as IRouteCommand,
...(hasOrgSlug
? [
{
id: 'nav-organization-settings-webhooks',
name: 'Organization Webhooks',
route: `/org/${slug}/webhooks`,
defaultHidden: true,
} as IRouteCommand,
]
: []),
]
: []),
{
id: 'nav-project-settings-api',
name: 'API Settings',
route: `/project/${ref}/integrations/data_api/settings`,
defaultHidden: true,
},
{
id: 'nav-project-settings-storage',
name: 'Storage Settings',
route: `/project/${ref}/storage/settings`,
defaultHidden: true,
},
...(projectSettingsCustomDomains
? [
{
id: 'nav-project-settings-custom-domains',
name: 'Custom Domains',
route: `/project/${ref}/settings/general#custom-domains`,
defaultHidden: true,
} as IRouteCommand,
]
: []),
{
id: 'nav-project-settings-restart-project',
name: 'Project availability',
value: 'project availability restart project pause project resume project',
route: `/project/${ref}/settings/general#restart-project`,
defaultHidden: true,
},
{
id: 'nav-project-settings-pause-project',
name: 'Pause project',
route: `/project/${ref}/settings/general#pause-project`,
defaultHidden: true,
},
{
id: 'nav-project-settings-transfer-project',
name: 'Transfer project',
route: `/project/${ref}/settings/general#transfer-project`,
defaultHidden: true,
},
{
id: 'nav-project-settings-delete-project',
name: 'Delete project',
route: `/project/${ref}/settings/general#delete-project`,
defaultHidden: true,
},
{
id: 'nav-project-settings-database-password',
name: 'Database password',
route: `/project/${ref}/database/settings#database-password`,
defaultHidden: true,
},
{
id: 'nav-project-settings-reset-database-password',
name: 'Reset database password',
route: `/project/${ref}/database/settings#database-password`,
defaultHidden: true,
},
{
id: 'nav-project-settings-connection-string',
name: 'Connection string',
action: () => {
router.push(
{
pathname: router.pathname,
query: { ...router.query, showConnect: 'true' },
},
undefined,
{ shallow: true }
)
setIsOpen(false)
},
defaultHidden: true,
} as ICommand,
{
id: 'nav-project-settings-connection-pooling',
name: 'Connection pooling',
route: `/project/${ref}/database/settings#connection-pooler`,
defaultHidden: true,
},
{
id: 'nav-project-settings-ssl-configuration',
name: 'SSL configuration',
route: `/project/${ref}/database/settings#ssl-configuration`,
defaultHidden: true,
},
{
id: 'nav-project-settings-network-restrictions',
name: 'Network restrictions',
route: `/project/${ref}/database/settings#network-restrictions`,
defaultHidden: true,
},
{
id: 'nav-project-settings-banned-ips',
name: 'Banned IPs',
route: `/project/${ref}/database/settings#banned-ips`,
defaultHidden: true,
},
...(showLogDrains
? [
{
id: 'nav-project-settings-log-drains',
name: 'Log drains',
route: `/project/${ref}/settings/log-drains`,
defaultHidden: true,
} as IRouteCommand,
]
: []),
],
{ ...options, deps: [platformWebhooksEnabled, showLogDrains, ref, slug] }
)
}