Skip to content

Commit 4625fc8

Browse files
committed
Refactor ApiKeysTableRow and utils for improved API key ID handling
- Integrated the getApiKeyIdBadgeLabel function into the ApiKeysTableRow for better ID display. - Updated ApiKeyAddedCell to handle undefined createdBy email more gracefully. - Enhanced tooltip interactions for improved user experience. These changes streamline the API key management interface and enhance the clarity of API key information.
1 parent a576ee4 commit 4625fc8

2 files changed

Lines changed: 55 additions & 48 deletions

File tree

src/features/dashboard/settings/keys/api-keys-table-row.tsx

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
TooltipContent,
1919
TooltipTrigger,
2020
} from '@/ui/primitives/tooltip'
21-
import { getLastUsedLabel } from './api-keys-utils'
21+
import { getApiKeyIdBadgeLabel, getLastUsedLabel } from './api-keys-utils'
2222
import { DeleteApiKeyDialog } from './delete-api-key-dialog'
2323

2424
interface ApiKeysTableRowProps {
@@ -63,11 +63,6 @@ const ApiKeyNameCell = ({ name }: ApiKeyNameCellProps) => (
6363
</TableCell>
6464
)
6565

66-
const getApiKeyIdBadgeLabel = (id: string) => {
67-
if (id.length <= 10) return id
68-
return `${id.slice(0, 6)}...${id.slice(-4)}`
69-
}
70-
7166
const ApiKeyIdBadge = ({ id }: ApiKeyIdBadgeProps) => {
7267
const posthog = usePostHog()
7368
const { toast } = useToast()
@@ -115,7 +110,7 @@ const ApiKeyLastUsedCell = ({
115110
{lastUsedAt ? (
116111
<Tooltip>
117112
<TooltipTrigger asChild>
118-
<span className="cursor-default border-b border-dotted border-fg-tertiary/40">
113+
<span className="cursor-default">
119114
{lastUsedLabel}
120115
</span>
121116
</TooltipTrigger>
@@ -135,48 +130,52 @@ const ApiKeyAddedCell = ({
135130
isCliKey,
136131
keyName,
137132
onDelete,
138-
}: ApiKeyAddedCellProps) => (
139-
<TableCell className="pl-3 pr-0 py-2 text-left text-sm text-fg-tertiary">
140-
<div className="flex items-center gap-6 justify-between">
141-
<span className="block w-[92px] shrink-0 whitespace-nowrap">
142-
{addedDate}
143-
</span>
144-
<div className="flex items-center gap-6">
145-
{isCliKey ? (
146-
<Tooltip>
147-
<TooltipTrigger asChild>
148-
<span className="text-fg-tertiary flex size-5 shrink-0 items-center justify-center">
149-
<E2BLogo className="size-5" />
150-
</span>
151-
</TooltipTrigger>
152-
<TooltipContent side="top">Added through E2B CLI</TooltipContent>
153-
</Tooltip>
154-
) : createdBy ? (
155-
<Tooltip>
156-
<TooltipTrigger asChild>
157-
<span className="shrink-0">
158-
<UserAvatar email={createdBy.email} />
159-
</span>
160-
</TooltipTrigger>
161-
<TooltipContent side="top">{createdBy.email}</TooltipContent>
162-
</Tooltip>
163-
) : (
164-
<span className="size-5 shrink-0" aria-hidden />
165-
)}
166-
<Button
167-
type="button"
168-
variant="ghost"
169-
size="slate"
170-
className="text-fg-tertiary hover:text-fg shrink-0 active:translate-y-0"
171-
aria-label={`Delete ${keyName ?? 'API key'}`}
172-
onClick={onDelete}
173-
>
174-
<TrashIcon className="size-4" />
175-
</Button>
133+
}: ApiKeyAddedCellProps) => {
134+
const createdByEmail = createdBy?.email?.trim() || 'Unknown user'
135+
136+
return (
137+
<TableCell className="pl-3 pr-0 py-2 text-left text-sm text-fg-tertiary">
138+
<div className="flex items-center gap-6 justify-between">
139+
<span className="block w-[92px] shrink-0 whitespace-nowrap">
140+
{addedDate}
141+
</span>
142+
<div className="flex items-center gap-6">
143+
{isCliKey ? (
144+
<Tooltip>
145+
<TooltipTrigger asChild>
146+
<span className="text-fg-tertiary flex size-5 shrink-0 items-center justify-center">
147+
<E2BLogo className="size-5" />
148+
</span>
149+
</TooltipTrigger>
150+
<TooltipContent side="top">Added through E2B CLI</TooltipContent>
151+
</Tooltip>
152+
) : createdBy ? (
153+
<Tooltip>
154+
<TooltipTrigger asChild>
155+
<span className="cursor-default shrink-0">
156+
<UserAvatar email={createdByEmail} />
157+
</span>
158+
</TooltipTrigger>
159+
<TooltipContent side="top">{createdByEmail}</TooltipContent>
160+
</Tooltip>
161+
) : (
162+
<span className="size-5 shrink-0" aria-hidden />
163+
)}
164+
<Button
165+
type="button"
166+
variant="ghost"
167+
size="slate"
168+
className="text-fg-tertiary hover:text-fg shrink-0 active:translate-y-0"
169+
aria-label={`Delete ${keyName ?? 'API key'}`}
170+
onClick={onDelete}
171+
>
172+
<TrashIcon className="size-4" />
173+
</Button>
174+
</div>
176175
</div>
177-
</div>
178-
</TableCell>
179-
)
176+
</TableCell>
177+
)
178+
}
180179

181180
export const ApiKeysTableRow = ({ apiKey, teamSlug }: ApiKeysTableRowProps) => {
182181
const [deleteOpen, setDeleteOpen] = useState(false)

src/features/dashboard/settings/keys/api-keys-utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export const getMaskedIdSearchString = (apiKey: TeamAPIKey): string => {
88
return `${prefix}${maskedValuePrefix}...${maskedValueSuffix}`.toLowerCase()
99
}
1010

11+
/** Builds the visible ID badge label; e.g. `"e2b_c28e178eecf2"` -> `"e2b_c2...ecf2"` */
12+
export const getApiKeyIdBadgeLabel = (id: string): string => {
13+
if (id.length <= 10) return id
14+
return `${id.slice(0, 6)}...${id.slice(-4)}`
15+
}
16+
1117
/** Returns true when the key name or masked id contains the trimmed query (case-insensitive). */
1218
export const matchesApiKeySearch = (
1319
apiKey: TeamAPIKey,
@@ -16,6 +22,8 @@ export const matchesApiKeySearch = (
1622
const q = query.trim().toLowerCase()
1723
if (!q) return true
1824
if (apiKey.name.toLowerCase().includes(q)) return true
25+
if (apiKey.id.toLowerCase().includes(q)) return true
26+
if (getApiKeyIdBadgeLabel(apiKey.id).toLowerCase().includes(q)) return true
1927
return getMaskedIdSearchString(apiKey).includes(q)
2028
}
2129

0 commit comments

Comments
 (0)