mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 16:37:32 +00:00
fix(studio): a delete's toast names the undo key, as the ripple toast does (#8571)
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user