import { PermissionAction } from '@supabase/shared-types/out/constants' import { Code, Edit2, Eye, EyeOff, Lock, MoreVertical, Trash } from 'lucide-react' import { useState } from 'react' import { Badge, Button, cn, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, TableCell, TableRow, Tooltip, TooltipContent, TooltipTrigger, } from 'ui' import type { EnvironmentVariable } from './EnvironmentVariables.types' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions' function getScopeLabel(variable: EnvironmentVariable): string { if (variable.category === 'platform') return 'Production' if (variable.scope === null) return 'All Environments' if (variable.scope === 'production') return 'Production' if (variable.scope === 'preview' && !variable.branch) return 'Preview' if (variable.scope === 'branch' && variable.branch) return variable.branch.replace(/_/g, '-') if (variable.scope === 'development') return 'Development' return 'All Environments' } interface EnvironmentVariableRowProps { variable: EnvironmentVariable onSelectEdit: () => void onSelectDelete: () => void } const EnvironmentVariableRow = ({ variable, onSelectEdit, onSelectDelete, }: EnvironmentVariableRowProps) => { const { can: canUpdateSecrets } = useAsyncCheckPermissions(PermissionAction.SECRETS_WRITE, '*') const [revealed, setRevealed] = useState(false) const isPlatform = variable.category === 'platform' const scopeLabel = getScopeLabel(variable) const displayValue = variable.isSecret ? revealed ? variable.value ?? '' : '••••••••••••••' : variable.value const isWriteOnly = variable.isSecret && revealed && !variable.value return ( {/* Icon */}
{variable.isSecret ? ( ) : ( )}
{/* Name + scope + badges */}

{variable.name}

{variable.isSecret && ( Sensitive )} {variable.hasEnvVar === false && ( No env var A required secret hasn't been set for this config field yet )} {variable.hasConfig === false && ( No config This env var has no corresponding platform config mapping )}

{scopeLabel}

{/* Value + eye toggle */}
{/* Updated at */}

{variable.updatedAt ? `Updated ${new Date(variable.updatedAt).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}` : 'Added recently'}

{/* Actions */} {isPlatform ? null : (