Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(channels): preserve favorite drop targets on release (#9651)

dev-rb2884e1311c06
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 3cd430f15a..9d85fd30b9 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -686,7 +686,7 @@ resolved session ID; keep the existing `AgentSessionProvider` subscription to
Offer Add channels on manual-section headers and empty states; keep the picker scoped to eligible joined channels, explain scope and assignment moves in concise helper text, and leave smart membership rule-driven.
Place the smart rule Input below Name contains; show a match count with hover/focus channel preview, and keep preview queries reactive to the selected scope without briefly reporting pending matches as empty.
Keep per-section sorting and unread filters personal, and filter after membership assignment so hidden rows never leak into another section.
- Default Favorites to Custom order and persist drag reordering through the shared favorites mutation; preserve hidden and non-channel favorite positions, disable dragging under automatic sorts, show an insertion line at the actual destination edge, and keep the original rail unchanged.
+ Default Favorites to Custom order and persist drag reordering through the shared favorites mutation; preserve hidden and non-channel favorite positions, disable dragging under automatic sorts, show an insertion line at the actual destination edge, and keep the original rail unchanged. Retain pointer hit-testing coordinates until the drag sensor finishes so intervening scroll updates cannot discard a valid drop.
Share the sliders-icon section menu's Sort, Filter, and actions with a header context menu; use trailing `SingleSelectCheck` marks for sorting, keep the Unread only label left and its switch right, and keep the filter submenu open when toggled.
Compose the section click and right-click menus with `ContextMenuContent`, `MenuItem`, `MenuGroup`, and `MenuSeparator`; do not nest padded `Dropdown.Group` elements inside a context-menu surface.
Keep all section mute, unmute, and snooze actions personal to the viewer; use the complete current membership, not filtered or hydrated rows, and never apply the change to later additions. Resolve built-in membership through the complete channel list, including custom-section assignments and preserving participant checks; Favorites targets channel favorites only. Use the bulk item-preference endpoints and shared snooze picker, applying confirmed changes to the cache once and preserving successful chunks on partial failure.
diff --git a/apps/web/src/components/app/ItemDragAndDrop.tsx b/apps/web/src/components/app/ItemDragAndDrop.tsx
index 8b3541261d..110921b5c4 100644
--- a/apps/web/src/components/app/ItemDragAndDrop.tsx
+++ b/apps/web/src/components/app/ItemDragAndDrop.tsx
@@ -149,6 +149,8 @@ export function ItemDndProvider(props: { children: JSXElement }) {
pointerPosition = { x: e.clientX, y: e.clientY };
};
+ // The mouse sensor finishes on mouseup, after pointerup. Clearing on
+ // pointerup can erase the drop target during an intervening scroll update.
const handlePointerEnd = () => {
queueMicrotask(() => {
pointerPosition = undefined;
@@ -158,7 +160,6 @@ export function ItemDndProvider(props: { children: JSXElement }) {
window.addEventListener('keydown', handleKeyDown);
window.addEventListener('keyup', handleKeyUp);
window.addEventListener('pointermove', handlePointerMove, { capture: true });
- window.addEventListener('pointerup', handlePointerEnd, { capture: true });
window.addEventListener('pointercancel', handlePointerEnd, { capture: true });
window.addEventListener('mousemove', handleMouseMove, { capture: true });
window.addEventListener('mouseup', handlePointerEnd, { capture: true });
@@ -169,9 +170,6 @@ export function ItemDndProvider(props: { children: JSXElement }) {
window.removeEventListener('pointermove', handlePointerMove, {
capture: true,
});
- window.removeEventListener('pointerup', handlePointerEnd, {
- capture: true,
- });
window.removeEventListener('pointercancel', handlePointerEnd, {
capture: true,
});
@@ -185,7 +183,10 @@ export function ItemDndProvider(props: { children: JSXElement }) {
return (
<DragOperationContext.Provider value={{ isAltKey: isAltPressed }}>
- <DragDropProvider collisionDetector={pointerWithin}>
+ <DragDropProvider
+ collisionDetector={pointerWithin}
+ onDragEnd={handlePointerEnd}
+ >
<DragDropSensors />
{props.children}
<DragOverlay class="z-drag pointer-events-none">
diff --git a/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.test.tsx b/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.test.tsx
index b8379a1341..a4fe2fadeb 100644
--- a/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.test.tsx
+++ b/apps/web/src/features/channels-view/components/rail/ChannelFavoriteRows.test.tsx
@@ -1,3 +1,4 @@
+import { ItemDndProvider } from '@app/components/app/ItemDragAndDrop';
import type { ChannelEntity } from '@entity';
import type { ChannelLabel } from '@service-storage/generated/schemas/channelLabel';
import type { Favorite } from '@service-storage/generated/schemas/favorite';
@@ -9,10 +10,12 @@ import {
screen,
waitFor,
} from '@solidjs/testing-library';
+import { useDragDropContext } from '@thisbeyond/solid-dnd';
import {
type ComponentProps,
createSignal,
type JSX,
+ onCleanup,
type ParentProps,
type Setter,
splitProps,
@@ -52,6 +55,7 @@ const rail = vi.hoisted(() => ({
}));
const drag = vi.hoisted(() => ({
+ real: false,
activate: vi.fn(),
viewer: (): string => 'viewer',
starts: [] as Array<
@@ -103,26 +107,42 @@ vi.mock('@solid-primitives/resize-observer', () => ({
},
}),
}));
-vi.mock('@thisbeyond/solid-dnd', () => ({
- createDraggable: (id: string, data: Record<string, unknown>) => {
- drag.draggables.set(id, data);
- return {
- ref() {},
- dragActivators: { onMouseDown: () => drag.activate(id) },
- isActiveDraggable: false,
- };
- },
- createDroppable: () => ({ ref() {}, isActiveDroppable: false }),
- useDragDropContext: () => [
- { active: {} },
- {
- onDragStart: (callback: (typeof drag.starts)[number]) =>
- drag.starts.push(callback),
- onDragEnd: (callback: (typeof drag.ends)[number]) =>
- drag.ends.push(callback),
+vi.mock('@thisbeyond/solid-dnd', async (importOriginal) => {
+ const original =
+ await importOriginal<typeof import('@thisbeyond/solid-dnd')>();
+
+ return {
+ ...original,
+ createDraggable: (id: string, data: Record<string, unknown>) => {
+ if (drag.real) return original.createDraggable(id, data);
+
+ drag.draggables.set(id, data);
+ return {
+ ref() {},
+ dragActivators: { onMouseDown: () => drag.activate(id) },
+ isActiveDraggable: false,
+ };
},
- ],
-}));
+ createDroppable: (id: string, data: Record<string, unknown>) => {
+ if (drag.real) return original.createDroppable(id, data);
+
+ return { ref() {}, isActiveDroppable: false };
+ },
+ useDragDropContext: () => {
+ if (drag.real) return original.useDragDropContext();
+
+ return [
+ { active: {} },
+ {
+ onDragStart: (callback: (typeof drag.starts)[number]) =>
+ drag.starts.push(callback),
+ onDragEnd: (callback: (typeof drag.ends)[number]) =>
+ drag.ends.push(callback),
+ },
+ ];
+ },
+ };
+});
vi.mock('./ChannelsRailContext', async (importOriginal) => ({
...(await importOriginal<typeof import('./ChannelsRailContext')>()),
@@ -217,6 +237,7 @@ vi.mock('@app/components/view-shell', async () => ({
}));
vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice: () => false }));
vi.mock('@ui', async () => ({
+ Layer: (props: ParentProps) => props.children,
Button: (
props: ComponentProps<'button'> & {
variant?: string;
@@ -251,6 +272,7 @@ beforeEach(() => {
drag.starts.length = 0;
drag.ends.length = 0;
drag.draggables.clear();
+ drag.real = false;
rail.labels = () => [];
rail.sectionPreferences = () => ({ sort: 'manual' });
rail.sectionOrder = () => [];
@@ -510,6 +532,69 @@ describe('favorite reordering', () => {
);
});
+ it.each(['favorite', 'outside'] as const)(
+ 'resolves a %s drop after scrolling between pointer and mouse release',
+ async (destination) => {
+ drag.real = true;
+ drag.favorites = original;
+ const hit = vi.fn((): Element => screen.getAllByRole('treeitem')[0]);
+ Object.defineProperty(globalThis.document, 'elementFromPoint', {
+ configurable: true,
+ value: hit,
+ });
+ const Rows = () => {
+ onCleanup(() => {
+ Reflect.deleteProperty(globalThis.document, 'elementFromPoint');
+ });
+ const reorder = useFavoriteReorder(() => [first, last]);
+ const context = useDragDropContext();
+
+ return (
+ <div
+ data-testid="favorite-list"
+ on:scroll={() => context?.[1].detectCollisions()}
+ >
+ <DraggableFavoriteRow favorite={first} reorder={reorder} />
+ <DraggableFavoriteRow favorite={last} reorder={reorder} />
+ </div>
+ );
+ };
+
+ render(() => (
+ <ItemDndProvider>
+ <Rows />
+ </ItemDndProvider>
+ ));
+
+ const rows = screen.getAllByRole('treeitem');
+ fireEvent.mouseDown(rows[1], { button: 0, clientX: 20, clientY: 60 });
+ fireEvent.mouseMove(globalThis.document, { clientX: 20, clientY: 20 });
+ if (destination === 'outside')
+ hit.mockReturnValue(globalThis.document.body);
+ fireEvent.pointerUp(rows[0], { button: 0, clientX: 20, clientY: 20 });
+ await Promise.resolve();
+ fireEvent.scroll(screen.getByTestId('favorite-list'));
+ fireEvent.mouseUp(globalThis.document, {
+ button: 0,
+ clientX: 20,
+ clientY: 20,
+ });
+
+ if (destination !== 'favorite') {
+ expect(drag.reorder).not.toHaveBeenCalled();
+ return;
+ }
+
+ await waitFor(() =>
+ expect(drag.reorder).toHaveBeenCalledExactlyOnceWith({
+ favorites: [last, document, hidden, first].map(
+ ({ entityId, entityType }) => ({ entityId, entityType })
+ ),
+ })
+ );
+ }
+ );
+
it('suppresses drag clicks without blocking keyboard or later pointer activation', () => {
render(() => (
<DraggableFavoriteRow
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index 9c28e5a7ce..f8d2a3c38a 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -1167,8 +1167,10 @@ move it to that position; an accent insertion line shows the exact destination
above or below the target row. The order saves through the shared favorites API
and survives reloads. Hidden favorites and favorites of other entity types keep
their positions. **Sort → Custom order** restores dragging after choosing an
-automatic sort. Dropping a favorite does not open its conversation or move it
-into a custom section. Failed saves roll back and show an error toast.
+automatic sort. Releasing over a favorite preserves the drop target through
+scroll updates; releasing outside the list leaves the order unchanged. Dropping
+a favorite does not open its conversation or move it into a custom section.
+Failed saves roll back and show an error toast.
### Sections