import { useState } from 'react'; interface NamespaceEditorProps { value: Record; onChange: (value: Record) => void; /** * Disable the "add namespace" controls (input fields + button). Existing * entries remain editable / removable. Used by the DKS [LEGACY] section * to steer new integrations toward MCP servers. */ addDisabled?: boolean; /** Tooltip shown on the disabled controls. */ addDisabledReason?: string; /** Optional href surfaced alongside the tooltip (e.g. MCP help doc). */ addDisabledHref?: string; } export function NamespaceEditor({ value, onChange, addDisabled = false, addDisabledReason, addDisabledHref, }: NamespaceEditorProps) { const [newName, setNewName] = useState(''); const [newApiKey, setNewApiKey] = useState(''); const entries = Object.entries(value); const handleAdd = () => { if (addDisabled) return; const name = newName.trim(); if (!name || name in value) return; onChange({ ...value, [name]: { apiKey: newApiKey } }); setNewName(''); setNewApiKey(''); }; const handleRemove = (name: string) => { const { [name]: _, ...rest } = value; onChange(rest); }; const handleApiKeyChange = (name: string, apiKey: string) => { onChange({ ...value, [name]: { apiKey } }); }; const disabledTitle = addDisabled ? addDisabledReason : undefined; return (
{entries.map(([name, { apiKey }]) => (
{name} handleApiKeyChange(name, e.target.value)} placeholder="API Key" className="flex-1 px-3 py-1.5 text-sm border border-slate-300 rounded-lg focus:ring-2 focus:ring-accent-ring focus:border-accent outline-none" />
))}
setNewName(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); handleAdd(); } }} placeholder="namespace" disabled={addDisabled} title={disabledTitle} className="w-[140px] px-3 py-1.5 text-sm border border-slate-300 rounded-lg focus:ring-2 focus:ring-accent-ring focus:border-accent outline-none disabled:bg-slate-100 disabled:text-slate-400 disabled:cursor-not-allowed" /> setNewApiKey(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); handleAdd(); } }} placeholder="API Key" disabled={addDisabled} title={disabledTitle} className="flex-1 px-3 py-1.5 text-sm border border-slate-300 rounded-lg focus:ring-2 focus:ring-accent-ring focus:border-accent outline-none disabled:bg-slate-100 disabled:text-slate-400 disabled:cursor-not-allowed" /> {addDisabled && addDisabledHref && ( MCP ガイド )}
); }