-
Notifications
You must be signed in to change notification settings - Fork 482
feat(gui): API Keys workspace view #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0cc26f8
feat(gui): add API Keys workspace view (rail + main, classic toggle)
Wibias f3e7385
gui: drop per-tab apikeys toggle (sidebar owns it)
Wibias b9bfcdf
fix(gui): wire API Keys workspace to global viewMode
Wibias 7ef666d
fix(gui): address API Keys workspace review findings
Wibias 1eecd37
test(gui): align API Keys workspace create-guard assertion
Wibias 54ea222
fix(gui): harden API Keys workspace overview, create, and landmarks
Wibias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
239 changes: 239 additions & 0 deletions
239
gui/src/components/apikeys-workspace/ApiKeysWorkspace.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| /** | ||
| * ApiKeysWorkspace — rail + main workspace for the API Keys tab, mirroring the | ||
| * Providers workspace DNA. Left rail lists Overview + active keys; the main pane | ||
| * shows either the overview (endpoint, generate form, usage example) or a per-key | ||
| * detail view. | ||
| */ | ||
| import { useRef, useState } from "react"; | ||
| import { IconCheck, IconPlus, IconTrash, IconX } from "../../icons"; | ||
| import { useT } from "../../i18n"; | ||
|
|
||
| export interface ApiKeyEntry { | ||
| id: string; | ||
| name: string; | ||
| prefix: string; | ||
| createdAt: string; | ||
| } | ||
|
|
||
| export interface ApiKeysWorkspaceProps { | ||
| keys: ApiKeyEntry[]; | ||
| endpoint: string; | ||
| localeTag?: string; | ||
| creating: boolean; | ||
| newKey: string | null; | ||
| copied: boolean; | ||
| /** Resolves true only after a successful create so the draft name can be cleared. */ | ||
| onCreate: (name: string) => Promise<boolean>; | ||
| onDismissNewKey: () => void; | ||
| onCopyNewKey: () => void; | ||
| onDelete: (id: string) => void; | ||
| } | ||
|
|
||
| function formatCreatedDate(iso: string, localeTag?: string): string { | ||
| return new Date(iso).toLocaleDateString(localeTag); | ||
| } | ||
|
|
||
| export default function ApiKeysWorkspace({ | ||
| keys, | ||
| endpoint, | ||
| localeTag, | ||
| creating, | ||
| newKey, | ||
| copied, | ||
| onCreate, | ||
| onDismissNewKey, | ||
| onCopyNewKey, | ||
| onDelete, | ||
| }: ApiKeysWorkspaceProps) { | ||
| const t = useT(); | ||
| const [selectedId, setSelectedId] = useState<string | null>(null); | ||
| const [newName, setNewName] = useState(""); | ||
| const [confirmDelete, setConfirmDelete] = useState(false); | ||
| const createInFlight = useRef(false); | ||
|
|
||
| const selected = keys.find(k => k.id === selectedId) ?? null; | ||
|
|
||
| const handleCreate = async () => { | ||
| if (creating || createInFlight.current) return; | ||
| createInFlight.current = true; | ||
| try { | ||
| const ok = await onCreate(newName); | ||
| if (ok) setNewName(""); | ||
| } finally { | ||
| createInFlight.current = false; | ||
| } | ||
| }; | ||
|
|
||
| const handleDeleteClick = () => { | ||
| if (!selected) return; | ||
| if (!confirmDelete) { | ||
| setConfirmDelete(true); | ||
| return; | ||
| } | ||
| onDelete(selected.id); | ||
| setConfirmDelete(false); | ||
| setSelectedId(null); | ||
| }; | ||
|
|
||
| const showOverview = () => { | ||
| setSelectedId(null); | ||
| setConfirmDelete(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="apikeys-workspace-shell"> | ||
| <div className="apikeys-workspace-root"> | ||
| <aside className="apikeys-workspace-rail" aria-label={t("api.title")}> | ||
| <div className="apikeys-workspace-rail-header"> | ||
| <span className="apikeys-workspace-rail-title">{t("api.activeKeys", { count: keys.length })}</span> | ||
| <span className="apikeys-workspace-rail-count">{keys.length}</span> | ||
| </div> | ||
| <div className="apikeys-workspace-rail-list"> | ||
| <button | ||
| type="button" | ||
| className={`apikeys-workspace-rail-row${selectedId === null ? " apikeys-workspace-rail-row--selected" : ""}`} | ||
| onClick={showOverview} | ||
| aria-current={selectedId === null ? "page" : undefined} | ||
| > | ||
| <span className="apikeys-workspace-rail-name">{t("api.workspace.overview")}</span> | ||
| </button> | ||
| {keys.length === 0 ? ( | ||
| <span className="apikeys-workspace-rail-empty">{t("api.workspace.noKeysHint")}</span> | ||
| ) : ( | ||
| keys.map(k => ( | ||
| <button | ||
| key={k.id} | ||
| type="button" | ||
| className={`apikeys-workspace-rail-row${selectedId === k.id ? " apikeys-workspace-rail-row--selected" : ""}`} | ||
| onClick={() => { setSelectedId(k.id); setConfirmDelete(false); }} | ||
| aria-current={selectedId === k.id ? "page" : undefined} | ||
| > | ||
| <span className="apikeys-workspace-rail-name">{k.name}</span> | ||
| <span className="apikeys-workspace-rail-meta">{k.prefix} · {formatCreatedDate(k.createdAt, localeTag)}</span> | ||
| </button> | ||
| )) | ||
| )} | ||
| </div> | ||
| </aside> | ||
|
|
||
| <section className="apikeys-workspace-main" aria-label={t("api.workspace.details")}> | ||
| {selected ? ( | ||
| <div className="awi-detail"> | ||
| <button type="button" className="btn btn-ghost btn-sm awi-back" onClick={showOverview}> | ||
| {t("modal.back")} | ||
| </button> | ||
| <div className="awi-detail-head"> | ||
| <h2 className="awi-detail-title">{selected.name}</h2> | ||
| <span className="awi-detail-actions"> | ||
| {confirmDelete ? ( | ||
| <> | ||
| <button type="button" className="btn btn-danger btn-sm" onClick={handleDeleteClick}> | ||
| <IconTrash /> {t("api.confirm")} | ||
| </button> | ||
| <button type="button" className="btn btn-ghost btn-sm" onClick={() => setConfirmDelete(false)}> | ||
| {t("common.cancel")} | ||
| </button> | ||
| </> | ||
| ) : ( | ||
| <button type="button" className="btn btn-danger btn-sm" onClick={handleDeleteClick} aria-label={t("api.deleteAria")}> | ||
| <IconTrash /> {t("api.workspace.deleteKey")} | ||
| </button> | ||
| )} | ||
| </span> | ||
| </div> | ||
| {confirmDelete && ( | ||
| <p className="muted" style={{ fontSize: 13, marginTop: 0 }}>{t("api.workspace.deleteConfirm")}</p> | ||
| )} | ||
| <div className="awi-section"> | ||
| <h3 className="awi-section-title">{t("api.workspace.keyDetails")}</h3> | ||
| <dl className="awi-kv"> | ||
| <div className="awi-kv-row"> | ||
| <dt>{t("api.colName")}</dt> | ||
| <dd>{selected.name}</dd> | ||
| </div> | ||
| <div className="awi-kv-row"> | ||
| <dt>{t("api.workspace.keyPrefix")}</dt> | ||
| <dd><code>{selected.prefix}</code></dd> | ||
| </div> | ||
| <div className="awi-kv-row"> | ||
| <dt>{t("api.colCreated")}</dt> | ||
| <dd>{formatCreatedDate(selected.createdAt, localeTag)}</dd> | ||
| </div> | ||
| </dl> | ||
| </div> | ||
| </div> | ||
| ) : ( | ||
| <> | ||
| {keys.length > 0 && ( | ||
| <div className="awi-hint">{t("api.workspace.selectKeyHint")}</div> | ||
| )} | ||
|
|
||
| {newKey && ( | ||
| <div className="awi-newkey"> | ||
| <h3 className="awi-newkey-title">{t("api.newKeyTitle")}</h3> | ||
| <p className="awi-newkey-note">{t("api.newKeyNote")}</p> | ||
| <div className="awi-newkey-row"> | ||
| <code className="awi-newkey-code">{newKey}</code> | ||
| <button type="button" className="btn btn-sm btn-ghost" onClick={onCopyNewKey}> | ||
| {copied ? <><IconCheck /> {t("api.copied")}</> : t("api.copy")} | ||
| </button> | ||
| <button type="button" className="btn btn-sm btn-ghost" onClick={onDismissNewKey} aria-label={t("api.dismiss")}> | ||
| <IconX /> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
| <div className="awi-section"> | ||
| <h3 className="awi-section-title">{t("api.endpoint")}</h3> | ||
| <code className="awi-endpoint">{endpoint}</code> | ||
| <p className="awi-endpoint-note">{t("api.endpointNote")}</p> | ||
| </div> | ||
|
|
||
| <div className="awi-section"> | ||
| <h3 className="awi-section-title">{t("api.generateTitle")}</h3> | ||
| <div className="awi-generate-row"> | ||
| <input | ||
| type="text" | ||
| className="input" | ||
| placeholder={t("api.keyNamePlaceholder")} | ||
| aria-label={t("api.keyNamePlaceholder")} | ||
| value={newName} | ||
| disabled={creating} | ||
| onChange={e => setNewName(e.target.value)} | ||
| onKeyDown={e => { | ||
| if ( | ||
| e.key !== "Enter" | ||
| || e.nativeEvent.isComposing | ||
| || creating | ||
| || createInFlight.current | ||
| ) { | ||
| return; | ||
| } | ||
| e.preventDefault(); | ||
| void handleCreate(); | ||
| }} | ||
| /> | ||
| <button type="button" className="btn btn-primary" onClick={() => { void handleCreate(); }} disabled={creating}> | ||
| <IconPlus /> {creating ? t("api.generating") : t("api.generate")} | ||
| </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="awi-section"> | ||
| <h3 className="awi-section-title">{t("api.usageTitle")}</h3> | ||
| <pre className="awi-usage-pre">{`curl ${endpoint} \\ | ||
| -H "Authorization: Bearer ocx_YOUR_KEY_HERE" \\ | ||
| -H "Content-Type: application/json" \\ | ||
| -d '{ | ||
| "model": "gpt-5.4", | ||
| "input": ${JSON.stringify(t("api.usageSampleInput"))} | ||
| }'`}</pre> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| </div> | ||
| </> | ||
| )} | ||
| </section> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a user selects any key,
selectedIdstays non-null and every rail action only selects another key, so the overview containing key generation, endpoint information, and the one-time new-key banner becomes unreachable until the page is remounted or the key is deleted. This can also hide an uncopied newly generated secret after the user selects its rail entry; add an Overview rail row or a back action that callssetSelectedId(null).Useful? React with 👍 / 👎.