mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +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" />
192 lines
6.2 KiB
TypeScript
192 lines
6.2 KiB
TypeScript
import { useParams } from 'common'
|
|
import dayjs from 'dayjs'
|
|
import {
|
|
Edit3Icon,
|
|
EyeIcon,
|
|
EyeOffIcon,
|
|
KeyIcon,
|
|
LoaderIcon,
|
|
MoreVerticalIcon,
|
|
TrashIcon,
|
|
} from 'lucide-react'
|
|
import { parseAsString, useQueryState } from 'nuqs'
|
|
import { useState } from 'react'
|
|
import {
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
import { Input } from 'ui-patterns/DataInputs/Input'
|
|
|
|
import { SecretTableColumn } from './Secrets.types'
|
|
import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
|
|
import { useVaultSecretDecryptedValueQuery } from '@/data/vault/vault-secret-decrypted-value-query'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import type { VaultSecret } from '@/types'
|
|
|
|
interface SecretRowProps {
|
|
row: VaultSecret
|
|
col: SecretTableColumn
|
|
}
|
|
|
|
export const SecretRow = ({ row, col }: SecretRowProps) => {
|
|
const { ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const [revealSecret, setRevealSecret] = useState(false)
|
|
const name = row?.name ?? 'No name provided'
|
|
|
|
const [, setSelectedSecretToEdit] = useQueryState('edit', parseAsString)
|
|
const [, setSelectedSecretToDelete] = useQueryState('delete', parseAsString)
|
|
|
|
const { can: canManageSecrets } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.DATABASE_WRITE
|
|
)
|
|
|
|
const { data: revealedValue, isFetching } = useVaultSecretDecryptedValueQuery(
|
|
{
|
|
projectRef: ref!,
|
|
connectionString: project?.connectionString,
|
|
id: row.id,
|
|
},
|
|
{
|
|
enabled: !!(ref! && row.id) && revealSecret,
|
|
}
|
|
)
|
|
|
|
if (col.id === 'actions') {
|
|
return (
|
|
<div className="flex items-center justify-end w-full" onClick={(e) => e.stopPropagation()}>
|
|
<DropdownMenu>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
title="Manage Secret"
|
|
variant="text"
|
|
className="px-1"
|
|
icon={<MoreVerticalIcon />}
|
|
aria-label="Manage secret"
|
|
// Tooltip repeats the label; screen readers would read it twice
|
|
aria-describedby={undefined}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">Manage secret</TooltipContent>
|
|
</Tooltip>
|
|
<DropdownMenuContent side="bottom" align="end" className="w-40">
|
|
<DropdownMenuItemTooltip
|
|
className="gap-x-2"
|
|
disabled={!canManageSecrets}
|
|
onClick={() => setSelectedSecretToEdit(row.id)}
|
|
tooltip={{
|
|
content: { side: 'left', text: 'You need additional permissions to edit secrets' },
|
|
}}
|
|
>
|
|
<Edit3Icon size={12} />
|
|
<p>Edit</p>
|
|
</DropdownMenuItemTooltip>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<DropdownMenuItemTooltip
|
|
className="gap-x-2"
|
|
disabled={!canManageSecrets}
|
|
onClick={() => setSelectedSecretToDelete(row.id)}
|
|
tooltip={{
|
|
content: {
|
|
side: 'left',
|
|
text: 'You need additional permissions to delete secrets',
|
|
},
|
|
}}
|
|
>
|
|
<TrashIcon size={12} />
|
|
<p className="text-foreground-light">Delete</p>
|
|
</DropdownMenuItemTooltip>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (col.id === 'secret_value') {
|
|
return (
|
|
<div className="flex items-center gap-2 w-full" onClick={(e) => e.stopPropagation()}>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="text"
|
|
className="px-1.5"
|
|
icon={
|
|
isFetching && revealedValue === undefined ? (
|
|
<LoaderIcon className="animate-spin" size={16} strokeWidth={1.5} />
|
|
) : !revealSecret ? (
|
|
<EyeIcon size={16} strokeWidth={1.5} />
|
|
) : (
|
|
<EyeOffIcon size={16} strokeWidth={1.5} />
|
|
)
|
|
}
|
|
onClick={() => setRevealSecret(!revealSecret)}
|
|
aria-label={revealSecret ? 'Hide secret value' : 'Show secret value'}
|
|
// Tooltip repeats the label; screen readers would read it twice
|
|
aria-describedby={undefined}
|
|
/>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">
|
|
{revealSecret ? 'Hide secret value' : 'Show secret value'}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
<div className="grow min-w-0">
|
|
{revealSecret && revealedValue !== undefined ? (
|
|
<Input copy readOnly size="tiny" className="font-mono" value={revealedValue} />
|
|
) : (
|
|
<p className="text-sm font-mono text-foreground">••••••••••••••••••</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (col.id === 'updated_at') {
|
|
return (
|
|
<div className="w-full flex items-center justify-start">
|
|
<p className="text-xs text-foreground-light">
|
|
{row.updated_at === row.created_at ? <span>Added</span> : <span>Updated</span>}{' '}
|
|
<span>on</span> {dayjs(row.updated_at).format('MMM D, YYYY')}
|
|
</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (col.id === 'id') {
|
|
return (
|
|
<div className="w-full flex items-center">
|
|
<KeyIcon size={12} strokeWidth={2} className="text-foreground-light mr-2" />
|
|
<p className="text-foreground-light text-xs font-mono truncate" title={row.id}>
|
|
{row.id}
|
|
</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="w-full flex flex-col justify-center">
|
|
<p className="text-xs text-foreground truncate select-text" title={name}>
|
|
{name}
|
|
</p>
|
|
{row.description !== undefined && row.description !== '' && (
|
|
<div>
|
|
<p className="text-xs text-foreground-lighter w-full truncate select-text">
|
|
{row.description}
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|