fix(studio): messages that count clips or keyframes say 1 clip, not 1 clips (#7496)

* fix(studio): messages that count clips or keyframes say 1 clip, not 1 clips

* fix(studio): countOf needs no comment
This commit is contained in:
Miguel Ángel
2026-11-10 12:37:28 +00:00
committed by GitHub
parent 248f56fbaa
commit ec30de0627
7 changed files with 54 additions and 4 deletions
@@ -26,6 +26,7 @@ import {
type MutableRef,
type UseTimelineElementVisibilityEditingInput,
} from "./timelineTrackVisibility";
import { countOf } from "../utils/countOf";
interface AudioGroupCarveInput extends UseTimelineElementVisibilityEditingInput {
checkEditable?: (elements: readonly TimelineElement[]) => boolean;
@@ -181,7 +182,7 @@ export async function createAudioGroupAndAssignMembers({
// then persists `sources: [groupId]` on success, so a quiet no-op leaves the
// carve aimed at a group that does not exist.
if (elements.length < 2) {
throw new Error(`Cannot group ${elements.length} clip(s): a group needs at least two`);
throw new Error(`Cannot group ${countOf(elements.length, "clip")}: a group needs at least two`);
}
if (!GROUP_ID_PATTERN.test(groupId)) {
throw new Error(`Invalid audio group id ${JSON.stringify(groupId)}`);
@@ -25,6 +25,7 @@ import {
} from "./gsapShared";
import { useStableHandlers } from "./useStableHandlers";
import { progressAtTime, runEaseOf, timeAtProgress, warpsTime } from "../utils/gsapKeyframeEases";
import { countOf } from "../utils/countOf";
type RecordedKeyframe = {
percentage: number;
@@ -375,7 +376,7 @@ export function useGestureCommit({
}
trackPreviewEditResult("gesture_recording", recordingMethodRef.current, outcome.finish());
}
showToast(`Recorded ${sortedPcts.length} keyframes`, "info");
showToast(`Recorded ${countOf(sortedPcts.length, "keyframe")}`, "info");
} catch (err) {
console.error("[GR:error]", err);
showToast(`Gesture commit failed: ${err}`, "error");
+5 -1
View File
@@ -9,6 +9,7 @@ import { isLinkedSelectionOn } from "../utils/linkedClipPreferences";
import { buildAtomicCutIntents, runAtomicCutTransaction } from "../utils/razorSplitTransaction";
import type { RecordEditInput } from "./timelineEditingHelpers";
import { useFreezeFrame } from "./useFreezeFrame";
import { countOf } from "../utils/countOf";
interface UseRazorSplitOptions {
projectId: string | null;
@@ -138,7 +139,10 @@ export function useRazorSplit({
const result = await runCut(splittable, splitTime, "all");
if (!result) return;
if (result.syncFailed) return;
showToast(`Split ${result.splitCount} clips at ${splitTime.toFixed(2)}s`, "info");
showToast(
`Split ${countOf(result.splitCount, "clip")} at ${splitTime.toFixed(2)}s`,
"info",
);
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to split clips";
showToast(message, "error");
@@ -156,6 +156,34 @@ describe("useTimelineDeleteOps: ripple undo label", () => {
expect(body.targets).toHaveLength(elements.length);
});
it("a refused delete names its count: 1 clip, 2 clips", async () => {
vi.stubGlobal(
"fetch",
vi.fn(async (input: RequestInfo | URL) =>
String(input).includes("/file-mutations/remove-elements/")
? new Response("{}", { status: 500 })
: new Response(JSON.stringify({ content: html }), { status: 200 }),
),
);
const showToast = vi.fn();
const { elements, b, getHook } = mountDeleteHarness({
handleTimelineGroupMove: vi.fn(),
showToast,
});
await act(async () => {
await getHook().handleTimelineElementDelete(b);
});
await act(async () => {
await getHook().handleTimelineElementsDelete(elements.slice(0, 2));
});
expect(showToast.mock.calls.map(([message]) => message)).toEqual([
"Failed to delete 1 clip from index.html",
"Failed to delete 2 clips from index.html",
]);
});
it("shows exactly one toast when a ripple fails to persist after a committed delete", async () => {
const handleTimelineGroupMove = vi.fn().mockRejectedValue(new Error("persist failed"));
const showToast = vi.fn();
@@ -25,6 +25,7 @@ import type {
TimelineGroupMoveChange,
} from "./useTimelineGroupEditing";
import { studioApiFetch } from "../utils/studioApiFetch";
import { countOf } from "../utils/countOf";
/** Apply already-resolved ripple changes to the surviving elements for the
* optimistic store update after a delete. Pure — no IO. */
@@ -139,7 +140,9 @@ export function useTimelineDeleteOps({
},
);
if (!removeResponse.ok) {
throw new Error(`Failed to delete ${sameFile.length} clips from ${targetPath}`);
throw new Error(
`Failed to delete ${countOf(sameFile.length, "clip")} from ${targetPath}`,
);
}
const removeData = (await removeResponse.json()) as { content?: string };
const removedContent =
+10
View File
@@ -0,0 +1,10 @@
import { describe, expect, it } from "vitest";
import { countOf } from "./countOf";
describe("countOf", () => {
it("names one thing in the singular and two in the plural", () => {
expect(countOf(1, "clip")).toBe("1 clip");
expect(countOf(2, "clip")).toBe("2 clips");
expect(countOf(0, "keyframe")).toBe("0 keyframes");
});
});
+3
View File
@@ -0,0 +1,3 @@
export function countOf(n: number, word: string): string {
return `${n} ${n === 1 ? word : `${word}s`}`;
}