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

+31
View File
@@ -22,6 +22,7 @@ import { ExpandableText } from "@/components/ui/expandable-text";
import { StreamingLabelSheen } from "@/components/ui/streaming-label-sheen";
import { LoadingRing } from "@/components/ui/loading-ring";
import { ImageViewport } from "@/components/ui/image-viewport";
import { ToastProvider, useToast } from "@/components/ui/toast";
import type { CodexFastMode } from "@/lib/types";
import { Sample, type ComponentExample } from "./example";
import { useGalleryTranslation } from "./i18n";
@@ -168,6 +169,33 @@ function Alerts() {
</div>;
}
function ToastActions() {
const { t } = useGalleryTranslation();
const show = useToast();
const [removed, setRemoved] = useState(false);
const remove = () => {
setRemoved(true);
show?.({
tone: "pending",
message: t("controls.toast.pending"),
action: {
label: t("toast.undo", { ns: "common" }),
run: () => {
setRemoved(false);
show?.({ tone: "success", message: t("controls.toast.restored") });
},
},
onExpire: () => setRemoved(false),
});
};
return <div className="flex flex-wrap gap-3">
<Button variant="outline" onClick={() => show?.({ tone: "error", message: t("controls.toast.error"), dedupeKey: "example-error" })}>
{t("controls.toast.showError")}
</Button>
<Button variant="destructive" onClick={remove} disabled={removed}>{t("controls.alert.remove")}</Button>
</div>;
}
function Sheets() {
const { t } = useGalleryTranslation();
return <Sheet><SheetTrigger asChild><Button variant="outline">{t("controls.sheet.open")}</Button></SheetTrigger>
@@ -306,6 +334,9 @@ export const foundationExamples: ComponentExample[] = [
{ title: "controls.alert.title", files: ["alert-dialog"], Preview: Alerts,
description: "controls.alert.description", options: "controls.alert.options",
code: '<Button onClick={() => setOpen(true)}>Remove</Button>\n<AlertDialog open={open} onOpenChange={setOpen}>\n <AlertDialogContent><AlertDialogTitle>Remove item?</AlertDialogTitle><AlertDialogDescription>This removes the item.</AlertDialogDescription><AlertDialogCancel>Cancel</AlertDialogCancel><AlertDialogAction onClick={removeItem}>Remove</AlertDialogAction></AlertDialogContent>\n</AlertDialog>' },
{ title: "controls.toast.title", files: ["toast"], Preview: () => <ToastProvider><ToastActions /></ToastProvider>,
description: "controls.toast.description", options: "controls.toast.options",
code: '<ToastProvider><ExampleActions /></ToastProvider>\n\n// Inside ExampleActions\nconst show = useToast();\nshow?.({ tone: "pending", message: "Example will be removed.",\n action: { label: "Undo", run: restoreExample }, onExpire: removeExample });' },
{ title: "controls.sheet.title", files: ["sheet"], Preview: Sheets,
description: "controls.sheet.description", options: "controls.sheet.options",
code: '<Sheet><SheetTrigger asChild><Button>Details</Button></SheetTrigger><SheetContent side="right"><SheetTitle>Details</SheetTitle><SheetDescription>Additional information.</SheetDescription>{content}</SheetContent></Sheet>' },
@@ -106,6 +106,15 @@
"removed": "Example removed.",
"available": "Example available."
},
"toast": {
"title": "Toasts",
"description": "Short notices for errors, success, and actions you can undo.",
"options": "Mount ToastProvider and call useToast to show a notice. An optional action gives the user more time to respond.",
"showError": "Show error",
"error": "Could not save the example.",
"pending": "Example will be removed.",
"restored": "Example restored."
},
"sheet": {
"title": "Side panels",
"description": "A modal panel attached to an edge of the viewport.",
@@ -106,6 +106,15 @@
"removed": "Ejemplo eliminado.",
"available": "Ejemplo disponible."
},
"toast": {
"title": "Avisos temporales",
"description": "Avisos breves de errores, acciones completadas y acciones que se pueden deshacer.",
"options": "Monta ToastProvider y usa useToast para mostrar un aviso. Una acción opcional da más tiempo para responder.",
"showError": "Mostrar error",
"error": "No se pudo guardar el ejemplo.",
"pending": "Se eliminará el ejemplo.",
"restored": "Ejemplo restaurado."
},
"sheet": {
"title": "Paneles laterales",
"description": "Un panel modal unido a un borde del área visible.",
@@ -106,6 +106,15 @@
"removed": "Exemple retiré.",
"available": "Exemple disponible."
},
"toast": {
"title": "Notifications temporaires",
"description": "De courtes notifications pour les erreurs, les réussites et les actions réversibles.",
"options": "Montez ToastProvider et utilisez useToast pour afficher une notification. Une action facultative laisse plus de temps pour réagir.",
"showError": "Afficher une erreur",
"error": "Impossible d’enregistrer l’exemple.",
"pending": "L’exemple va être supprimé.",
"restored": "L’exemple a été rétabli."
},
"sheet": {
"title": "Panneaux latéraux",
"description": "Un panneau modal attaché à un bord de la zone d’affichage.",
@@ -106,6 +106,15 @@
"removed": "Contoh dihapus.",
"available": "Contoh tersedia."
},
"toast": {
"title": "Notifikasi singkat",
"description": "Notifikasi singkat untuk kesalahan, keberhasilan, dan tindakan yang dapat dibatalkan.",
"options": "Pasang ToastProvider dan gunakan useToast untuk menampilkan notifikasi. Tindakan opsional memberi waktu lebih lama untuk merespons.",
"showError": "Tampilkan kesalahan",
"error": "Contoh tidak dapat disimpan.",
"pending": "Contoh akan dihapus.",
"restored": "Contoh dipulihkan."
},
"sheet": {
"title": "Panel samping",
"description": "Panel modal yang menempel pada tepi area tampilan.",
@@ -106,6 +106,15 @@
"removed": "サンプルを削除しました。",
"available": "サンプルは利用可能です。"
},
"toast": {
"title": "トースト通知",
"description": "エラー、成功、取り消せる操作を短く知らせます。",
"options": "ToastProvider を配置し、useToast を使って通知を表示します。操作ボタン付きの通知は長めに表示されます。",
"showError": "エラーを表示",
"error": "サンプルを保存できませんでした。",
"pending": "サンプルを削除します。",
"restored": "サンプルを復元しました。"
},
"sheet": {
"title": "サイドパネル",
"description": "表示領域の端に配置するモーダルパネル。",
@@ -106,6 +106,15 @@
"removed": "예제를 제거했습니다.",
"available": "예제를 사용할 수 있습니다."
},
"toast": {
"title": "토스트 알림",
"description": "오류, 성공, 실행 취소가 가능한 작업을 짧게 알립니다.",
"options": "ToastProvider를 마운트한 뒤 useToast를 사용해 알림을 표시합니다. 작업 버튼이 있는 알림은 더 오래 표시됩니다.",
"showError": "오류 표시",
"error": "예제를 저장하지 못했습니다.",
"pending": "예제가 삭제될 예정입니다.",
"restored": "예제를 복원했습니다."
},
"sheet": {
"title": "측면 패널",
"description": "표시 영역의 가장자리에 붙는 모달 패널입니다.",
@@ -106,6 +106,15 @@
"removed": "Exemplo removido.",
"available": "Exemplo disponível."
},
"toast": {
"title": "Avisos temporários",
"description": "Avisos breves de erros, sucessos e ações que podem ser desfeitas.",
"options": "Monte ToastProvider e use useToast para exibir um aviso. Uma ação opcional dá mais tempo para responder.",
"showError": "Mostrar erro",
"error": "Não foi possível salvar o exemplo.",
"pending": "O exemplo será removido.",
"restored": "Exemplo restaurado."
},
"sheet": {
"title": "Painéis laterais",
"description": "Um painel modal ligado a uma borda da área visível.",
@@ -106,6 +106,15 @@
"removed": "Đã xóa ví dụ.",
"available": "Ví dụ khả dụng."
},
"toast": {
"title": "Thông báo tạm thời",
"description": "Thông báo ngắn về lỗi, thành công và thao tác có thể hoàn tác.",
"options": "Gắn ToastProvider và dùng useToast để hiện thông báo. Nếu có nút thao tác, thông báo sẽ hiện lâu hơn.",
"showError": "Hiện lỗi",
"error": "Không thể lưu ví dụ.",
"pending": "Ví dụ sẽ bị xóa.",
"restored": "Đã khôi phục ví dụ."
},
"sheet": {
"title": "Bảng bên",
"description": "Bảng dạng hộp thoại gắn vào một cạnh vùng hiển thị.",
@@ -106,6 +106,15 @@
"removed": "示例已移除。",
"available": "示例可用。"
},
"toast": {
"title": "轻提示",
"description": "简短提示错误、成功或可撤销操作。",
"options": "挂载 ToastProvider,然后调用 useToast 显示提示。带操作的提示会停留更久,方便用户响应。",
"showError": "显示错误",
"error": "无法保存示例。",
"pending": "即将移除示例。",
"restored": "已恢复示例。"
},
"sheet": {
"title": "侧边面板",
"description": "贴靠视口边缘的模态面板。",
@@ -106,6 +106,15 @@
"removed": "已移除範例。",
"available": "範例可供使用。"
},
"toast": {
"title": "浮動提示",
"description": "簡短提示錯誤、成功或可復原的操作。",
"options": "掛載 ToastProvider,再呼叫 useToast 顯示提示。附帶操作的提示會停留較久,方便使用者回應。",
"showError": "顯示錯誤",
"error": "無法儲存範例。",
"pending": "即將移除範例。",
"restored": "已還原範例。"
},
"sheet": {
"title": "側邊面板",
"description": "貼靠檢視區邊緣的模態面板。",