| 1 | import { Plug, Trash2 } from "lucide-react"; |
| 2 | |
| 3 | import { draftSubmissionLocksEditing, type SessionDraftSurface } from "../app-runtime/useSessionDraftSurface"; |
| 4 | import { Tooltip } from "../components/Tooltip"; |
| 5 | import type { Translator } from "../lib/i18n"; |
| 6 | |
| 7 | /** Keeps optional draft controls available without turning the landing surface |
| 8 | * into a management page. */ |
| 9 | export function DraftTopicbarActions(props: { |
| 10 | t: Translator; |
| 11 | draft: SessionDraftSurface; |
| 12 | onSetMCPEnabled(server: SessionDraftSurface["servers"][number], enabled: boolean): void; |
| 13 | onDiscard(): void; |
| 14 | }) { |
| 15 | const { draft, t } = props; |
| 16 | const editingLocked = draft.preparingSubmission || draftSubmissionLocksEditing(draft.operation); |
| 17 | const enabledServers = draft.servers.filter((server) => server.enabled && !draft.settings.disabledMcp[server.name]).length; |
| 18 | return <div className="topicbar__actions draft-topicbar-actions"> |
| 19 | {draft.servers.length > 0 ? <details className="draft-topicbar-mcp"> |
| 20 | <summary className="topicbar__action-btn topicbar__action-btn--utility" aria-label={t("draft.mcpTitle")}> |
| 21 | <Plug size={15} aria-hidden="true" /> |
| 22 | <span>{enabledServers}/{draft.servers.length}</span> |
| 23 | </summary> |
| 24 | <div className="draft-topicbar-mcp__menu" role="group" aria-label={t("draft.mcpTitle")}> |
| 25 | {draft.servers.map((server) => { |
| 26 | const available = server.enabled; |
| 27 | const selected = available && !draft.settings.disabledMcp[server.name]; |
| 28 | return <label key={server.name}> |
| 29 | <input type="checkbox" checked={selected} disabled={!available || editingLocked} |
| 30 | onChange={(event) => props.onSetMCPEnabled(server, event.currentTarget.checked)} /> |
| 31 | <span>{server.name}</span> |
| 32 | <small>{available ? t(selected ? "draft.mcpEnabled" : "draft.mcpDisabled") : t("draft.mcpUnavailable")}</small> |
| 33 | </label>; |
| 34 | })} |
| 35 | </div> |
| 36 | </details> : null} |
| 37 | <Tooltip label={t("draft.discard")}> |
| 38 | <button className="topicbar__action-btn topicbar__action-btn--icon topicbar__action-btn--utility" type="button" |
| 39 | aria-label={t("draft.discard")} disabled={editingLocked} onClick={props.onDiscard}> |
| 40 | <Trash2 size={15} aria-hidden="true" /> |
| 41 | </button> |
| 42 | </Tooltip> |
| 43 | </div>; |
| 44 | } |
| 45 |