Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(comments): open a minimized margin thread as a dismissable popover (#6825)
gbirmanf08fc12d5841
diff --git a/apps/web/src/lib/core/comments/MinimizedThreads.tsx b/apps/web/src/lib/core/comments/MinimizedThreads.tsxindex 4396c9db98..f2a80109cc 100644--- a/apps/web/src/lib/core/comments/MinimizedThreads.tsx+++ b/apps/web/src/lib/core/comments/MinimizedThreads.tsx@@ -1,16 +1,11 @@+import { Popover } from '@kobalte/core/popover';import ChatTeardrop from '@phosphor/chat-teardrop.svg';import { cn, Layer } from '@ui';import type { EditorThemeClasses } from 'lexical';-import {- createEffect,- createSignal,- onCleanup,- Show,- useContext,-} from 'solid-js';+import { createEffect, createSignal, useContext } from 'solid-js';import type { Layout, Root } from './commentType';import { MeasureContainer } from './MeasureContainer';-import { CommentsContext, Thread } from './Thread';+import { CommentsContext, ThreadCard } from './Thread';export function MinimizedThread(props: {comment: Root;@@ -26,9 +21,7 @@ export function MinimizedThread(props: {expandable?: boolean;}) {const [expanded, setExpanded] = createSignal<boolean>(false);- const [expandedThreadRef, setExpandedThreadRef] = createSignal<- HTMLDivElement | undefined- >(undefined);+ const [badge, setBadge] = createSignal<HTMLDivElement>();const expandable = () => props.expandable !== false;@@ -46,23 +39,6 @@ export function MinimizedThread(props: {}});- createEffect(() => {- if (!expanded()) return;- function handleClick(e: MouseEvent) {- const _expandedThreadRef = expandedThreadRef();- if (- _expandedThreadRef &&- !_expandedThreadRef.contains(e.target as Node)- ) {- setExpanded(false);- }- }- document.addEventListener('mousedown', handleClick);- onCleanup(() => {- document.removeEventListener('mousedown', handleClick);- });- });-// TODO (seamus) : in the current version of minimized threads the ids are// not being shown.// const _userIds = createMemo(() => {@@ -86,19 +62,7 @@ export function MinimizedThread(props: {};return (- <Show- when={!expanded()}- fallback={- <Thread- comment={props.comment}- layout={props.layout}- isActive={true}- maxHeight={props.maxHeight}- ref={setExpandedThreadRef}- width={320}- />- }- >+ <><MeasureContaineralignment={'left'}alignmentOffset={0}@@ -110,6 +74,7 @@ export function MinimizedThread(props: {><Layer depth={2}><div+ ref={setBadge}class={cn('transition-transform flex items-center group text-ink-extra-muted pointer-events-auto',props.isActive && '-translate-x-4'@@ -130,6 +95,39 @@ export function MinimizedThread(props: {</div></Layer></MeasureContainer>- </Show>+ {/* A dismissable layer, not an outside-click listener: the delete+ confirmation and menus the card opens nest inside it, so pressing+ them does not dismiss the card. Unportaled, the card keeps the+ document's scroll and clipping like the badge it opens from. */}+ <Popover+ open={expanded()}+ onOpenChange={setExpanded}+ anchorRef={badge}+ placement="left-start"+ gutter={4}+ flip+ slide+ >+ <Popover.Content+ class="outline-none"+ style={{ 'z-index': 'calc(var(--z-index-placeable) + 1)' }}+ onOpenAutoFocus={(e) => e.preventDefault()}+ onCloseAutoFocus={(e) => e.preventDefault()}+ onInteractOutside={(e) => {+ // The badge reopens the card on click; closing on its press first+ // would make it flicker shut and open again.+ const target = e.detail.originalEvent.target;+ if (target instanceof Node && badge()?.contains(target))+ e.preventDefault();+ }}+ onClick={(e) => {+ setActiveThread(props.comment.threadId);+ e.stopPropagation();+ }}+ >+ <ThreadCard comment={props.comment} isActive width={320} />+ </Popover.Content>+ </Popover>+ </>);}diff --git a/apps/web/src/lib/core/comments/Thread.test.tsx b/apps/web/src/lib/core/comments/Thread.test.tsxindex 6038fb940d..dc3df7dfe9 100644--- a/apps/web/src/lib/core/comments/Thread.test.tsx+++ b/apps/web/src/lib/core/comments/Thread.test.tsx@@ -1,6 +1,13 @@import { URL_PARAMS as markdownParams } from '@block-md/constants';-import { cleanup, fireEvent, render, waitFor } from '@solidjs/testing-library';-import type { ParentProps } from 'solid-js';+import { Dialog } from '@kobalte/core/dialog';+import {+ cleanup,+ fireEvent,+ render,+ screen,+ waitFor,+} from '@solidjs/testing-library';+import { createSignal, type ParentProps } from 'solid-js';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import type { Root } from './commentType';import { MinimizedThread } from './MinimizedThreads';@@ -11,7 +18,10 @@ import {ThreadBody,} from './Thread';-const mocks = vi.hoisted(() => ({ unifiedDiscussions: true }));+const mocks = vi.hoisted(() => ({+ unifiedDiscussions: true,+ confirmed: vi.fn(),+}));vi.mock('@core/util/url', () => ({buildSimpleEntityUrl: (entity: { type: string; id: string },@@ -43,7 +53,24 @@ vi.mock('@channel/Input/message-payload', () => ({vi.mock('@core/messages/MessageThread', () => ({MessageThreadById: (props: {buildLink: (message: { id: string }) => string;- }) => <a href={props.buildLink({ id: 'comment-root' })}>Copy link</a>,+ }) => {+ // Stands in for the message actions' delete confirmation, which the+ // thread renders into a portal outside the card.+ const [confirming, setConfirming] = createSignal(false);+ return (+ <>+ <a href={props.buildLink({ id: 'comment-root' })}>Copy link</a>+ <button onClick={() => setConfirming(true)}>Delete</button>+ <Dialog open={confirming()} onOpenChange={setConfirming}>+ <Dialog.Portal>+ <Dialog.Content>+ <button onClick={() => mocks.confirmed()}>Confirm delete</button>+ </Dialog.Content>+ </Dialog.Portal>+ </Dialog>+ </>+ );+ },}));vi.mock('@core/component/LexicalMarkdown/component/core/StaticMarkdown',@@ -161,6 +188,42 @@ describe('anchored comment links', () => {expect(view.getByRole('link')).toBeTruthy();});+ // The popover content, found through the thread it hosts. jsdom never runs+ // the exit animation presence waits on, so closing leaves it mounted and+ // only its open state changes.+ const card = (view: ReturnType<typeof render>) =>+ view.getByText('Copy link').closest('[data-comment-thread]')!+ .parentElement!;++ it('keeps an expanded minimized comment open through a dialog it opens', async () => {+ const view = renderThreadBody('md', true);+ fireEvent.click(view.getByText('1'));+ fireEvent.click(view.getByRole('button', { name: 'Delete' }));+ const confirm = await screen.findByRole('button', {+ name: 'Confirm delete',+ });+ // Outside-press detection arms a tick after a layer opens.+ await new Promise((resolve) => setTimeout(resolve));+ // The confirmation is portaled out of the card; pressing it must reach+ // its handler instead of dismissing the card that owns it.+ fireEvent.pointerDown(confirm);+ fireEvent.mouseDown(confirm);+ fireEvent.click(confirm);+ expect(mocks.confirmed).toHaveBeenCalledTimes(1);+ expect(card(view).hasAttribute('data-expanded')).toBe(true);+ });++ it('dismisses an expanded minimized comment on a press outside it', async () => {+ const view = renderThreadBody('md', true);+ fireEvent.click(view.getByText('1'));+ expect(view.getByRole('link')).toBeTruthy();+ await new Promise((resolve) => setTimeout(resolve));+ fireEvent.pointerDown(document.body);+ await waitFor(() =>+ expect(card(view).hasAttribute('data-expanded')).toBe(false)+ );+ });+it.each(['md', 'task', 'snippet', 'skill', 'pdf'] as const)('copies legacy %s root and reply links without a block provider',async (documentType) => {diff --git a/apps/web/src/lib/core/comments/Thread.tsx b/apps/web/src/lib/core/comments/Thread.tsxindex a09415ba69..2921e1f758 100644--- a/apps/web/src/lib/core/comments/Thread.tsx+++ b/apps/web/src/lib/core/comments/Thread.tsx@@ -396,8 +396,6 @@ export function Thread(props: {theme?: EditorThemeClasses;maxHeight?: number;handleMouseDown?: (e: MouseEvent) => void;- ref?: (el: HTMLDivElement) => void;- width?: number;}) {let measureContainerRef!: HTMLDivElement;@@ -419,32 +417,49 @@ export function Thread(props: {threadId={props.comment.threadId}maxHeight={props.maxHeight}isActive={props.isActive}- forceWidth={props.width}transition={false}>- <Layer depth={2}>- <div- data-comment-thread- // note: pdf-pointer-event-reset is a strange one-off class that mostly normalizes- // pointer-events: none vs. all inside the .pdfOverlayInner div.- class="shrink-0 border border-edge bg-surface p-2 shadow-md rounded-xl shadow-drop-shadow portal-scope pointer-events-auto pdf-pointer-event-reset"- classList={{- 'transition-transform duration-100': true,- '-translate-x-8': props.isActive,- }}- style={{- width: props.width ? `${props.width}px` : 'auto',- }}- ref={props.ref}- >- <ThreadBody- comment={props.comment}- isActive={props.isActive}- theme={props.theme}- flatComposer- />- </div>- </Layer>+ <ThreadCard+ comment={props.comment}+ isActive={props.isActive}+ theme={props.theme}+ shifted={props.isActive}+ /></MeasureContainer>);}++/** The floating card around a thread, placed by the margin or by a popover. */+export function ThreadCard(props: {+ comment: Root;+ isActive: boolean;+ theme?: EditorThemeClasses;+ width?: number;+ /** Nudge the active card toward the text it annotates. */+ shifted?: boolean;+}) {+ return (+ <Layer depth={2}>+ <div+ data-comment-thread+ // note: pdf-pointer-event-reset is a strange one-off class that mostly normalizes+ // pointer-events: none vs. all inside the .pdfOverlayInner div.+ class="shrink-0 border border-edge bg-surface p-2 shadow-md rounded-xl shadow-drop-shadow portal-scope pointer-events-auto pdf-pointer-event-reset"+ classList={{+ 'transition-transform duration-100': true,+ '-translate-x-8': props.shifted,+ }}+ style={{+ width: props.width ? `${props.width}px` : 'auto',+ }}+ >+ <ThreadBody+ comment={props.comment}+ isActive={props.isActive}+ theme={props.theme}+ flatComposer+ />+ </div>+ </Layer>+ );+}