mirror of
https://github.com/supabase/supabase.git
synced 2026-06-15 08:05:21 +08:00
## Summary - Adds contextual `A + <letter>` chord shortcuts for jumping between Authentication sub-pages while `AuthLayout` is mounted, mirroring the existing database-nav chord pattern. - Wires the shared `LIST_PAGE_*` shortcuts (focus search, create new, reset filters, schema selector) onto the Auth list pages so they behave like the Database list pages. - Fills in the previously-missing `A + U` chord for the **Users** page so every entry in the Auth menu has a chord. Resolves [FE-3187](https://linear.app/supabase/issue/FE-3187/add-a-u-keyboard-shortcut-for-auth-users-page). ## Auth navigation chords Active anywhere under `/project/<ref>/auth/*`. Press `A` then the listed letter. | Page | Chord | | --- | --- | | Overview | `A` `O` | | Users | `A` `U` | | OAuth Apps | `A` `A` | | Email | `A` `E` | | Policies | `A` `P` | | Sign In / Providers | `A` `I` | | Passkeys | `A` `K` | | OAuth Server | `A` `V` | | Sessions | `A` `S` | | Rate Limits | `A` `R` | | Multi-Factor | `A` `M` | | URL Configuration | `A` `L` | | Attack Protection | `A` `T` | | Auth Hooks | `A` `H` | | Audit Logs | `A` `G` | | Performance | `A` `F` | ## Auth list-page shortcuts Each Auth list page opts into the shared `LIST_PAGE_*` registry — same chords as the Database list pages (`Shift+F`, `Shift+N`, `F` `C`, `O` `S`). Coverage matches the controls each page actually exposes: | List page | Search (`Shift+F`) | New (`Shift+N`) | Reset filters (`F` `C`) | Schema selector (`O` `S`) | | --- | :---: | :---: | :---: | :---: | | Custom Auth Providers | ✓ | ✓ | ✓ | — | | OAuth Apps | ✓ | ✓ | ✓ | — | | Policies | ✓ | — | ✓ | ✓ | | Auth Hooks | — | ✓ | — | — | | Redirect URLs | — | ✓ | — | — | | Third-Party Auth | — | ✓ | — | — | ## Test plan - [x] While anywhere under `/project/<ref>/auth/*`, every chord in the navigation table jumps to the corresponding page. - [x] On each list page in the second table, the marked shortcuts focus the search input / open the create flow / reset filters / open the schema picker as expected. - [x] Chords are not active outside of `/project/<ref>/auth/*` and do not trigger while typing in inputs (where `ignoreInputs` applies). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Global keyboard shortcuts for Auth pages: navigate auth sections, focus/search inputs, reset filters, and open "Add" flows (providers, OAuth apps, hooks, URLs, policies). * "Add" controls in lists respond to shortcuts and show appropriate disabled/tooltip states when unavailable. * Product menu and shortcuts reference now include an "Auth Navigation" section and per-item shortcut hints. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
130 lines
4.2 KiB
TypeScript
130 lines
4.2 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useParams } from 'common'
|
|
import { ChevronDown } from 'lucide-react'
|
|
import { useMemo } from 'react'
|
|
import {
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from 'ui'
|
|
|
|
import { Hook, HOOK_DEFINITION_TITLE, HOOKS_DEFINITIONS } from './hooks.constants'
|
|
import { extractMethod, isValidHook } from './hooks.utils'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import { useAuthConfigQuery } from '@/data/auth/auth-config-query'
|
|
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
|
|
interface AddHookDropdownProps {
|
|
buttonText?: string
|
|
align?: 'end' | 'center'
|
|
type?: 'primary' | 'default'
|
|
open?: boolean
|
|
onOpenChange?: (open: boolean) => void
|
|
onSelectHook: (hook: HOOK_DEFINITION_TITLE) => void
|
|
}
|
|
|
|
export const AddHookDropdown = ({
|
|
buttonText = 'Add hook',
|
|
align = 'end',
|
|
type = 'primary',
|
|
open,
|
|
onOpenChange,
|
|
onSelectHook,
|
|
}: AddHookDropdownProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const { data: organization } = useSelectedOrganizationQuery()
|
|
|
|
const { data: authConfig } = useAuthConfigQuery({ projectRef })
|
|
const { can: canUpdateAuthHook } = useAsyncCheckPermissions(PermissionAction.AUTH_EXECUTE, '*')
|
|
const { getEntitlementSetValues: getEntitledHookSet } = useCheckEntitlements('auth.hooks')
|
|
const entitledHookSet = getEntitledHookSet()
|
|
|
|
const { availableHooks, nonAvailableHooks } = useMemo(() => {
|
|
const allHooks: Hook[] = HOOKS_DEFINITIONS.map((definition) => ({
|
|
...definition,
|
|
enabled: authConfig?.[definition.enabledKey] || false,
|
|
method: extractMethod(
|
|
authConfig?.[definition.uriKey] || '',
|
|
authConfig?.[definition.secretsKey] || ''
|
|
),
|
|
}))
|
|
|
|
const availableHooks: Hook[] = allHooks.filter(
|
|
(h) => !isValidHook(h) && entitledHookSet.includes(h.entitlementKey)
|
|
)
|
|
|
|
const nonAvailableHooks: Hook[] = allHooks.filter(
|
|
(h) => !isValidHook(h) && !entitledHookSet.includes(h.entitlementKey)
|
|
)
|
|
|
|
return { availableHooks, nonAvailableHooks }
|
|
}, [entitledHookSet, authConfig])
|
|
|
|
if (!canUpdateAuthHook) {
|
|
return (
|
|
<ButtonTooltip
|
|
disabled
|
|
type={type}
|
|
tooltip={{
|
|
content: { side: 'bottom', text: 'You need additional permissions to add auth hooks' },
|
|
}}
|
|
>
|
|
{buttonText}
|
|
</ButtonTooltip>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<DropdownMenu open={open} onOpenChange={onOpenChange}>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button type={type} iconRight={<ChevronDown />}>
|
|
{buttonText}
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent className="w-76" align={align}>
|
|
<div>
|
|
{availableHooks.length === 0 && (
|
|
<DropdownMenuLabel className="text-foreground-light">
|
|
All available hooks have been added
|
|
</DropdownMenuLabel>
|
|
)}
|
|
{availableHooks.map((h) => (
|
|
<DropdownMenuItem key={h.title} onClick={() => onSelectHook(h.title)}>
|
|
{h.title}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</div>
|
|
{nonAvailableHooks.length > 0 && (
|
|
<>
|
|
{availableHooks.length > 0 && <DropdownMenuSeparator />}
|
|
|
|
<DropdownMenuLabel className="grid gap-1 bg-surface-200">
|
|
<p className="text-foreground-light">Team or Enterprise Plan required</p>
|
|
<p className="text-foreground-lighter text-xs">
|
|
The following hooks are not available on{' '}
|
|
<InlineLink href={`/org/${organization?.slug ?? '_'}/billing`}>
|
|
your plan
|
|
</InlineLink>
|
|
.
|
|
</p>
|
|
</DropdownMenuLabel>
|
|
|
|
{nonAvailableHooks.map((h) => (
|
|
<DropdownMenuItem key={h.title} disabled={true}>
|
|
{h.title}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</>
|
|
)}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|