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.

feat(spreadsheets): simplify spreadsheet comments sidebar (#7234)

gbirman204760be01ec
diff --git a/apps/web/src/features/block-spreadsheet/SpreadsheetComments.test.tsx b/apps/web/src/features/block-spreadsheet/SpreadsheetComments.test.tsx
index 766b9425f5..0ad4e91e2b 100644
--- a/apps/web/src/features/block-spreadsheet/SpreadsheetComments.test.tsx
+++ b/apps/web/src/features/block-spreadsheet/SpreadsheetComments.test.tsx
@@ -292,37 +292,26 @@ it('opens notification targets at the linked range and keeps deleted-sheet threa
).toBeTruthy();
});
-it('keeps sidebar and floating composer attachments independent', async () => {
+it('uses discussion for sidebar comments and keeps selection comments in the grid', () => {
mount();
fireEvent.click(screen.getByRole('button', { name: 'Comments' }));
+ const panel = screen.getByRole('complementary');
+ expect(panel.querySelector('input[aria-label="Comment draft"]')).toBeNull();
+ expect(screen.getByText('Discussion')).toBeTruthy();
+ expect(screen.queryByText('Cell comments')).toBeNull();
+ expect(
+ screen.queryByText('Comments attached to a sheet selection')
+ ).toBeNull();
+
selection = { anchor: 'D9', focus: 'D9' };
fireEvent.click(screen.getByRole('button', { name: 'Comment' }));
- const panel = screen.getByRole('complementary');
- fireEvent.input(panel.querySelector('input')!, {
- target: { value: 'Sidebar draft' },
- });
- fireEvent.click(
- [...panel.querySelectorAll('button')].find(
- (button) => button.textContent === 'Post'
- )!
- );
- await waitFor(() =>
- expect(mocks.send).toHaveBeenCalledWith(
- expect.objectContaining({
- parent: { type: 'document', id: 'doc' },
- message: expect.objectContaining({
- anchor: { type: 'spreadsheet', ...anchor },
- }),
- })
- )
- );
expect(screen.getByRole('dialog').getAttribute('aria-label')).toBe(
'Comments on Budget · D9'
);
expect(screen.getByRole('dialog').querySelector('input')).toBeTruthy();
});
-it('mounts a workbook discussion on the document parent without legacy comment links', () => {
+it('mounts discussion on the document parent without legacy comment links', () => {
mount();
fireEvent.click(screen.getByRole('button', { name: 'Comments' }));
expect(mocks.discussion).toHaveBeenCalledWith(
@@ -332,7 +321,7 @@ it('mounts a workbook discussion on the document parent without legacy comment l
targetId: null,
})
);
- expect(screen.getByText('Workbook discussion')).toBeTruthy();
+ expect(screen.getByText('Discussion')).toBeTruthy();
});
it.each(['root-id', 'reply-id'])(
@@ -361,7 +350,7 @@ it.each(['root-id', 'reply-id'])(
}
);
-it('clears a previous range highlight for a workbook link and preserves the draft range', async () => {
+it('clears a previous range highlight when opening a workbook link', () => {
mocks.data.push({
...mocks.data[0],
id: 'workbook-root',
@@ -369,9 +358,6 @@ it('clears a previous range highlight for a workbook link and preserves the draf
});
mocks.target = 'reply-id';
mount();
- const input = screen.getByRole('textbox') as HTMLInputElement;
- fireEvent.input(input, { target: { value: 'Range draft' } });
- selection = { anchor: 'D9', focus: 'D9' };
mocks.target = 'workbook-reply';
mocks.rootId = 'workbook-root';
@@ -381,19 +367,44 @@ it('clears a previous range highlight for a workbook link and preserves the draf
expect(mocks.discussion).toHaveBeenCalledWith(
expect.objectContaining({ targetId: 'workbook-reply' })
);
- expect(screen.getByRole('textbox')).toBe(input);
- expect(input.value).toBe('Range draft');
- fireEvent.click(screen.getByRole('button', { name: 'Post' }));
- await waitFor(() =>
- expect(mocks.send).toHaveBeenCalledWith(
- expect.objectContaining({
- message: expect.objectContaining({
- content: 'Range draft',
- anchor: { type: 'spreadsheet', ...anchor },
- }),
- })
- )
- );
+});
+
+it('filters cell comments by open and resolved state', () => {
+ mocks.data.push({
+ ...mocks.data[0],
+ id: 'resolved-root',
+ content: 'Already handled',
+ state: {
+ ...mocks.data[0].state,
+ root_id: 'resolved-root',
+ resolved: true,
+ },
+ });
+ mount();
+ fireEvent.click(screen.getByRole('button', { name: 'Comments' }));
+
+ expect(screen.getByText('Check assumptions')).toBeTruthy();
+ expect(screen.queryByText('Already handled')).toBeNull();
+
+ fireEvent.click(screen.getByRole('radio', { name: 'Resolved' }));
+ expect(screen.queryByText('Check assumptions')).toBeNull();
+ expect(screen.getByText('Already handled')).toBeTruthy();
+
+ fireEvent.click(screen.getByRole('radio', { name: 'All' }));
+ expect(screen.getByText('Check assumptions')).toBeTruthy();
+ expect(screen.getByText('Already handled')).toBeTruthy();
+});
+
+it('reveals a resolved cell comment opened from a notification', () => {
+ mocks.data[0].state.resolved = true;
+ mocks.target = 'reply-id';
+ mount();
+
+ expect(
+ (screen.getByRole('radio', { name: 'Resolved' }) as HTMLInputElement)
+ .checked
+ ).toBe(true);
+ expect(screen.getByText('Check assumptions')).toBeTruthy();
});
it('clears a previous range navigation error when opening a workbook link', () => {
diff --git a/apps/web/src/features/block-spreadsheet/SpreadsheetComments.tsx b/apps/web/src/features/block-spreadsheet/SpreadsheetComments.tsx
index cda087fb5a..e85c0bf6c2 100644
--- a/apps/web/src/features/block-spreadsheet/SpreadsheetComments.tsx
+++ b/apps/web/src/features/block-spreadsheet/SpreadsheetComments.tsx
@@ -24,6 +24,7 @@ import {
} from '@queries/messages/mutations';
import type { MessageListItem } from '@service-storage/messages';
import { Button } from '@ui/components/Button';
+import { SegmentedControl } from '@ui/components/SegmentedControl';
import {
createEffect,
createMemo,
@@ -52,6 +53,17 @@ import type { SpreadsheetStore } from './primitives/create-spreadsheet-store';
import { SpreadsheetCommentComposer } from './views/SpreadsheetCommentComposer';
import { SpreadsheetCommentThread } from './views/SpreadsheetCommentThread';
+type CommentFilter = 'open' | 'resolved' | 'all';
+
+const COMMENT_FILTER_OPTIONS: Array<{
+ value: CommentFilter;
+ label: string;
+}> = [
+ { value: 'open', label: 'Open' },
+ { value: 'resolved', label: 'Resolved' },
+ { value: 'all', label: 'All' },
+];
+
/** Production wiring for spreadsheet discussions on the shared message store. */
export function SpreadsheetComments(props: {
documentId: string;
@@ -73,9 +85,9 @@ export function SpreadsheetComments(props: {
const target = useMessageLink(parent, linkedMessageId);
const navigationCount = useParamNavigationCount('comment_id');
const [open, setOpen] = createSignal(false);
- const [anchor, setAnchor] = createSignal<SpreadsheetCommentAnchor>();
const [location, setLocation] = createSignal<SpreadsheetCommentAnchor>();
const [error, setError] = createSignal('');
+ const [commentFilter, setCommentFilter] = createSignal<CommentFilter>('open');
const threads = () => (query.isSuccess ? query.data : []);
const discussionTarget = () =>
threads().find((thread) => thread.id === target.rootId())?.state.anchor ===
@@ -191,12 +203,26 @@ export function SpreadsheetComments(props: {
range: context.range,
};
};
- const selectAnchor = () => setAnchor(currentAnchor());
const toggle = () => {
- if (!open()) selectAnchor();
closeCard();
setOpen(!open());
};
+ const selectionThreads = createMemo(() =>
+ threads().filter(
+ (thread) =>
+ !thread.state.deleted_at &&
+ (!thread.deleted_at || thread.thread.reply_count > 0) &&
+ spreadsheetCommentAnchor(thread.state.anchor)
+ )
+ );
+ const filteredSelectionThreads = createMemo(() =>
+ selectionThreads().filter((thread) => {
+ if (commentFilter() === 'all') return true;
+ return commentFilter() === 'resolved'
+ ? thread.state.resolved
+ : !thread.state.resolved;
+ })
+ );
const anchoredThreads = createMemo(() =>
threads().flatMap((thread) => {
const value = spreadsheetCommentAnchor(thread.state.anchor);
@@ -251,12 +277,11 @@ export function SpreadsheetComments(props: {
add: (element) => {
if (!canComment()) return;
clearHover();
- const selected = currentAnchor();
if (!element) {
- setAnchor(selected);
setOpen(true);
return;
}
+ const selected = currentAnchor();
setCard({
element,
anchor: selected,
@@ -309,11 +334,9 @@ export function SpreadsheetComments(props: {
closeCard();
setLocation(undefined);
setError('');
- if (!open()) setAnchor(ready ? currentAnchor() : undefined);
setOpen(true);
}
if (!ready) return;
- if (!anchor()) setAnchor(currentAnchor());
if (!loaded) return;
const thread = threads().find(
(thread) => thread.id === target.rootId()
@@ -322,7 +345,7 @@ export function SpreadsheetComments(props: {
navigatedRequest = value;
const linked = spreadsheetCommentAnchor(thread.state.anchor);
if (linked) {
- setAnchor(linked);
+ setCommentFilter(thread.state.resolved ? 'resolved' : 'open');
navigate(linked);
}
}
@@ -386,85 +409,77 @@ export function SpreadsheetComments(props: {
{error()}
</p>
</Show>
- <Show when={query.isSuccess && !count()}>
- <p class="py-4 text-sm text-ink-muted">
- No comments yet. Start a discussion about the selected cells.
- </p>
- </Show>
<Suspense
fallback={
<p class="text-sm text-ink-muted">Loading comments…</p>
}
>
- <For
- each={threads()
- .filter(
- (thread) =>
- !thread.state.deleted_at &&
- spreadsheetCommentAnchor(thread.state.anchor)
- )
- .map((thread) => thread.id)}
- >
- {(id) => {
- const thread = () =>
- threads().find((item) => item.id === id)!;
- const linked = () =>
- spreadsheetCommentAnchor(thread().state.anchor)!;
- const label = () => {
- const value = linked();
- const sheet = props.store
- .workbook()
- .find((sheet) => sheet.id === value.sheetId);
- return `${sheet?.name ?? value.sheetName} · ${value.range}${sheet ? '' : ' (deleted sheet)'}`;
- };
- return (
- <>
- <button
- class="mt-3 mb-1 rounded px-2 py-1 text-xs text-accent hover:bg-hover"
- onClick={() => navigate(linked())}
- >
- {label()}
- </button>
- {renderThread(thread)}
- </>
- );
- }}
- </For>
- <EntityDiscussion
- parent={parent()}
- canWrite={canComment()}
- link={{ type: 'spreadsheet', id: props.documentId }}
- targetId={discussionTarget()}
- label="Workbook discussion"
- />
+ <section aria-label="Cell comments">
+ <div class="mb-3">
+ <SegmentedControl
+ value={commentFilter()}
+ options={COMMENT_FILTER_OPTIONS}
+ onChange={setCommentFilter}
+ size="sm"
+ aria-label="Filter cell comments"
+ />
+ </div>
+ <Show when={selectionThreads().length === 0}>
+ <p class="py-3 text-sm text-ink-muted">
+ No cell comments yet. Select cells in the sheet to add
+ one.
+ </p>
+ </Show>
+ <Show
+ when={
+ selectionThreads().length > 0 &&
+ filteredSelectionThreads().length === 0
+ }
+ >
+ <p class="py-3 text-sm text-ink-muted">
+ No {commentFilter()} cell comments.
+ </p>
+ </Show>
+ <For
+ each={filteredSelectionThreads().map((thread) => thread.id)}
+ >
+ {(id) => {
+ const thread = () =>
+ threads().find((item) => item.id === id)!;
+ const linked = () =>
+ spreadsheetCommentAnchor(thread().state.anchor)!;
+ const label = () => {
+ const value = linked();
+ const sheet = props.store
+ .workbook()
+ .find((sheet) => sheet.id === value.sheetId);
+ return `${sheet?.name ?? value.sheetName} · ${value.range}${sheet ? '' : ' (deleted sheet)'}`;
+ };
+ return (
+ <>
+ <button
+ class="mt-3 mb-1 rounded px-2 py-1 text-xs text-accent hover:bg-hover"
+ onClick={() => navigate(linked())}
+ >
+ {label()}
+ </button>
+ {renderThread(thread)}
+ </>
+ );
+ }}
+ </For>
+ </section>
+ <div class="mt-5 border-t border-edge-muted pt-1">
+ <EntityDiscussion
+ parent={parent()}
+ canWrite={canComment()}
+ link={{ type: 'spreadsheet', id: props.documentId }}
+ targetId={discussionTarget()}
+ label="Discussion"
+ />
+ </div>
</Suspense>
</div>
- <Show when={canComment() && anchor()}>
- <div class="shrink-0 border-t border-edge-muted p-3">
- <div class="mb-2 flex items-center justify-between gap-2 text-xs text-ink-muted">
- <span>
- {anchor()
- ? `${anchor()!.sheetName} · ${anchor()!.range}`
- : 'Workbook comment'}
- </span>
- <button class="underline" onClick={selectAnchor}>
- Use selection
- </button>
- </div>
- <StaticMarkdownContext>
- <Suspense>
- <SpreadsheetCommentComposer
- parent={parent()}
- onSend={async (snapshot) => {
- const value = anchor();
- if (!value) throw new Error('Select cells to comment');
- await post(value, snapshot);
- }}
- />
- </Suspense>
- </StaticMarkdownContext>
- </div>
- </Show>
</aside>
</Show>
</div>
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx
index c32ce593d4..6b87851572 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx
@@ -36,6 +36,7 @@ function renderGrid(
| 'showGridlines'
| 'showFormulas'
| 'columnWidths'
+ | 'hiddenColumns'
| 'rowCount'
| 'sheetId'
| 'onFill'
@@ -104,6 +105,7 @@ function renderGrid(
showGridlines={options.showGridlines}
showFormulas={options.showFormulas}
columnWidths={options.columnWidths}
+ hiddenColumns={options.hiddenColumns}
onFill={options.onFill}
onResizeColumn={options.onResizeColumn}
values={options.values ?? {}}
@@ -999,6 +1001,27 @@ describe('cell context menu', () => {
expect(onCellAction).not.toHaveBeenCalled();
});
+ it('anchors a range comment to a rendered cell when its selection anchor is hidden', async () => {
+ const comments = {
+ canComment: () => true,
+ add: vi.fn(),
+ hasComment: () => false,
+ enter: vi.fn(),
+ leave: vi.fn(),
+ show: vi.fn(),
+ };
+ const view = renderGrid({}, { comments, hiddenColumns: [0] });
+ view.controller.selectRange({ row: 1, column: 0 }, { row: 1, column: 25 });
+ fireEvent.keyDown(view.element, { key: 'ContextMenu' });
+ const comment = await screen.findByRole('menuitem', { name: 'Comment' });
+ fireEvent.keyDown(comment, { key: 'Enter' });
+ await waitFor(() =>
+ expect(comments.add).toHaveBeenCalledWith(
+ view.getByRole('gridcell', { name: 'B2' })
+ )
+ );
+ });
+
it('keeps the native text editing menu and does not open the cell menu over headers', async () => {
const view = renderGrid({ A1: { value: 'draft' } });
view.controller.beginEdit('cell');
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
index 077a6663fc..48bbf45aba 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
@@ -59,6 +59,30 @@ const CELL_LINE_HEIGHT = 1.2;
const MAX_ROW_HEIGHT = 160;
const TOUCH_SLOP = 8;
+export function renderedSelectionCell(
+ root: ParentNode | undefined,
+ selection: CellSelection
+) {
+ if (!root) return;
+ const anchor = root.querySelector<HTMLElement>(
+ `[data-address="${cellAddress(selection.anchor)}"]`
+ );
+ if (anchor) return anchor;
+ const area = selectionBounds(selection);
+ return [...root.querySelectorAll<HTMLElement>('[data-address]')].find(
+ (element) => {
+ const position = parseCellAddress(element.dataset.address ?? '');
+ return (
+ position &&
+ position.row >= area.top &&
+ position.row <= area.bottom &&
+ position.column >= area.left &&
+ position.column <= area.right
+ );
+ }
+ );
+}
+
function fontPixels(cell?: SpreadsheetCell) {
return ((cell?.fontSize ?? 10) * 4) / 3;
}
@@ -780,11 +804,7 @@ export function SpreadsheetGrid(props: {
props.onSelectRange(cellMenuSelection.anchor, cellMenuSelection.focus);
if (action === 'comment') {
if (props.comments?.canComment())
- props.comments.add(
- grid.querySelector<HTMLElement>(
- `[data-address="${cellAddress(cellMenuSelection.anchor)}"]`
- ) ?? undefined
- );
+ props.comments.add(renderedSelectionCell(grid, cellMenuSelection));
} else if (action === 'copy' || !props.readonly)
props.onCellAction?.(action);
}
diff --git a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
index ca53e0fcc8..de3282e623 100644
--- a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
+++ b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
@@ -13,7 +13,10 @@ import { match } from 'ts-pattern';
import { SpreadsheetFileMenu } from '../components/SpreadsheetActionMenus';
import { SpreadsheetDialog } from '../components/SpreadsheetDialog';
import { SpreadsheetFindDialog } from '../components/SpreadsheetDialogs';
-import { SpreadsheetGrid } from '../components/SpreadsheetGrid';
+import {
+ renderedSelectionCell,
+ SpreadsheetGrid,
+} from '../components/SpreadsheetGrid';
import type { HeaderAction } from '../components/SpreadsheetHeaderMenu';
import { SpreadsheetSheetTabs } from '../components/SpreadsheetSheetTabs';
import {
@@ -149,11 +152,7 @@ export function SpreadsheetEditor(props: {
);
const addComment = () => {
grid.commit();
- props.comments?.add(
- gridElement?.querySelector<HTMLElement>(
- `[data-address="${grid.activeAddress()}"]`
- ) ?? undefined
- );
+ props.comments?.add(renderedSelectionCell(gridElement, grid.selection()));
};
const restoreEditorFocus = () => {
const pending = pendingMenuAction;
diff --git a/docs/AGENT_GUIDE/documents.md b/docs/AGENT_GUIDE/documents.md
index e80090d90c..10d79969e1 100644
--- a/docs/AGENT_GUIDE/documents.md
+++ b/docs/AGENT_GUIDE/documents.md
@@ -260,18 +260,21 @@ commented range. Hover any cell in that range to read its threads; choose
triangle also opens the card on touch devices. Interacting with a card keeps it
open until dismissed so a reply is not lost when moving the pointer.
-**Comments** in the document header opens all workbook threads. Range labels
+**Comments** in the document header opens the workbook commenting sidebar. Range labels
navigate to the corresponding sheet and cells; deleted-sheet threads remain
-readable. **Workbook discussion** contains comments about the whole workbook,
-with its own composer. The pinned composer at the bottom posts on the displayed
-range; **Use selection** changes that range. Both surfaces use the shared message
-controls for replies, edits, deletion, reactions, and attachments. Range threads
-also offer **Resolve** and **Reopen**. Mentions and replies use inbox notifications
-and message links. Older spreadsheet annotation comments are not displayed.
+readable. Range threads are filtered by **Open**, **Resolved**, or **All**;
+Open is the default. **Discussion** contains comments about the whole workbook
+and is the sidebar's new-comment composer. To start a cell comment,
+select the range and use the ribbon, keyboard shortcut, or cell context menu.
+Both surfaces use the shared message controls for replies, edits, deletion,
+reactions, and attachments. Range threads also offer **Resolve** and **Reopen**.
+Mentions and replies use inbox notifications and message links. Older spreadsheet
+annotation comments are not displayed.
Opening an inbox notification opens the sidebar and targets its comment/range.
-Range links leave Workbook discussion on its normal timeline; workbook links
-open that discussion at the linked message, clear the previous range highlight
-or navigation error, and preserve an open range draft's attachment.
+Range links leave Discussion on its normal timeline; workbook links
+open that discussion at the linked message and clear the previous range highlight
+or navigation error. A resolved range link switches the filter to **Resolved** so
+the targeted thread remains visible.
Comment-only access can post/reply; view-only access can read. Edit/delete applies
to the author's own comments, and failures retain the input draft. Draft demos
must be saved before persistent comments are available.