feat: undo toast after clearing history or summary#44
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 7 |
| Duplication | 2 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull request overview
This PR adds a lightweight “Undo” safety net after destructive “clear” actions in the extension popup, so users can quickly restore cleared search history or Gemini summaries without an extra confirmation modal.
Changes:
- Introduces
DOMUtils.showUndoToast(message, onUndo)as a singleton, auto-dismissing undo toast with an action button. - Updates history and Gemini summary “clear” flows to capture the pre-clear data and restore it on Undo (only when non-empty).
- Adds styling + i18n strings for the toast, and expands Jest coverage for toast behavior and both undo flows.
Reviewed changes
Copilot reviewed 8 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/setup.js | Adds DOMUtils.showUndoToast mock for component tests. |
| tests/history.test.js | Tests undo offering/restoration for clearing history and “no toast when empty”. |
| tests/gemini.test.js | Tests undo offering/restoration for clearing summaries and “no toast when empty”. |
| tests/dom.test.js | Adds unit tests for DOMUtils.showUndoToast rendering, click behavior, auto-dismiss, singleton replacement. |
| scss/popup.scss | Adds .undo-toast and .undo-toast-btn styling. |
| Package/dist/utils/dom.js | Implements DOMUtils.showUndoToast with singleton + 6s auto-dismiss. |
| Package/dist/components/history.js | Adds undo-after-clear behavior for history (captures list before clearing). |
| Package/dist/components/gemini.js | Adds undo-after-clear behavior for summaries (captures summaryList + timestamp before clearing). |
| Package/css/popup.css | Rebuilt CSS output including undo toast styles. |
| Package/css/popup.css.map | Rebuilt source map output for the CSS rebuild. |
| Package/_locales/zh_TW/messages.json | Adds undo/cleared toast i18n keys; includes other message text adjustments. |
| Package/_locales/ja/messages.json | Adds undo/cleared toast i18n keys; includes other message text adjustments. |
| Package/_locales/en/messages.json | Adds undo/cleared toast i18n keys; includes other message text adjustments. |
Files not reviewed (1)
- Package/css/popup.css: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a5991f8bd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| state.hasHistory = false; | ||
|
|
||
| // Send a message to background.js to request clearing of selected text list data | ||
| chrome.runtime.sendMessage({ action: "clearSearchHistoryList" }); |
There was a problem hiding this comment.
Avoid clearing history again after Undo
When the background service worker is cold or slow to handle this message, a user can click the new Undo toast before clearSearchHistoryList is processed; the popup then restores searchHistoryList, but the background handler in Package/dist/background.js still responds by writing { searchHistoryList: [] } afterward, making Undo appear to succeed and then erasing the restored history. The popup already clears storage above, so this duplicate async clear needs to be removed or sequenced with the undo flow.
Useful? React with 👍 / 👎.
Clearing the search history or the Gemini summary was instant and irreversible — one click destroyed data with no confirmation and no way back. - DOMUtils.showUndoToast(message, onUndo): single-instance toast at the bottom of the popup with an Undo button, auto-dismisses after 6s - history: capture the list before clearing; Undo writes it back (popup.js's storage.onChanged listener re-renders the list) and restores the button/empty-message state - gemini: capture summaryList + timestamp before clearing; Undo writes them back and re-renders via clearExpiredSummary - no toast when there was nothing to clear - new locale keys (en/ja/zh_TW): undoLabel, historyClearedMsg, summaryClearedMsg; toast styles added to popup.scss (popup.css rebuilt via npm run build:css) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHTr9jh2Y9e5pkRAQwuBhx
3a5991f to
8f00d7a
Compare
問題
清空搜尋紀錄/摘要是一鍵不可逆:沒有確認、沒有復原,誤觸就直接失去資料。(匯入覆蓋的問題已由 60a6bfd 的合併式匯入解決,本 PR 補上另一半:清空的安全網。)
實作
DOMUtils.showUndoToast(message, onUndo):popup 底部置中的單例 toast,含「復原」按鈕,6 秒自動消失(業界標準的輕量 undo 模式,不打斷操作)history.js):清空前先讀出清單;按復原寫回 storage——popup.js 既有的storage.onChanged監聽器會自動重繪列表,並恢復按鈕/空狀態gemini.js):清空前保留summaryList+timestamp;復原後寫回並經clearExpiredSummary重繪popup.scss並以npm run build:css重建(deep/dark 主題皆為深底白字,無需分支)測試
全部 21 套件 / 1262 個測試通過(新增 8 個):toast 渲染/復原回呼/自動消失/單例取代,以及兩個清空流程的「復原還原 storage」與「空清單不顯示」。
🤖 Generated with Claude Code
https://claude.ai/code/session_01HHTr9jh2Y9e5pkRAQwuBhx
Generated by Claude Code