mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 21:05:06 +03:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Introduces UI for Scoped PAT's. ## Additional context WIP. Testing endpoints. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Scoped access tokens: create, view, delete, and manage granular resource/action permissions with custom expiry options and scoped creation flows. * New scoped token UI: modal/sheet creation flow, resource access selectors, permissions editor, and a scoped token list. * **UI Improvements** * Tabbed Classic vs Scoped tokens layout, refreshed tokens page, improved forms, search/filtering, and table tweaks. * **Bug Fixes / Maintenance** * New data hooks and utilities for scoped tokens and token handling. * **Removed** * Legacy account settings layout and legacy token banner. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { useMemo } from 'react'
|
|
import { ACCESS_TOKEN_RESOURCES } from '../AccessToken.constants'
|
|
import { getRealAccess, formatAccessText } from '../AccessToken.utils'
|
|
|
|
export const useGroupedPermissions = (tokenPermissions: string[] | undefined) => {
|
|
const groupedPermissions = useMemo(() => {
|
|
const grouped: Record<string, string[]> = {}
|
|
|
|
if (!tokenPermissions || tokenPermissions.length === 0) {
|
|
return grouped
|
|
}
|
|
|
|
ACCESS_TOKEN_RESOURCES.forEach((resource) => {
|
|
const access = getRealAccess(resource.resource, tokenPermissions)
|
|
if (access !== 'no access') {
|
|
const formattedAccess = formatAccessText(access)
|
|
if (!grouped[formattedAccess]) {
|
|
grouped[formattedAccess] = []
|
|
}
|
|
grouped[formattedAccess].push(resource.title)
|
|
}
|
|
})
|
|
|
|
return grouped
|
|
}, [tokenPermissions])
|
|
|
|
const totalCount = Object.values(groupedPermissions).reduce(
|
|
(sum, resources) => sum + resources.length,
|
|
0
|
|
)
|
|
|
|
return { groupedPermissions, totalCount }
|
|
}
|