fix(webui): make action feedback easier to notice (#6702)

* fix(webui): make action feedback easier to notice

* fix(webui): preserve undo and report confirmed action results

* refactor(webui): trim toast preview and redundant coverage

* test(webui): advance the undo window for the last topic deletion
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-18 16:10:02 +08:00
1 parent 0f45d74fec
commit 9ccf3b6214
59 files changed
+1621 -508

No files matched your search

@@ -332,6 +332,7 @@ export function SettingsPage({
}}
onDeleteConfiguration={(preset, onDeleted) => {
presetDeletedCallback.current = onDeleted;
modelState.setModelPresetDeleteError(null);
modelState.setModelPresetPendingDelete(preset);
}}
/>
@@ -604,9 +605,13 @@ export function SettingsPage({
onAction={systemActions.handleAutomationAction}
onRequestEdit={(job) => {
setAutomationDetailReturn(null);
systemState.setAutomationDialogError(null);
systemState.setAutomationPendingEdit(job);
}}
onRequestDelete={systemState.setAutomationPendingDelete}
onRequestDelete={(job) => {
systemState.setAutomationDialogError(null);
systemState.setAutomationPendingDelete(job);
}}
onChangeChat={systemActions.handleAutomationChat}
onManageModels={() => selectSection("models")}
returnToDetailJob={automationDetailReturn}
@@ -669,6 +674,7 @@ export function SettingsPage({
<ModelPresetDeleteDialog
preset={modelState.modelPresetPendingDelete}
deleting={modelState.saving}
error={modelState.modelPresetPendingDelete ? modelState.modelPresetDeleteError : null}
onOpenChange={(open) => {
if (!open) {
modelState.setModelPresetPendingDelete(null);
@@ -728,6 +734,7 @@ export function SettingsPage({
<AutomationDeleteDialog
job={systemState.automationPendingDelete}
deleting={systemState.automationAction === `delete:${systemState.automationPendingDelete?.id ?? ""}`}
error={systemState.automationPendingDelete ? systemState.automationDialogError : null}
onOpenChange={(open) => {
if (!open) systemState.setAutomationPendingDelete(null);
}}
@@ -737,6 +744,7 @@ export function SettingsPage({
<AutomationEditDialog
job={systemState.automationPendingEdit}
saving={systemState.automationAction === `update:${systemState.automationPendingEdit?.id ?? ""}`}
error={systemState.automationPendingEdit ? systemState.automationDialogError : null}
onOpenChange={(open) => {
if (!open) systemState.setAutomationPendingEdit(null);
}}
@@ -149,11 +149,13 @@ export function agentDraftFromPayload(
export function ModelPresetDeleteDialog({
preset,
deleting,
error,
onOpenChange,
onConfirm,
}: {
preset: SettingsPayload["model_presets"][number] | null;
deleting: boolean;
error?: string | null;
onOpenChange: (open: boolean) => void;
onConfirm: () => void;
}) {
@@ -161,8 +163,8 @@ export function ModelPresetDeleteDialog({
const tx = (key: string, fallback: string, values?: Record<string, unknown>) =>
t(key, { defaultValue: fallback, ...(values ?? {}) });
return (
<Dialog open={preset !== null} onOpenChange={onOpenChange}>
<DialogContent className="max-w-[440px]">
<Dialog open={preset !== null} onOpenChange={(open) => { if (open || !deleting) onOpenChange(open); }}>
<DialogContent showCloseButton={!deleting} className="max-w-[440px]">
<DialogHeader className="text-left">
<DialogTitle>
{tx("settings.models.deletePresetTitle", "Delete model preset?")}
@@ -175,6 +177,7 @@ export function ModelPresetDeleteDialog({
)}
</DialogDescription>
</DialogHeader>
{error ? <p role="alert" className="break-words text-sm text-destructive">{error}</p> : null}
<DialogFooter>
<Button
type="button"
@@ -17,6 +17,7 @@ import {
} from "@/components/settings/models/providerForm";
import type { ModelSettingsState } from "@/components/settings/models/useModelSettingsState";
import { normalizeContextWindowTokens } from "@/components/settings/shared/ModelControls";
import { useToast } from "@/components/ui/toast";
import {
ApiError,
cancelProviderOAuth,
@@ -86,6 +87,7 @@ export function useModelSettingsActions({
installCapabilities,
configuredModelProviderOptions,
}: ModelSettingsActionsOptions) {
const showToast = useToast();
const oauthMounted = useRef(true);
useEffect(() => {
oauthMounted.current = true;
@@ -117,6 +119,7 @@ export function useModelSettingsActions({
setModelPresetEditingName,
setModelPresetNameError,
setModelPresetPendingDelete,
setModelPresetDeleteError,
setProviderForms,
setProviderOAuthCompleting,
setProviderOAuthDialogError,
@@ -392,7 +395,15 @@ export function useModelSettingsActions({
setError(null);
} catch (err) {
setModelCallOrder(previousOrder);
setError((err as Error).message);
if (showToast && err instanceof ApiError && (err.status === 503 || err.status === 504)) {
showToast({
tone: "error",
message: t("message.agentActivity.updateAgentSettingsFailed"),
dedupeKey: "settings:models:call-order",
});
} else {
setError((err as Error).message);
}
} finally {
setModelCallOrderSaving(false);
}
@@ -423,14 +434,14 @@ export function useModelSettingsActions({
return false;
}
setSaving(true);
setModelPresetDeleteError(null);
try {
const payload = await deleteModelConfiguration(client, modelPresetPendingDelete.name);
applyPayload(payload, { preserveCapabilityForms: true });
setModelPresetPendingDelete(null);
setError(null);
return true;
} catch (err) {
setError((err as Error).message);
setModelPresetDeleteError(err instanceof Error ? err.message : String(err));
return false;
} finally {
setSaving(false);
@@ -25,6 +25,7 @@ export function useModelSettingsState(initialSettings: SettingsPayload | null) {
const [modelMigrationSaving, setModelMigrationSaving] = useState(false);
const [modelPresetPendingDelete, setModelPresetPendingDelete] =
useState<SettingsPayload["model_presets"][number] | null>(null);
const [modelPresetDeleteError, setModelPresetDeleteError] = useState<string | null>(null);
const modelPresetBeforeCreateRef = useRef<string | null>(null);
const [providerOperation, setProviderOperation] = useState<ProviderOperation | null>(null);
const providerSaving = providerOperation?.provider ?? null;
@@ -76,6 +77,8 @@ export function useModelSettingsState(initialSettings: SettingsPayload | null) {
setModelPresetEditingName,
setModelPresetNameError,
setModelPresetPendingDelete,
modelPresetDeleteError,
setModelPresetDeleteError,
setProviderForms,
setProviderOAuthCompleting,
setProviderOAuthDialogError,
@@ -55,8 +55,10 @@ import {
import { Input } from "@/components/ui/input";
import { SegmentedControl } from "@/components/ui/segmented-control";
import { Textarea } from "@/components/ui/textarea";
import { useToast } from "@/components/ui/toast";
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
import { useLogoFallback } from "@/hooks/useLogoFallback";
import { copyTextToClipboard } from "@/lib/clipboard";
import { isGenericRepositoryLogoUrl, logoFallbackUrls } from "@/lib/provider-brand";
import type {
CliAppInfo,
@@ -1463,17 +1465,20 @@ function CliAppReadyPanel({
onBackToChat: () => void;
}) {
const { t } = useTranslation();
const showToast = useToast();
const [copied, setCopied] = useState(false);
const prompt = t("settings.cliApps.readyPrompt", {
name: app.name,
defaultValue: "Use @{{name}} to inspect what this CLI can do.",
});
const copyPrompt = () => {
if (!navigator.clipboard) return;
void navigator.clipboard.writeText(prompt).then(() => {
setCopied(true);
const copyPrompt = async () => {
const copied = await copyTextToClipboard(prompt);
setCopied(copied);
if (copied) {
window.setTimeout(() => setCopied(false), 1400);
});
} else {
showToast?.({ tone: "error", message: t("fileActions.failed"), dedupeKey: "settings:apps:copy-prompt" });
}
};
return (
@@ -690,12 +690,14 @@ const AUTOMATION_EVERY_UNITS: Array<{ value: AutomationEveryUnit; ms: number }>
export function AutomationEditDialog({
job,
saving,
error,
onOpenChange,
onCancel,
onSave,
}: {
job: SessionAutomationJob | null;
saving: boolean;
error?: string | null;
onOpenChange: (open: boolean) => void;
onCancel?: (job: SessionAutomationJob) => void;
onSave: (job: SessionAutomationJob, values: AutomationUpdatePayload) => void | Promise<void>;
@@ -727,11 +729,13 @@ export function AutomationEditDialog({
const submit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
if (saving) return;
const payload = automationUpdatePayloadFromDraft(draft, job);
if (!job || typeof payload === "string") return;
void onSave(job, payload);
};
const changeOpen = (open: boolean) => {
if (!open && saving) return;
onOpenChange(open);
if (!open && job) onCancel?.(job);
};
@@ -745,6 +749,7 @@ export function AutomationEditDialog({
<DialogContent
{...dialogFocus}
aria-describedby={undefined}
showCloseButton={!saving}
className="w-[min(calc(100vw-2rem),34rem)]"
onEscapeKeyDown={(event) => {
// Escape in the nested date calendar must not cancel the editor.
@@ -879,6 +884,7 @@ export function AutomationEditDialog({
/>
) : null}
{error ? <AutomationError message={error} /> : null}
{validation ? (
<div id={validationId} className="rounded-control bg-destructive/8 px-3 py-2 text-[12px] text-destructive">
{validation}
@@ -910,11 +916,13 @@ export function AutomationEditDialog({
export function AutomationDeleteDialog({
job,
deleting,
error,
onOpenChange,
onConfirm,
}: {
job: SessionAutomationJob | null;
deleting: boolean;
error?: string | null;
onOpenChange: (open: boolean) => void;
onConfirm: (job: SessionAutomationJob) => void | Promise<void>;
}) {
@@ -923,8 +931,8 @@ export function AutomationDeleteDialog({
const tx = (key: string, fallback: string, values?: Record<string, unknown>) =>
t(key, { defaultValue: fallback, ...(values ?? {}) });
return (
<Dialog open={Boolean(job)} onOpenChange={onOpenChange}>
<DialogContent {...dialogFocus} className="w-[min(calc(100vw-2rem),26rem)]">
<Dialog open={Boolean(job)} onOpenChange={(open) => { if (open || !deleting) onOpenChange(open); }}>
<DialogContent {...dialogFocus} showCloseButton={!deleting} className="w-[min(calc(100vw-2rem),26rem)]">
<DialogHeader>
<DialogTitle>{tx("settings.automations.deleteTitle", "Delete automation")}</DialogTitle>
<DialogDescription>
@@ -935,6 +943,7 @@ export function AutomationDeleteDialog({
)}
</DialogDescription>
</DialogHeader>
{error ? <AutomationError message={error} /> : null}
<DialogFooter>
<Button
type="button"
@@ -11,6 +11,7 @@ import {
StatusPill,
} from "@/components/settings/shared/SettingsControls";
import { Button } from "@/components/ui/button";
import { useToast } from "@/components/ui/toast";
import { getRuntimeHost, isNativeRuntime } from "@/lib/runtime";
import type { NanobotFeatureInfo, SettingsPayload } from "@/lib/types";
@@ -38,6 +39,7 @@ export function RuntimeSettings({
onInstallCapability: (name: string) => void;
}) {
const { t } = useTranslation();
const showToast = useToast();
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
const runtimeSurface = settings.surface ?? settings.runtime_surface;
const runtimeHost = getRuntimeHost(runtimeSurface, settings.runtime_capabilities);
@@ -84,7 +86,11 @@ export function RuntimeSettings({
const result = await action();
setHostActionMessage({ target, message: successMessage(result) });
} catch {
setHostActionMessage({ target, message: failureMessage });
if (showToast) {
showToast({ tone: "error", message: failureMessage, dedupeKey: `settings:runtime:${target}` });
} else {
setHostActionMessage({ target, message: failureMessage });
}
} finally {
setHostActionBusy(null);
}
@@ -93,6 +93,7 @@ export function createSystemSettingsActions({
nanobotFeatureActionRef,
nanobotFeatures,
setAutomationAction,
setAutomationDialogError,
setAutomationPendingDelete,
setAutomationPendingEdit,
setAutomations,
@@ -230,8 +231,9 @@ export function createSystemSettingsActions({
job: SessionAutomationJob,
) => {
const key = `${action}:${job.id}`;
const reportError = action === "delete" ? setAutomationDialogError : setAutomationsError;
setAutomationAction(key);
setAutomationsError(null);
reportError(null);
try {
const payload = await runAutomationAction(client, action, job.id);
setAutomations(payload);
@@ -241,7 +243,7 @@ export function createSystemSettingsActions({
window.setTimeout(() => void refreshAutomations(false), 4000);
}
} catch (err) {
setAutomationsError((err as Error).message);
reportError(err instanceof Error ? err.message : String(err));
} finally {
setAutomationAction(null);
}
@@ -253,13 +255,13 @@ export function createSystemSettingsActions({
) => {
const key = `update:${job.id}`;
setAutomationAction(key);
setAutomationsError(null);
setAutomationDialogError(null);
try {
const payload = await updateAutomation(client, job.id, values);
setAutomations(payload);
setAutomationPendingEdit(null);
} catch (err) {
setAutomationsError((err as Error).message);
setAutomationDialogError(err instanceof Error ? err.message : String(err));
} finally {
setAutomationAction(null);
}
@@ -52,6 +52,7 @@ export function useSystemSettingsState(toolsCatalog: ToolsCatalog) {
const [mcpMessage, setMcpMessage] = useState<string | null>(null);
const [mcpError, setMcpError] = useState<string | null>(null);
const [automationsError, setAutomationsError] = useState<string | null>(null);
const [automationDialogError, setAutomationDialogError] = useState<string | null>(null);
const [automationAction, setAutomationAction] = useState<string | null>(null);
const [automationPendingDelete, setAutomationPendingDelete] =
useState<SessionAutomationJob | null>(null);
@@ -106,6 +107,8 @@ export function useSystemSettingsState(toolsCatalog: ToolsCatalog) {
setAutomationPendingEdit,
setAutomations,
setAutomationsError,
automationDialogError,
setAutomationDialogError,
setAutomationsFilter,
setAutomationsLoading,
setCliApps,