fix(web): fix thread jumping after reorder (#7103)
This commit is contained in:
1 parent
730ce9edd9
commit
1afe5545b7
3 files changed
+37
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
|
||||
import { defaultAnimateLayoutChanges, type AnimateLayoutChanges } from "@dnd-kit/sortable";
|
||||
import {
|
||||
animatePinnedLayoutChanges,
|
||||
archiveSelectedThreadEntries,
|
||||
buildBulkTitleRegenerationContextMenuItem,
|
||||
buildMultiSelectThreadContextMenuItems,
|
||||
@@ -53,6 +55,32 @@ import {
|
||||
|
||||
const localEnvironmentId = EnvironmentId.make("environment-local");
|
||||
|
||||
describe("animatePinnedLayoutChanges", () => {
|
||||
const baseArgs: Parameters<AnimateLayoutChanges>[0] = {
|
||||
active: null,
|
||||
containerId: "pinned-threads",
|
||||
isDragging: false,
|
||||
isSorting: false,
|
||||
id: "thread-a",
|
||||
index: 1,
|
||||
items: ["thread-b", "thread-a"],
|
||||
newIndex: 0,
|
||||
previousItems: ["thread-a", "thread-b"],
|
||||
previousContainerId: "pinned-threads",
|
||||
transition: { duration: 200, easing: "ease" },
|
||||
wasDragging: true,
|
||||
};
|
||||
|
||||
it("does not replay layout movement after the pointer is released", () => {
|
||||
expect(defaultAnimateLayoutChanges(baseArgs)).toBe(true);
|
||||
expect(animatePinnedLayoutChanges(baseArgs)).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps layout movement while the user is sorting", () => {
|
||||
expect(animatePinnedLayoutChanges({ ...baseArgs, isSorting: true })).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldNavigateAfterProjectRemoval", () => {
|
||||
const projectThreads = [{ environmentId: "environment-local", id: "thread-1" }];
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as React from "react";
|
||||
import { defaultAnimateLayoutChanges, type AnimateLayoutChanges } from "@dnd-kit/sortable";
|
||||
import type { ContextMenuItem } from "@t3tools/contracts";
|
||||
import type { SidebarProjectSortOrder, SidebarThreadSortOrder } from "@t3tools/contracts/settings";
|
||||
import {
|
||||
@@ -23,6 +24,12 @@ export const THREAD_JUMP_HINT_SHOW_DELAY_MS = 100;
|
||||
// it small; cold opens still render instantly from the cached snapshot.
|
||||
export const SIDEBAR_THREAD_PREWARM_LIMIT = 3;
|
||||
|
||||
// The list already reaches its destination through sortable transforms while
|
||||
// the pointer is down. dnd-kit's default also animates the committed DOM order
|
||||
// after release, replaying the same movement across every affected row.
|
||||
export const animatePinnedLayoutChanges: AnimateLayoutChanges = (args) =>
|
||||
args.isSorting ? defaultAnimateLayoutChanges(args) : false;
|
||||
|
||||
type SidebarProject = {
|
||||
id: string;
|
||||
title: string;
|
||||
|
||||
@@ -121,6 +121,7 @@ import type { SidebarThreadSummary } from "../types";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { buildThreadActionMenuItems } from "./threadActionMenu.logic";
|
||||
import {
|
||||
animatePinnedLayoutChanges,
|
||||
buildBulkTitleRegenerationContextMenuItem,
|
||||
formatWorkingDurationLabel,
|
||||
firstValidTimestampMs,
|
||||
@@ -448,6 +449,7 @@ function SortablePinnedThreadRow(props: {
|
||||
}) {
|
||||
const { listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
||||
id: props.id,
|
||||
animateLayoutChanges: animatePinnedLayoutChanges,
|
||||
});
|
||||
return props.children({ listeners, setNodeRef, transform, transition, isDragging });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user