Skip to content

feat(tabs): undo for closing a query tab (#747) - #818

Open
Asgabani wants to merge 1 commit into
libredb:mainfrom
Asgabani:feat/undo-close-tab
Open

feat(tabs): undo for closing a query tab (#747)#818
Asgabani wants to merge 1 commit into
libredb:mainfrom
Asgabani:feat/undo-close-tab

Conversation

@Asgabani

Copy link
Copy Markdown

Closes #747.

What changed

closeTab (src/hooks/use-tab-manager.ts) dropped the closed tab's state immediately, so a misclick on the close icon lost an unsaved query with no recovery. It now:

  • Captures the closed tab (its full QueryTab — query text, name, type — and its original index) in a ref before removing it.
  • Shows a toast (sonner, matching the existing showStarPromptToast pattern) with an "Undo" action.
  • reopenLastClosedTab() splices the tab back into its original position and makes it active again.

Deliberately only the single most-recently-closed tab is recoverable — closing a second tab before undoing the first drops the first. That matches the issue's framing (recovering from an immediate misclick, not a multi-level history) and keeps the implementation to one ref rather than a stack.

No confirmation step was added to the close action itself, per the issue's explicit constraint ("closing a tab is a frequent, usually intentional action").

Testing

Ran locally (bun run format && bun run lint && bun run typecheck && bun run knip && bun run chart:check && bun run channels:showcase:check && bun run readme:check && bun run security:check && bun run test && bun run build, plus bun run build:lib && bun run attw since useTabManager is reachable from the embeddable workspace export surface):

  • format / lint / typecheck / knip: clean. Lint warning count unchanged from a clean checkout (189).
  • All four drift guards (chart, channels showcase, readme, security): pass.
  • bun run test:components: 39/39 groups pass.
  • bun run test: same 13 pre-existing failures as a clean checkout (Helm binary not installed, missing built standalone zip). No live Postgres/MySQL in this sandbox.
  • bun run test:coverage && bun run coverage:check: 100.00% line coverage on the merged lcov.
  • bun run build, bun run build:lib, bun run attw: all succeed.

If CI surfaces something this sandbox couldn't (Helm chart tests, live DB integration tests), happy to fix it up.

closeTab dropped a tab's query and name with no way back — a misclick
on the close icon lost unsaved work outright. closeTab now keeps the
just-closed tab (query, name, position) and offers a toast with an
Undo action that restores it and makes it active again. Only the most
recent close is recoverable; the close action itself stays
confirmation-free per the issue's explicit constraint.
@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closing a tab loses its query with no way to undo it

1 participant