|
1 | | -import { IconAlert, IconInfo, IconRefresh } from "../icons"; |
| 1 | +import { useEffect, useRef, useState } from "react"; |
| 2 | +import { IconAlert, IconCheck, IconInfo, IconRefresh, IconX } from "../icons"; |
2 | 3 | import { Trans } from "../i18n/provider"; |
3 | 4 | import { Select } from "../ui"; |
4 | 5 | import { navigateHash } from "../hash-routing"; |
@@ -144,70 +145,128 @@ export function DashboardInjectionPanel({ d }: { apiBase: string; d: Dash }) { |
144 | 145 | export function DashboardMaintenancePanel({ d }: { d: Dash }) { |
145 | 146 | const { |
146 | 147 | t, runSync, syncing, updateTriggerRef, openUpdateDialog, updateLoading, updateOpen, |
147 | | - syncResult, syncError, updateJob, reconnecting, |
| 148 | + syncResult, syncError, updateJob, reconnecting, clearSyncFeedback, |
148 | 149 | } = d; |
149 | 150 |
|
| 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 | + |
150 | 201 | 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> |
181 | 234 | </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 | + )} |
182 | 246 | </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 />} |
186 | 250 | <span> |
187 | 251 | {t("dash.syncOk", { count: syncResult.added })} |
188 | 252 | {syncResult.warning ? ` ${syncResult.warning}` : ""} |
189 | 253 | {syncResult.nativeSubagentDefaultsWarning ? ` ${syncResult.nativeSubagentDefaultsWarning}` : ""} |
190 | 254 | {syncResult.staleAppServerHint ? <>{" "}<Trans k="dash.syncStaleHint" cmd="ocx sync --restart-codex" /></> : null} |
191 | 255 | </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> |
192 | 259 | </div> |
193 | 260 | )} |
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"> |
196 | 263 | <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> |
197 | 267 | </div> |
198 | 268 | )} |
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 | + </> |
211 | 270 | ); |
212 | 271 | } |
213 | 272 |
|
|
0 commit comments