Skip to content

feat(canvas): delete a canvas with a confirm and an undo window - #3895

Draft
adamleithp wants to merge 1 commit into
mainfrom
canvas-delete-undo
Draft

feat(canvas): delete a canvas with a confirm and an undo window#3895
adamleithp wants to merge 1 commit into
mainfrom
canvas-delete-undo

Conversation

@adamleithp

@adamleithp adamleithp commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What

Adds Delete… to a canvas's menu (it had none), and puts both delete paths behind a confirm dialog + an undo window.

Screen.Recording.2026-07-28.at.19.41.59.mov
  • Canvas header menu and the canvases-grid card menu now open a quill AlertDialog ("Delete canvas") instead of deleting on click — the grid one used to delete immediately, no confirmation.
  • Confirming does not delete yet. The canvas is marked pending and the host isn't told until the "Deleted artifact" toast's timer (8s, matching the archive-undo window) expires. Undo just cancels the timer, so nothing is ever recreated.
  • Pending canvases stay in their lists rather than vanishing: the artifacts row swaps its template icon for a pulsing trash can, turns its accent red, reads "Deleting…", and stops opening. The grid card dims behind the same icon. Undo restores them in place — no re-insert, no reorder.
  • Deleting from inside a canvas navigates to the space's artifacts list. The commit therefore runs outside React (module-level timer + hostClient) so it survives that unmount.
  • If the delete fails, the pending mark clears (the canvas comes back) and an error toast explains why.

delete is only tracked when it actually commits; a cancelled one tracks the new delete_undo action type.

Files

  • deleteCanvasWithUndo.ts — the undo window: mark pending → schedule commit → toast with Undo. Re-deleting the same canvas restarts the window instead of stacking commits.
  • stores/pendingCanvasDeleteStore.ts — state-only zustand map of ids inside their window.
  • WebsiteLayout.tsx, WebsiteDashboardsIndex.tsx, WebsiteChannelArtifacts.tsx — menus, dialogs, deleting state.
  • useDashboards.ts — exposes invalidateDashboards for the out-of-React commit.

Testing

4 unit tests in deleteCanvasWithUndo.test.ts (defers the send, undo cancels outright, failure restores + toasts, re-delete restarts). Full @posthog/ui suite passes (2303).

Manually:

  1. Artifacts → canvas Delete… → confirm → row stays with a pulsing red trash icon and "Deleting…", click does nothing → Undo → back to normal in place.
  2. Same, let the toast expire → row gone once the list refreshes; reload confirms it's really deleted.
  3. Delete from inside a canvas → lands on Artifacts with that row already pulsing.
  4. Canvases grid → delete → card dims with the trash overlay → Undo restores it.
  5. Offline → confirm → after 8s the canvas reappears with "Couldn't delete canvas".

🤖 Generated with Claude Code

The canvas "…" menu had no way to delete; the canvases grid had one that
deleted on click with no confirmation.

Both now open an alert dialog, and confirming doesn't delete straight
away: the canvas is marked pending and the host isn't told until the
"Deleted artifact" toast's timer expires, so Undo simply cancels the
timer rather than recreating anything.

Pending canvases stay in their lists — the artifacts row swaps its
template icon for a pulsing trash can and stops opening, the grid card
dims behind the same icon — so undoing restores them in place.

The commit runs outside React (module-level timer + hostClient) because
deleting from inside a canvas navigates away immediately.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Jul 28, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit fc5334e.

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.

1 participant