Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions static/frontend/src/components/settings/SettingsPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ vi.mock("@tanstack/react-query", () => ({
}));

import { useQuery } from "@tanstack/react-query";
import { getApiKeyValue } from "./apiKeys";

interface ServerStatus {
status: string;
Expand Down Expand Up @@ -160,6 +161,10 @@ describe("SettingsPage ApiKeysSection Logic", () => {
expect(truncated).toBe("short...");
});

it("normalizes object key entries", () => {
expect(getApiKeyValue({ key: "sk-object-key" })).toBe("sk-object-key");
});

it("checks if keys array has items", () => {
const data = { keys: ["key1", "key2"] };
const hasKeys = data?.keys?.length > 0;
Expand Down
30 changes: 18 additions & 12 deletions static/frontend/src/components/settings/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useI18n } from '@/contexts';
import { ProxySettings } from './ProxySettings';
import { AuthManager } from './AuthManager';
import { PortConfiguration } from './PortConfig';
import { type ApiKeyEntry, getApiKeyValue } from './apiKeys';
import styles from './SettingsPage.module.css';

// API functions
Expand Down Expand Up @@ -164,7 +165,7 @@ function StatusBar() {

function ApiKeysSection() {
const { t } = useI18n();
const { data, isLoading, refetch } = useQuery<{ keys: string[] }>({
const { data, isLoading, refetch } = useQuery<{ keys: ApiKeyEntry[] }>({
queryKey: ['apiKeys'],
queryFn: fetchApiKeys,
});
Expand Down Expand Up @@ -229,17 +230,22 @@ function ApiKeysSection() {
</p>
<div className={styles.keyList}>
{data?.keys?.length ? (
data.keys.map((key) => (
<div key={key} className={styles.keyItem}>
<code className={styles.keyValue}>{key.substring(0, 16)}...</code>
<button
className={styles.deleteButton}
onClick={() => handleDelete(key)}
>
{t.common.delete}
</button>
</div>
))
data.keys.map((entry) => {
const key = getApiKeyValue(entry);
if (!key) return null;

return (
<div key={key} className={styles.keyItem}>
<code className={styles.keyValue}>{key.substring(0, 16)}...</code>
<button
className={styles.deleteButton}
onClick={() => handleDelete(key)}
>
{t.common.delete}
</button>
</div>
);
})
) : (
<div className={styles.emptyState}>{t.settingsPage.noApiKeys}</div>
)}
Expand Down
5 changes: 5 additions & 0 deletions static/frontend/src/components/settings/apiKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type ApiKeyEntry = string | { key?: string; value?: string };

export function getApiKeyValue(key: ApiKeyEntry) {
return typeof key === 'string' ? key : key.key || key.value || '';
}