From 871333e80215dc460fe46d6f01083d85c2e0da3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Mon, 23 Nov 2026 09:30:56 +0000 Subject: [PATCH] fix(studio): a delete's toast names the undo key, as the ripple toast does (#8571) --- .../studio/src/hooks/useElementLifecycleOps.ts | 11 +++-------- .../src/hooks/useTimelineDeleteOps.test.tsx | 17 +++++++++++++++++ .../studio/src/hooks/useTimelineDeleteOps.ts | 7 ++----- packages/studio/src/utils/studioHelpers.test.ts | 11 +++++++++++ packages/studio/src/utils/studioHelpers.ts | 5 +++++ 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/packages/studio/src/hooks/useElementLifecycleOps.ts b/packages/studio/src/hooks/useElementLifecycleOps.ts index d117c590f6..ef2fea0f8d 100644 --- a/packages/studio/src/hooks/useElementLifecycleOps.ts +++ b/packages/studio/src/hooks/useElementLifecycleOps.ts @@ -32,6 +32,7 @@ import { domEditCommitDeclined, type DomEditCommitOutcome } from "./domEditCommi import { cutoverCommittedOrThrow, type CutoverResult } from "../utils/sdkCutover"; import { studioWriteHeaders } from "../utils/studioFileVersion"; import { studioApiFetch } from "../utils/studioApiFetch"; +import { deletedNotice } from "../utils/studioHelpers"; interface UseElementLifecycleOpsParams extends DomEditCommitBaseParams { /** Route delete through SDK when session resolves the hf-id. */ @@ -145,10 +146,7 @@ export function useElementLifecycleOps({ if (allHandled) { clearDomSelection(); usePlayerStore.getState().setSelectedElementId(null); - showToast( - `Deleted ${label}. Use Undo to restore ${sameFile.length === 1 ? "it" : "them"}.`, - "info", - ); + showToast(deletedNotice(label, sameFile.length), "info"); return { ok: true } as const; } } @@ -209,10 +207,7 @@ export function useElementLifecycleOps({ forceReloadSdkSession?.(); reloadPreview(); for (const member of sameFile) onElementDeleted?.(member); - showToast( - `Deleted ${label}. Use Undo to restore ${sameFile.length === 1 ? "it" : "them"}.`, - "info", - ); + showToast(deletedNotice(label, sameFile.length), "info"); return { ok: true } as const; } catch (error) { const message = error instanceof Error ? error.message : "Failed to delete element"; diff --git a/packages/studio/src/hooks/useTimelineDeleteOps.test.tsx b/packages/studio/src/hooks/useTimelineDeleteOps.test.tsx index b0c6161089..a869ffc359 100644 --- a/packages/studio/src/hooks/useTimelineDeleteOps.test.tsx +++ b/packages/studio/src/hooks/useTimelineDeleteOps.test.tsx @@ -14,6 +14,7 @@ import { useTimelineTrimRipple } from "./useTimelineTrimRipple"; import { persistTimelineMoveEditsAtomically } from "./timelineMoveAdapter"; import { persistMoveEdits, type DragCommitDeps } from "../player/components/timelineClipDragCommit"; import { LANE_OVERLAP_NOTICE } from "../player/components/timelineCollision"; +import { keyHint } from "../player/components/studioShortcuts"; installReactActEnvironment(); @@ -119,6 +120,22 @@ describe("useTimelineDeleteOps: ripple undo label", () => { }); }); + it("a delete that lands names the clip and the undo key, as the ripple toast does", async () => { + const showToast = vi.fn(); + const { b, getHook } = mountDeleteHarness({ + handleTimelineGroupMove: vi.fn().mockResolvedValue(undefined), + showToast, + }); + + await act(async () => { + await getHook().handleTimelineElementDelete(b); + }); + + const undo = keyHint("undo"); + expect(showToast.mock.calls[0]).toEqual([`Deleted hf-b. Undo (${undo}) restores it.`, "info"]); + expect(showToast.mock.calls[1]?.[0]).toContain(`Undo (${undo}) restores it`); + }); + // editHistory.ts's coalescing keeps the LAST recordEdit call's label, so the // folded ripple move must carry the delete's label, not its own. it("passes the delete's own label to the folded ripple move, not 'Move timeline clips'", async () => { diff --git a/packages/studio/src/hooks/useTimelineDeleteOps.ts b/packages/studio/src/hooks/useTimelineDeleteOps.ts index 63a5d37fb0..6d8d874d61 100644 --- a/packages/studio/src/hooks/useTimelineDeleteOps.ts +++ b/packages/studio/src/hooks/useTimelineDeleteOps.ts @@ -8,7 +8,7 @@ import type { TimelineElement } from "../player"; import { usePlayerStore } from "../player"; import { saveServerRewriteWithHistory, type RecordEditInput } from "../utils/studioFileHistory"; import { studioWriteHeaders } from "../utils/studioFileVersion"; -import { getTimelineElementLabel } from "../utils/studioHelpers"; +import { deletedNotice, getTimelineElementLabel } from "../utils/studioHelpers"; import { buildPatchTarget, removeIframeTimelineElements, @@ -251,10 +251,7 @@ export function useTimelineDeleteOps({ // A failed ripple already showed its own toast above; the user did one // thing (delete), so they get one message, not this generic follow-up too. if (!rippleFailed) { - showToast( - `Deleted ${label}. Use Undo to restore ${sameFile.length === 1 ? "it" : "them"}.`, - "info", - ); + showToast(deletedNotice(label, sameFile.length), "info"); } if (rippleChanges && !rippleFailed && !rippleNoticeShownRef.current) { rippleNoticeShownRef.current = true; diff --git a/packages/studio/src/utils/studioHelpers.test.ts b/packages/studio/src/utils/studioHelpers.test.ts index 17984db3b1..cffbd6f266 100644 --- a/packages/studio/src/utils/studioHelpers.test.ts +++ b/packages/studio/src/utils/studioHelpers.test.ts @@ -1,7 +1,9 @@ // @vitest-environment happy-dom import { afterEach, describe, expect, it, vi } from "vitest"; +import { keyHint } from "../player/components/studioShortcuts"; import { + deletedNotice, historyTooltipLabel, findMatchingTimelineElementId, findTimelineIdByAncestor, @@ -19,6 +21,15 @@ afterEach(() => { vi.restoreAllMocks(); }); +describe("deletedNotice", () => { + it("names what went and the undo key, as the ripple toast does", () => { + const undo = keyHint("undo"); + expect(deletedNotice("Title", 1)).toBe(`Deleted Title. Undo (${undo}) restores it.`); + expect(deletedNotice("3 clips", 3)).toBe(`Deleted 3 clips. Undo (${undo}) restores them.`); + expect(undo).not.toBe(""); + }); +}); + describe("resolveTimelineSelectionSeekTime", () => { it("keeps the current time when it is already inside the clip range", () => { expect(resolveTimelineSelectionSeekTime(3, { start: 0, duration: 5 })).toBe(3); diff --git a/packages/studio/src/utils/studioHelpers.ts b/packages/studio/src/utils/studioHelpers.ts index 0afd8c8608..532e8d0e84 100644 --- a/packages/studio/src/utils/studioHelpers.ts +++ b/packages/studio/src/utils/studioHelpers.ts @@ -7,6 +7,7 @@ import type { TimelineAssetKind } from "./timelineAssetDrop"; import { roundToCenti } from "./rounding"; import { studioApiFetch } from "./studioApiFetch"; import { encodeUrlPath } from "@hyperframes/parsers"; +import { keyHint } from "../player/components/studioShortcuts"; export interface EditingFile { path: string; @@ -35,6 +36,10 @@ export function getTimelineElementLabel(element: TimelineElement): string { return element.label || element.id || element.tag; } +export function deletedNotice(label: string, count: number): string { + return `Deleted ${label}. Undo (${keyHint("undo")}) restores ${count === 1 ? "it" : "them"}.`; +} + function normalizeProjectAssetPath(value: string): string { const trimmed = value.trim(); const maybeUrl = /^[a-z]+:\/\//i.test(trimmed) ? new URL(trimmed).pathname : trimmed;