Skip to content

Commit 80be427

Browse files
authored
Merge pull request #1050 from Wibias/codex/dashboard-sync-feedback
feat(gui): fixed action toasts for dashboard sync + model-apply feedback
2 parents 4070464 + f9fdb19 commit 80be427

14 files changed

Lines changed: 760 additions & 67 deletions

‎gui/src/i18n/de.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ export const de: Record<TKey, string> = {
258258
"dash.updateStatus.running": "opencodex wird aktualisiert.",
259259
"dash.updateStatus.restarting": "Update installiert. Proxy wird neu gestartet.",
260260
"dash.updateStatus.succeeded": "Update abgeschlossen.",
261+
"dash.updateVersionTransition": "{currentVersion} -> {latestVersion}.",
262+
261263
"dash.updateStatus.failed": "Update fehlgeschlagen.",
262264
"prov.subtitle": "Konfiguriere die Upstream-Anbieter, die opencodex in Codex routet. Melde dich mit einem Konto an, füge einen Anbieter hinzu oder bearbeite die Rohkonfiguration.",
263265
"prov.add": "Anbieter hinzufügen",

‎gui/src/i18n/en.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ export const en = {
273273
"dash.updateStatus.running": "Updating opencodex.",
274274
"dash.updateStatus.restarting": "Update installed. Restarting proxy.",
275275
"dash.updateStatus.succeeded": "Update finished.",
276+
"dash.updateVersionTransition": "{currentVersion} -> {latestVersion}.",
277+
276278
"dash.updateStatus.failed": "Update failed.",
277279

278280
// providers

‎gui/src/i18n/ja.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ export const ja: Record<TKey, string> = {
267267
"dash.updateStatus.running": "opencodex を更新しています。",
268268
"dash.updateStatus.restarting": "更新をインストールしました。プロキシを再起動中。",
269269
"dash.updateStatus.succeeded": "更新が完了しました。",
270+
"dash.updateVersionTransition": "{currentVersion} -> {latestVersion}.",
271+
270272
"dash.updateStatus.failed": "更新に失敗しました。",
271273

272274
// providers

‎gui/src/i18n/ko.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ export const ko: Record<TKey, string> = {
265265
"dash.updateStatus.running": "opencodex 업데이트 중입니다.",
266266
"dash.updateStatus.restarting": "업데이트 설치 완료. 프록시를 재시작하는 중입니다.",
267267
"dash.updateStatus.succeeded": "업데이트가 완료됐습니다.",
268+
"dash.updateVersionTransition": "{currentVersion} -> {latestVersion}.",
269+
268270
"dash.updateStatus.failed": "업데이트에 실패했습니다.",
269271

270272
// providers

‎gui/src/i18n/ru.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ export const ru: Record<TKey, string> = {
267267
"dash.updateStatus.running": "Обновление opencodex.",
268268
"dash.updateStatus.restarting": "Обновление установлено. Перезапуск прокси.",
269269
"dash.updateStatus.succeeded": "Обновление завершено.",
270+
"dash.updateVersionTransition": "{currentVersion} -> {latestVersion}.",
271+
270272
"dash.updateStatus.failed": "Обновление не удалось.",
271273

272274
// providers

‎gui/src/i18n/zh.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ export const zh: Record<TKey, string> = {
262262
"dash.updateStatus.running": "正在更新 opencodex。",
263263
"dash.updateStatus.restarting": "更新已安装。正在重启代理。",
264264
"dash.updateStatus.succeeded": "更新完成。",
265+
"dash.updateVersionTransition": "{currentVersion} -> {latestVersion}.",
266+
265267
"dash.updateStatus.failed": "更新失败。",
266268

267269
// providers

‎gui/src/pages/Models.tsx‎

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
import { Switch, Notice, EmptyState, Select, Tooltip } from "../ui";
3-
import { IconChevron, IconBoxes, IconInfo, IconShuffle } from "../icons";
3+
import { IconChevron, IconBoxes, IconInfo, IconShuffle, IconCheck, IconAlert } from "../icons";
44
import { useT } from "../i18n/shared";
55
import type { TFn, TKey } from "../i18n/shared";
66
import { modelLabel } from "../model-display";
@@ -81,6 +81,25 @@ export default function Models({ apiBase }: { apiBase: string }) {
8181
const needsDefaultCollapseRef = useRef(initialCollapsed === null);
8282
const [status, setStatus] = useState("");
8383
const [ok, setOk] = useState(false);
84+
// Feedback generation: a repeated identical message (same success string, same validation
85+
// error) must still re-arm the toast timer. Clearing `status` alone is not enough — a
86+
// second identical value bails out of React's state diff, so the old timer would dismiss
87+
// the new toast early. Every publish bumps the generation.
88+
const [feedbackGen, setFeedbackGen] = useState(0);
89+
const publishFeedback = (nextOk: boolean, message: string) => {
90+
setOk(nextOk);
91+
setStatus(message);
92+
setFeedbackGen(g => g + 1);
93+
};
94+
// Transient action feedback as a fixed toast: appearing or auto-clearing it never shifts
95+
// the workspace below (the old inline Notice pushed the whole model grid down by its
96+
// height on every apply). The timer itself just clears the status again.
97+
useEffect(() => {
98+
if (!status) return;
99+
const holdMs = ok ? 6000 : 8000;
100+
const timer = setTimeout(() => setStatus(""), holdMs);
101+
return () => clearTimeout(timer);
102+
}, [status, ok, feedbackGen]);
84103
const [busy, setBusy] = useState(false);
85104
const busyRef = useRef(false);
86105
const loadGenerationRef = useRef(0);
@@ -430,7 +449,7 @@ export default function Models({ apiBase }: { apiBase: string }) {
430449

431450
const applyCustomCap = () => {
432451
const value = Number(customCap.replace(/[_,\s]/g, ""));
433-
if (!Number.isFinite(value) || value <= 0) { setOk(false); setStatus(t("models.capSaveFailed")); return; }
452+
if (!Number.isFinite(value) || value <= 0) { publishFeedback(false, t("models.capSaveFailed")); return; }
434453
setShowCustom(false);
435454
setGlobalCap(value);
436455
};
@@ -496,7 +515,7 @@ export default function Models({ apiBase }: { apiBase: string }) {
496515
// (setMaxConcurrentThreads no-ops on equal value), so a re-selected current
497516
// value or a double click can never double-write config.toml.
498517
if (!v2 || v2BusyRef.current) return;
499-
if (!Number.isInteger(value) || value < 1) { setOk(false); setStatus(t("models.v2ThreadsInvalid")); return; }
518+
if (!Number.isInteger(value) || value < 1) { publishFeedback(false, t("models.v2ThreadsInvalid")); return; }
500519
if (v2.maxConcurrentThreadsPerSession === value) return;
501520
setV2Busy(true);
502521
v2BusyRef.current = true;
@@ -581,8 +600,7 @@ export default function Models({ apiBase }: { apiBase: string }) {
581600
try {
582601
await readJsonOrThrow(r, t("models.customSaveFailed"));
583602
setCustomModalOpen(false);
584-
setOk(true);
585-
setStatus(t("models.customAdded"));
603+
publishFeedback(true, t("models.customAdded"));
586604
await load(true);
587605
} catch (e) {
588606
setCustomError(e instanceof Error ? e.message : t("models.customSaveFailed"));
@@ -606,8 +624,7 @@ export default function Models({ apiBase }: { apiBase: string }) {
606624
try {
607625
await readJsonOrThrow(r, t("models.customSaveFailed"));
608626
setCustomModalOpen(false);
609-
setOk(true);
610-
setStatus(t("models.customUpdated"));
627+
publishFeedback(true, t("models.customUpdated"));
611628
await load(true);
612629
} catch (e) {
613630
setCustomError(e instanceof Error ? e.message : t("models.customSaveFailed"));
@@ -623,16 +640,13 @@ export default function Models({ apiBase }: { apiBase: string }) {
623640
try {
624641
const r = await fetch(`${apiBase}/api/custom-models/${encodeURIComponent(id)}`, { method: "DELETE" });
625642
if (r.ok) {
626-
setOk(true);
627-
setStatus(t("models.customDeleted"));
643+
publishFeedback(true, t("models.customDeleted"));
628644
await load(true);
629645
} else {
630-
setOk(false);
631-
setStatus(t("models.customSaveFailed"));
646+
publishFeedback(false, t("models.customSaveFailed"));
632647
}
633648
} catch {
634-
setOk(false);
635-
setStatus(t("models.networkError"));
649+
publishFeedback(false, t("models.networkError"));
636650
}
637651
};
638652

@@ -1343,7 +1357,12 @@ export default function Models({ apiBase }: { apiBase: string }) {
13431357
</div>
13441358
</div>
13451359
<p className="page-sub">{t("models.subtitle")}</p>
1346-
{status && <Notice tone={ok ? "ok" : "err"}>{status}</Notice>}
1360+
{status && (
1361+
<div className={`action-toast notice ${ok ? "notice-ok" : "notice-err"}`} role="status" aria-live="polite">
1362+
{ok ? <IconCheck /> : <IconAlert />}
1363+
<span>{status}</span>
1364+
</div>
1365+
)}
13471366
{/* Keep the last-good catalog interactive but make a failed revalidation explicit. */}
13481367
{catalogState.showError && <Notice tone="err">{t("models.loadFail")}</Notice>}
13491368
<div className="models-workspace-root" aria-busy={catalogState.refreshing || undefined}>

‎gui/src/pages/dashboard-overview-sections.tsx‎

Lines changed: 108 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { IconAlert, IconInfo, IconRefresh } from "../icons";
1+
import { useEffect, useRef, useState } from "react";
2+
import { IconAlert, IconCheck, IconInfo, IconRefresh, IconX } from "../icons";
23
import { Trans } from "../i18n/provider";
34
import { Select } from "../ui";
45
import { navigateHash } from "../hash-routing";
@@ -144,70 +145,128 @@ export function DashboardInjectionPanel({ d }: { apiBase: string; d: Dash }) {
144145
export function DashboardMaintenancePanel({ d }: { d: Dash }) {
145146
const {
146147
t, runSync, syncing, updateTriggerRef, openUpdateDialog, updateLoading, updateOpen,
147-
syncResult, syncError, updateJob, reconnecting,
148+
syncResult, syncError, updateJob, reconnecting, clearSyncFeedback,
148149
} = d;
149150

151+
// A sync result that carries actionable guidance (generic warning, native subagent
152+
// defaults override, or the stale app-server hint) is the ONLY place that warning is
153+
// visible, so it must not vanish on a timer: it stays until the next sync or an
154+
// explicit dismiss.
155+
const syncHoldsWarning = !!syncResult && (
156+
!!syncResult.warning
157+
|| !!syncResult.nativeSubagentDefaultsWarning
158+
|| !!syncResult.staleAppServerHint
159+
);
160+
161+
// Sync feedback is a transient fixed toast instead of an inline notice: the toast sits
162+
// outside the layout flow, so the result can appear without pushing the panels below
163+
// this card down by a full box height (the old notice shifted the whole dashboard on
164+
// every sync click). Plain results auto-dismiss; a new sync clears and re-arms it.
165+
// Dismissal is published to the dashboard data (clearSyncFeedback), not just a local
166+
// flag, so switching tabs and back cannot resurrect a stale result as a fresh toast.
167+
const [syncToastDismissed, setSyncToastDismissed] = useState(false);
168+
const syncToastTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
169+
170+
useEffect(() => {
171+
if (syncToastTimerRef.current) {
172+
clearTimeout(syncToastTimerRef.current);
173+
syncToastTimerRef.current = null;
174+
}
175+
if ((syncResult || syncError) && !syncHoldsWarning) {
176+
const holdMs = syncError ? 8000 : 6000;
177+
syncToastTimerRef.current = setTimeout(() => {
178+
syncToastTimerRef.current = null;
179+
setSyncToastDismissed(true);
180+
clearSyncFeedback();
181+
}, holdMs);
182+
}
183+
return () => {
184+
if (syncToastTimerRef.current) clearTimeout(syncToastTimerRef.current);
185+
};
186+
}, [syncResult, syncError, syncHoldsWarning, clearSyncFeedback]);
187+
188+
// A fresh click re-arms the toast even if the previous one was already auto-dismissed.
189+
const handleRunSync = () => {
190+
setSyncToastDismissed(false);
191+
void runSync();
192+
};
193+
194+
// Shared dismiss affordance for the sync toast: closes it locally AND clears the
195+
// dashboard-level result so it cannot remount as fresh on the next Overview visit.
196+
const dismissSyncToast = () => {
197+
setSyncToastDismissed(true);
198+
clearSyncFeedback();
199+
};
200+
150201
return (
151-
<div className="panel maintenance-panel">
152-
{/* Same one-row chrome as Sub-agent delegation: copy left, action right. */}
153-
<div className="dash-sync-summary">
154-
<div className="dash-sync-copy">
155-
<div className="font-semibold">{t("dash.syncModels")}</div>
156-
<div className="muted text-control dash-sync-hint">{t("dash.syncModelsHint")}</div>
157-
</div>
158-
<div className="maintenance-actions">
159-
<button type="button" className="btn btn-ghost btn-sm" onClick={runSync} disabled={syncing}>
160-
<IconRefresh /> {syncing ? t("dash.syncing") : t("dash.syncRun")}
161-
</button>
162-
{/*
163-
The update flow lives in the sidebar footer, which reports whether one is waiting
164-
and is reachable from every page. A second button here duplicated it without
165-
adding that signal. The trigger stays as a zero-size anchor so the deep link
166-
(`#dashboard/update`) still has something to open against and the dialog has a
167-
focus target to return to on close.
168-
*/}
169-
<button
170-
ref={updateTriggerRef}
171-
type="button"
172-
className="maintenance-update-anchor"
173-
onClick={openUpdateDialog}
174-
disabled={updateLoading}
175-
aria-haspopup="dialog"
176-
aria-controls="dashboard-update-dialog"
177-
aria-expanded={updateOpen}
178-
aria-label={t("dash.checkUpdate")}
179-
tabIndex={-1}
180-
/>
202+
<>
203+
<div className="panel maintenance-panel">
204+
{/* Same one-row chrome as Sub-agent delegation: copy left, action right. */}
205+
<div className="dash-sync-summary">
206+
<div className="dash-sync-copy">
207+
<div className="font-semibold">{t("dash.syncModels")}</div>
208+
<div className="muted text-control dash-sync-hint">{t("dash.syncModelsHint")}</div>
209+
</div>
210+
<div className="maintenance-actions">
211+
<button type="button" className="btn btn-ghost btn-sm" onClick={handleRunSync} disabled={syncing}>
212+
<IconRefresh className={syncing ? "spin-icon" : undefined} /> {syncing ? t("dash.syncing") : t("dash.syncRun")}
213+
</button>
214+
{/*
215+
The update flow lives in the sidebar footer, which reports whether one is waiting
216+
and is reachable from every page. A second button here duplicated it without
217+
adding that signal. The trigger stays as a zero-size anchor so the deep link
218+
(`#dashboard/update`) still has something to open against and the dialog has a
219+
focus target to return to on close.
220+
*/}
221+
<button
222+
ref={updateTriggerRef}
223+
type="button"
224+
className="maintenance-update-anchor"
225+
onClick={openUpdateDialog}
226+
disabled={updateLoading}
227+
aria-haspopup="dialog"
228+
aria-controls="dashboard-update-dialog"
229+
aria-expanded={updateOpen}
230+
aria-label={t("dash.checkUpdate")}
231+
tabIndex={-1}
232+
/>
233+
</div>
181234
</div>
235+
{updateJob && (
236+
<div className={`notice ${updateJob.status === "failed" ? "notice-err" : "notice-ok"} maintenance-notice`} role="status">
237+
{updateJob.status === "failed" ? <IconAlert /> : <IconRefresh />}
238+
<span>
239+
{updateJobLabel(updateJob.status, t)}
240+
{updateJob.latestVersion ? ` ${t("dash.updateVersionTransition", { currentVersion: updateJob.currentVersion, latestVersion: updateJob.latestVersion })}` : ""}
241+
{reconnecting ? ` ${t("dash.updateReconnecting")}` : ""}
242+
{updateJob.error ? ` ${updateJob.error}` : ""}
243+
</span>
244+
</div>
245+
)}
182246
</div>
183-
{syncResult && (
184-
<div className={`notice ${syncResult.nativeSubagentDefaultsWarning ? "notice-warn" : "notice-ok"} maintenance-notice`} role="status">
185-
{syncResult.nativeSubagentDefaultsWarning ? <IconAlert /> : <IconRefresh />}
247+
{!syncToastDismissed && syncResult && (
248+
<div className={`action-toast notice ${syncHoldsWarning ? "notice-warn" : "notice-ok"}`} role="status" aria-live="polite">
249+
{syncHoldsWarning ? <IconAlert /> : <IconCheck />}
186250
<span>
187251
{t("dash.syncOk", { count: syncResult.added })}
188252
{syncResult.warning ? ` ${syncResult.warning}` : ""}
189253
{syncResult.nativeSubagentDefaultsWarning ? ` ${syncResult.nativeSubagentDefaultsWarning}` : ""}
190254
{syncResult.staleAppServerHint ? <>{" "}<Trans k="dash.syncStaleHint" cmd="ocx sync --restart-codex" /></> : null}
191255
</span>
256+
<button type="button" className="action-toast-dismiss" onClick={dismissSyncToast} aria-label={t("api.dismiss")}>
257+
<IconX width={13} height={13} aria-hidden="true" />
258+
</button>
192259
</div>
193260
)}
194-
{syncError && (
195-
<div className="notice notice-err maintenance-notice" role="status">
261+
{!syncToastDismissed && syncError && (
262+
<div className="action-toast notice notice-err" role="status" aria-live="polite">
196263
<IconAlert /><span>{t("dash.syncFailed", { error: syncError })}</span>
264+
<button type="button" className="action-toast-dismiss" onClick={dismissSyncToast} aria-label={t("api.dismiss")}>
265+
<IconX width={13} height={13} aria-hidden="true" />
266+
</button>
197267
</div>
198268
)}
199-
{updateJob && (
200-
<div className={`notice ${updateJob.status === "failed" ? "notice-err" : "notice-ok"} maintenance-notice`} role="status">
201-
{updateJob.status === "failed" ? <IconAlert /> : <IconRefresh />}
202-
<span>
203-
{updateJobLabel(updateJob.status, t)}
204-
{updateJob.latestVersion ? ` ${updateJob.currentVersion} -> ${updateJob.latestVersion}.` : ""}
205-
{reconnecting ? ` ${t("dash.updateReconnecting")}` : ""}
206-
{updateJob.error ? ` ${updateJob.error}` : ""}
207-
</span>
208-
</div>
209-
)}
210-
</div>
269+
</>
211270
);
212271
}
213272

‎gui/src/pages/use-dashboard-data.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useMemo, useRef, useState } from "react";
1+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
import { useKeyedClientResource } from "../client-resource";
33
import { replaceHash } from "../hash-routing";
44
import { useI18n } from "../i18n/shared";
@@ -589,6 +589,15 @@ export function useDashboardData(apiBase: string) {
589589
}
590590
};
591591

592+
// Clears the sync result/error in this hook. The dashboard toast owns its own dismissal
593+
// timer but must publish the dismissal here: syncResult/syncError live above the dashboard
594+
// tabs, so a component-local flag alone would let a stale result remount as a fresh toast
595+
// after the Overview panel unmounts and comes back.
596+
const clearSyncFeedback = useCallback(() => {
597+
setSyncResult(null);
598+
setSyncError(null);
599+
}, []);
600+
592601
const runSync = async () => {
593602
if (syncing) return;
594603
setSyncing(true);
@@ -737,7 +746,7 @@ export function useDashboardData(apiBase: string) {
737746
effortCapHelpTriggerRef, updateTriggerRef, maHelpTriggerRef, shadowCallHelpTriggerRef,
738747
effortCapHelpDialogRef, updateDialogRef, maHelpDialogRef, shadowCallHelpDialogRef,
739748
filteredGroups, sidecarModels,
740-
saveSidecar, saveShadowCall, switchMaMode, toggleCodexAutoStart, runSync,
749+
saveSidecar, saveShadowCall, switchMaMode, toggleCodexAutoStart, runSync, clearSyncFeedback,
741750
fetchUpdateCheck, closeUpdateDialog, openUpdateDialog, changeUpdateChannel, runUpdate,
742751
};
743752
}

0 commit comments

Comments
 (0)