mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Context We've been seeing many `NotFoundError: Failed to execute 'removeChild' on 'Node'` and `NotFoundError: Failed to execute 'insertBefore' on 'Node'` events on Sentry which are historically known to be caused by Google Translate in the browser. There's technically no _right way_ to address this unfortunately, but one of the solutions which should address most of these issues is to wrap any dynamic text within a span - we've considered that quite a while back tbh but never took the time to do this until today with the help of Claude. Although just a heads up that it might not necessarily completely eradicate those issues. Also added an eslint rule which should prevent future occurences of this <img width="1264" height="192" alt="image" src="https://github.com/user-attachments/assets/b2c32ea0-45a2-4ccd-82fe-1a859905fc29" />
75 lines
2.8 KiB
TypeScript
75 lines
2.8 KiB
TypeScript
import { Badge, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
|
|
import {
|
|
PERMISSION_MODE_LABEL,
|
|
type PermissionCatalogEntry,
|
|
type PermissionMode,
|
|
} from '../AccessToken.permissions'
|
|
import { TOKEN_ROLE_LABEL, type EntryAccess, type FailingResource } from '../AccessToken.roles'
|
|
|
|
const MAX_LISTED_RESOURCES = 5
|
|
const MAX_LISTED_PROJECT_ROLES = 3
|
|
|
|
/**
|
|
* One line per failing resource. Members invited to projects (not the org) get their real
|
|
* per-project role spelled out.
|
|
*/
|
|
export const failingResourceLine = (resource: FailingResource): string => {
|
|
if (resource.projectScopedRoles !== undefined && resource.projectScopedRoles.length > 0) {
|
|
const listed = resource.projectScopedRoles
|
|
.slice(0, MAX_LISTED_PROJECT_ROLES)
|
|
.map((project) => `${TOKEN_ROLE_LABEL[project.role]} on the project ${project.label}`)
|
|
.join(', ')
|
|
const overflow = resource.projectScopedRoles.length - MAX_LISTED_PROJECT_ROLES
|
|
const roles = overflow > 0 ? `${listed}, and ${overflow} more` : listed
|
|
return `${resource.label} — your role is ${roles}`
|
|
}
|
|
if (resource.role === 'member' || resource.role === 'none') {
|
|
return resource.type === 'organization'
|
|
? `${resource.label} — you don't have an organization-level role`
|
|
: `${resource.label} — you don't have a role on this project`
|
|
}
|
|
return `${resource.label} — your role is ${TOKEN_ROLE_LABEL[resource.role]}`
|
|
}
|
|
|
|
interface ExceedsRoleBadgeProps {
|
|
entry: PermissionCatalogEntry
|
|
mode: PermissionMode
|
|
access: EntryAccess
|
|
}
|
|
|
|
/**
|
|
* "Exceeds your role" pill with a tooltip naming exactly which resources deny the permission and
|
|
* why.
|
|
*/
|
|
export const ExceedsRoleBadge = ({ entry, mode, access }: ExceedsRoleBadgeProps) => {
|
|
const failingResources = access.failingResources
|
|
const overflowCount = failingResources.length - MAX_LISTED_RESOURCES
|
|
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span tabIndex={0}>
|
|
<Badge variant="destructive" className="cursor-help">
|
|
Exceeds your role
|
|
</Badge>
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top" className="max-w-80 space-y-1.5">
|
|
<p className="text-xs">
|
|
{entry.name} ({PERMISSION_MODE_LABEL[mode]}) requires the{' '}
|
|
{TOKEN_ROLE_LABEL[access.requiredRole]} role or above
|
|
{entry.level === 'organization' && <span>{' at the organization level'}</span>}
|
|
<span>. Requests will be denied on:</span>
|
|
</p>
|
|
<ul className="text-xs text-foreground-light space-y-0.5">
|
|
{failingResources.slice(0, MAX_LISTED_RESOURCES).map((resource) => (
|
|
<li key={resource.id}>{failingResourceLine(resource)}</li>
|
|
))}
|
|
{overflowCount > 0 && <li>and {overflowCount} more</li>}
|
|
</ul>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)
|
|
}
|