Files
supabase/apps/studio/components/ui/ApiKeysAccessNote.tsx
Joshen Lim 6d08d66b7d Add eslint rule for google translate dynamic spans + address all issues (#52949)
## 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"
/>
2026-11-05 23:28:46 +08:00

51 lines
1.7 KiB
TypeScript

import { AlertError } from '@/components/ui/AlertError'
type ApiKeysAccessNoteProps = {
/** Result of `useGrant` for the api-keys endpoint. Renders nothing unless it is denied or errored. */
grant: { status: 'loading' | 'granted' | 'denied' | 'error'; error?: { message: string } }
/** Once the grant is `granted`, state of the revealed key. Shows a note if it couldn't be loaded. */
keyState?: 'ready' | 'loading' | 'error' | 'missing'
/** What the user can do instead, appended to the shared message. */
fallback?: string
/** Spacing for the wrapper, which is only rendered when there is something to show. */
className?: string
}
/**
* Inline note for widgets that prefill or offer API keys, shown when the user can't read them.
* Keeps the rest of the widget usable.
*/
export const ApiKeysAccessNote = ({
grant,
keyState,
fallback,
className,
}: ApiKeysAccessNoteProps) => {
if (grant.status === 'denied') {
return (
<div className={className}>
<p className="text-xs text-foreground-lighter">
{`You need additional permissions to view API keys.${fallback ? ` ${fallback}` : ''}`}
</p>
</div>
)
}
if (grant.status === 'error') {
return (
<div className={className}>
<AlertError error={grant.error} subject="Failed to check API key permissions" />
</div>
)
}
if (grant.status === 'granted' && (keyState === 'error' || keyState === 'missing')) {
return (
<div className={className}>
<p className="text-xs text-foreground-lighter">
{`Couldn't load your API keys.${fallback ? ` ${fallback}` : ''}`}
</p>
</div>
)
}
return null
}