fix(webui): localize the component gallery
This commit is contained in:
1 parent
282839cc65
commit
ae5cb64e9e
54 files changed
+11120
-719
No files matched your search
@@ -11,6 +11,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from
|
||||
import { DEFAULT_LOCAL_PREFS } from "@/lib/local-preferences";
|
||||
import type { AutomationChatsPayload, SessionAutomationJob } from "@/lib/types";
|
||||
import { StatePicker, type ComponentExample } from "./example";
|
||||
import { useGalleryTranslation } from "./i18n";
|
||||
|
||||
const job: SessionAutomationJob = {
|
||||
id: "gallery-report", name: "Weekly summary", enabled: true, chat_binding_revision: "gallery-1",
|
||||
@@ -26,26 +27,28 @@ const chats: AutomationChatsPayload = {
|
||||
};
|
||||
|
||||
function RunResultPreview() {
|
||||
const { t, i18n } = useGalleryTranslation();
|
||||
const [mode, setMode] = useState<"complete" | "loading" | "error" | "empty" | "unavailable">("complete");
|
||||
const [open, setOpen] = useState(false);
|
||||
const trigger = useRef<HTMLButtonElement>(null);
|
||||
const result: AutomationRunResult = mode === "loading" || mode === "error"
|
||||
? { status: mode, response: null }
|
||||
: { status: "loaded", response: mode === "empty" ? "" : mode === "unavailable" ? null : "## Weekly summary\n\n- **Completed:** component previews\n- **Next:** review the changes" };
|
||||
return <><StatePicker label="运行结果" value={mode} options={["complete", "loading", "error", "empty", "unavailable"]} onChange={setMode} />
|
||||
<Button ref={trigger} variant="outline" onClick={() => setOpen(true)}>查看运行结果</Button>
|
||||
return <><StatePicker label={t("controls.runResult.state")} value={mode} options={["complete", "loading", "error", "empty", "unavailable"]} onChange={setMode} />
|
||||
<Button ref={trigger} variant="outline" onClick={() => setOpen(true)}>{t("controls.runResult.view")}</Button>
|
||||
<AutomationRunDialogView job={job} run={{ run_at_ms: Date.UTC(2026, 9, 12, 9, 30), status: "ok", duration_ms: 3200 }}
|
||||
locale="zh-CN" open={open} result={result} onRetry={() => setMode("complete")} onOpenChange={setOpen}
|
||||
locale={i18n.language} open={open} result={result} onRetry={() => setMode("complete")} onOpenChange={setOpen}
|
||||
onCloseAutoFocus={(event) => { event.preventDefault(); trigger.current?.focus(); }} /></>;
|
||||
}
|
||||
|
||||
function ChatBindingPreview() {
|
||||
const { t } = useGalleryTranslation();
|
||||
const [mode, setMode] = useState<"ready" | "pending" | "load-error" | "conflict">("ready");
|
||||
const [task, setTask] = useState(job);
|
||||
const [data, setData] = useState(chats);
|
||||
const [notice, setNotice] = useState("");
|
||||
return <><StatePicker label="聊天绑定状态" value={mode} options={["ready", "pending", "load-error", "conflict"]} onChange={setMode} />
|
||||
<Dialog><DialogTrigger asChild><Button variant="outline">设置运行聊天</Button></DialogTrigger>
|
||||
const [targetTitle, setTargetTitle] = useState("");
|
||||
return <><StatePicker label={t("controls.chatBinding.state")} value={mode} options={["ready", "pending", "load-error", "conflict"]} onChange={setMode} />
|
||||
<Dialog><DialogTrigger asChild><Button variant="outline">{t("controls.chatBinding.setChat")}</Button></DialogTrigger>
|
||||
<DialogContent aria-describedby={undefined} className="max-w-[520px] gap-0 p-0">
|
||||
<AutomationChatBindingView job={mode === "pending" ? { ...task, state: { pending: true } } : task}
|
||||
data={data} loadError={mode === "load-error"} showBrandLogos={false} onReload={() => setMode("ready")}
|
||||
@@ -54,27 +57,28 @@ function ChatBindingPreview() {
|
||||
setTask((current) => ({ ...current, chat_binding_revision: `${current.chat_binding_revision}-next`, payload: { ...current.payload, message: values.message } }));
|
||||
}} onSaved={(target) => {
|
||||
setData((current) => ({ ...current, current: target, revision: `${current.revision}-next` }));
|
||||
setNotice(`下次运行将在 ${target.title} 中进行`);
|
||||
setTargetTitle(target.title);
|
||||
}}>{(picker) => <>
|
||||
<DialogHeader className="px-6 pb-4 pr-12 pt-5"><DialogTitle>{task.name}</DialogTitle></DialogHeader>
|
||||
<div className="px-6 pb-6">{picker}</div>
|
||||
</>}</AutomationChatBindingView>
|
||||
</DialogContent>
|
||||
</Dialog><p role="status" className="mt-4 text-xs text-muted-foreground">{notice || "选择目标聊天,确认或修改任务说明。"}</p></>;
|
||||
</Dialog><p role="status" className="mt-4 text-xs text-muted-foreground">{targetTitle ? t("controls.chatBinding.saved", { title: targetTitle }) : t("controls.chatBinding.hint")}</p></>;
|
||||
}
|
||||
|
||||
function AboutPreview() {
|
||||
const { t } = useGalleryTranslation();
|
||||
const [mode, setMode] = useState<"ready" | "checking" | "up-to-date" | "update" | "error">("ready");
|
||||
const [notice, setNotice] = useState("");
|
||||
const [selectedLink, setSelectedLink] = useState(false);
|
||||
const result: VersionCheckState = mode === "up-to-date" ? { type: mode }
|
||||
: mode === "update" ? { type: mode, latestVersion: "0.3.6", pypiUrl: "https://pypi.org/project/nanobot-ai/" }
|
||||
: mode === "error" ? { type: mode, message: "无法获取版本信息,请重试。" } : null;
|
||||
return <><StatePicker label="版本状态" value={mode} options={["ready", "checking", "up-to-date", "update", "error"]} onChange={setMode} />
|
||||
: mode === "error" ? { type: mode, message: t("controls.about.error") } : null;
|
||||
return <><StatePicker label={t("controls.about.state")} value={mode} options={["ready", "checking", "up-to-date", "update", "error"]} onChange={setMode} />
|
||||
<AboutSettingsView reportIssueUrl="https://github.com/HKUDS/nanobot/issues/new?template=bug_report.yml"
|
||||
versionCheck={<VersionCheckRowView currentVersion="0.3.5" currentCommit="abcdef1234567890" checking={mode === "checking"}
|
||||
result={result} onCheck={() => setMode("update")} />}
|
||||
starLink={<StarLinkView onActivate={() => setNotice("选择了 GitHub 链接")} />} />
|
||||
{notice ? <p role="status" className="mt-4 text-xs text-muted-foreground">{notice}</p> : null}</>;
|
||||
starLink={<StarLinkView onActivate={() => setSelectedLink(true)} />} />
|
||||
{selectedLink ? <p role="status" className="mt-4 text-xs text-muted-foreground">{t("controls.about.selectedLink")}</p> : null}</>;
|
||||
}
|
||||
|
||||
function AppearancePreview() {
|
||||
@@ -86,36 +90,37 @@ function AppearancePreview() {
|
||||
}
|
||||
|
||||
function StarInvitationPreview() {
|
||||
const { t } = useGalleryTranslation();
|
||||
const [mode, setMode] = useState<"ready" | "saving" | "error">("ready");
|
||||
const [open, setOpen] = useState(false);
|
||||
const [notice, setNotice] = useState("");
|
||||
return <><StatePicker label="邀请状态" value={mode} options={["ready", "saving", "error"]} onChange={setMode} />
|
||||
<Button variant="outline" onClick={() => setOpen(true)}>查看邀请</Button>
|
||||
const [notice, setNotice] = useState<"dismissed" | "starred" | null>(null);
|
||||
return <><StatePicker label={t("controls.starInvitation.state")} value={mode} options={["ready", "saving", "error"]} onChange={setMode} />
|
||||
<Button variant="outline" onClick={() => setOpen(true)}>{t("controls.starInvitation.view")}</Button>
|
||||
<StarPromptView open={open} saving={mode === "saving"} error={mode === "error"} onOpenChange={setOpen}
|
||||
onDismissForever={() => { setNotice("预览中选择了不再提醒"); setOpen(false); }}
|
||||
onStar={() => { setNotice("预览中选择了 GitHub 链接"); setOpen(false); }} />
|
||||
{notice ? <p role="status" className="mt-4 text-xs text-muted-foreground">{notice}</p> : null}</>;
|
||||
onDismissForever={() => { setNotice("dismissed"); setOpen(false); }}
|
||||
onStar={() => { setNotice("starred"); setOpen(false); }} />
|
||||
{notice ? <p role="status" className="mt-4 text-xs text-muted-foreground">{t(`controls.starInvitation.${notice}`)}</p> : null}</>;
|
||||
}
|
||||
|
||||
export const runtimeSettingsExamples: ComponentExample[] = [
|
||||
{ title: "AutomationRunDialogView · 运行结果", files: ["webui/src/components/settings/system/AutomationRunDialogView.tsx"], Preview: RunResultPreview,
|
||||
description: "打开运行结果,比较 Markdown 回复、加载、重试、空回复与历史记录缺失状态。",
|
||||
options: "result 提供加载状态与已取得的回复。onRetry 交给调用方处理;此视图不读取运行时或请求结果。",
|
||||
{ title: "controls.runResult.title", files: ["webui/src/components/settings/system/AutomationRunDialogView.tsx"], Preview: RunResultPreview,
|
||||
description: "controls.runResult.description",
|
||||
options: "controls.runResult.options",
|
||||
code: '<AutomationRunDialogView job={job} run={run} locale="zh-CN" open={open} result={{ status: "loaded", response }} onRetry={retry} onOpenChange={setOpen} onCloseAutoFocus={restoreFocus} />' },
|
||||
{ title: "AutomationChatBindingView · 运行聊天", files: ["webui/src/components/settings/system/AutomationChatBindingView.tsx"], Preview: ChatBindingPreview,
|
||||
description: "选择运行聊天、修改任务说明,确认、更换回来或取消;可比较任务占用、加载错误与冲突。",
|
||||
options: "data 与 job 提供可用聊天和绑定版本。视图管理确认草稿;onSave、onSaved 与 onReload 由功能入口接入数据操作。",
|
||||
{ title: "controls.chatBinding.title", files: ["webui/src/components/settings/system/AutomationChatBindingView.tsx"], Preview: ChatBindingPreview,
|
||||
description: "controls.chatBinding.description",
|
||||
options: "controls.chatBinding.options",
|
||||
code: '<AutomationChatBindingView job={job} data={chats} loadError={false} showBrandLogos={false} onSave={save} onSaved={updateCurrent} onReload={reload}>{renderDetails}</AutomationChatBindingView>' },
|
||||
{ title: "About and version views · 关于与版本", files: ["webui/src/components/settings/overview/AboutSettingsView.tsx", "webui/src/components/settings/overview/VersionCheckRowView.tsx"], Preview: AboutPreview,
|
||||
description: "比较版本检查状态、提交链接、更新入口和关于页面;按钮用示例结果更新显示。",
|
||||
options: "AboutSettingsView 接受版本与支持链接的组合。VersionCheckRowView 展示 checking/result,并通过 onCheck 请求检查。真实检查与诊断链接数据由功能入口负责。",
|
||||
{ title: "controls.about.title", files: ["webui/src/components/settings/overview/AboutSettingsView.tsx", "webui/src/components/settings/overview/VersionCheckRowView.tsx"], Preview: AboutPreview,
|
||||
description: "controls.about.description",
|
||||
options: "controls.about.options",
|
||||
code: '<AboutSettingsView reportIssueUrl={reportIssueUrl} versionCheck={<VersionCheckRowView currentVersion={version} checking={checking} result={result} onCheck={check} />} starLink={<StarLinkView onActivate={star} />} />' },
|
||||
{ title: "AppearanceSettingsView · 外观选项", files: ["webui/src/components/settings/overview/AppearanceSettingsView.tsx"], Preview: AppearancePreview,
|
||||
description: "切换外观、活动展示、文件差异和通知偏好,下方显示示例值。",
|
||||
options: "主题和偏好由调用方管理。onChangeBrowserNotifications 将权限申请交给功能入口;预览回调只改变示例开关。",
|
||||
{ title: "controls.appearance.title", files: ["webui/src/components/settings/overview/AppearanceSettingsView.tsx"], Preview: AppearancePreview,
|
||||
description: "controls.appearance.description",
|
||||
options: "controls.appearance.options",
|
||||
code: '<AppearanceSettingsView theme={theme} onToggleTheme={toggleTheme} localPrefs={preferences} onChangeLocalPrefs={setPreferences} onChangeBrowserNotifications={changeNotifications} />' },
|
||||
{ title: "StarPromptView · 支持邀请", files: ["webui/src/components/StarPromptView.tsx"], Preview: StarInvitationPreview,
|
||||
description: "打开实际邀请弹窗,比较保存与错误状态,体验暂缓、GitHub 链接和不再提醒的操作。",
|
||||
options: "open、saving 和 error 是显示状态。领取邀请与持久化偏好由原有 StarPrompt 入口负责;视图只调用传入操作。",
|
||||
{ title: "controls.starInvitation.title", files: ["webui/src/components/StarPromptView.tsx"], Preview: StarInvitationPreview,
|
||||
description: "controls.starInvitation.description",
|
||||
options: "controls.starInvitation.options",
|
||||
code: '<StarPromptView open={open} saving={saving} error={error} onOpenChange={setOpen} onDismissForever={dismiss} onStar={openRepository} />' },
|
||||
];
|
||||
Reference in new issue
Block a user