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(crm): prevent company cell picker flashing (#7774)

teocb267a2756ca
diff --git a/apps/web/src/features/block-database/database-mentions.test.tsx b/apps/web/src/features/block-database/database-mentions.test.tsx
index d4e9a1be2b..14de339924 100644
--- a/apps/web/src/features/block-database/database-mentions.test.tsx
+++ b/apps/web/src/features/block-database/database-mentions.test.tsx
@@ -143,6 +143,7 @@ describe('native database mention adapter', () => {
it('restricts People at the native source and excludes groups and unrelated open tabs', () => {
const { menu, select } = setup({ specificEntityType: 'USER' });
+ expect(menu.animate).toBe(false);
expect(menu.sources).toEqual(['users']);
expect(menu.includeGroups).toBe(false);
expect(menu.showOpenTabs).toBe(false);
diff --git a/apps/web/src/features/block-database/database-mentions.tsx b/apps/web/src/features/block-database/database-mentions.tsx
index d2fcb094cf..800bd23a3e 100644
--- a/apps/web/src/features/block-database/database-mentions.tsx
+++ b/apps/web/src/features/block-database/database-mentions.tsx
@@ -46,6 +46,7 @@ export function DatabaseMentionPicker(props: DatabaseMentionPickerProps) {
<Show when={props.anchor}>
{(anchor) => (
<MentionsMenu
+ animate={false}
menu={operations}
anchor={anchor()}
{...databaseMentionScope(props.specificEntityType)}
diff --git a/apps/web/src/features/database/components/grid-cell.preview.test.tsx b/apps/web/src/features/database/components/grid-cell.preview.test.tsx
index c05b2f868b..e7247dddeb 100644
--- a/apps/web/src/features/database/components/grid-cell.preview.test.tsx
+++ b/apps/web/src/features/database/components/grid-cell.preview.test.tsx
@@ -1,15 +1,75 @@
import { createLivePreviewBatcher } from '@queries/preview/live-batcher';
-import { cleanup, render, screen } from '@solidjs/testing-library';
+import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from '@solidjs/testing-library';
import { createSignal, For, onCleanup } from 'solid-js';
import { afterEach, expect, it, vi } from 'vitest';
import type { DatabaseViewColumn } from '../core/database-view';
-import { GridCell } from './grid-cell';
+import { type DatabaseMentionPickerProps, GridCell } from './grid-cell';
afterEach(() => {
cleanup();
vi.useRealTimers();
});
+it('keeps the current company preview mounted while searching and cancelling its picker', async () => {
+ let mounts = 0;
+ let disposals = 0;
+ let picker: DatabaseMentionPickerProps | undefined;
+ const write = vi.fn(async () => true);
+ function Preview() {
+ mounts++;
+ onCleanup(() => disposals++);
+ return <span data-testid="company-preview">Northstar</span>;
+ }
+ render(() => (
+ <GridCell
+ column={{
+ id: 'company',
+ name: 'Company',
+ dataType: 'ENTITY',
+ specificEntityType: 'COMPANY',
+ options: [],
+ isMultiSelect: false,
+ writable: true,
+ }}
+ value="company-1"
+ canEdit
+ onWrite={write}
+ onAddOption={write}
+ onMention={write}
+ renderMentionValue={() => <Preview />}
+ renderMentionPicker={(props) => {
+ picker = props;
+ return null;
+ }}
+ />
+ ));
+ const original = screen.getByTestId('company-preview');
+ for (let round = 0; round < 2; round++) {
+ const trigger = screen.getByRole('button', { name: 'Company: Northstar' });
+ fireEvent.click(trigger);
+ const editor = screen.getByRole('textbox', {
+ name: 'Edit Company',
+ }) as HTMLInputElement;
+ expect(screen.getByTestId('company-preview')).toBe(original);
+ expect(disposals).toBe(0);
+ expect(editor.value).toBe('');
+ expect(document.activeElement).toBe(editor);
+ fireEvent.input(editor, { target: { value: 'new company' } });
+ expect(picker?.search).toBe('new company');
+ fireEvent.keyDown(editor, { key: 'Escape' });
+ await waitFor(() => expect(document.activeElement).toBe(trigger));
+ expect(screen.getByTestId('company-preview')).toBe(original);
+ }
+ expect(mounts).toBe(1);
+ expect(write).not.toHaveBeenCalled();
+});
+
it('retains a company preview when refreshed row objects still reference the same company', () => {
const column: DatabaseViewColumn = {
id: 'company',
diff --git a/apps/web/src/features/database/components/grid-cell.tsx b/apps/web/src/features/database/components/grid-cell.tsx
index 48a419c466..0ea7303f13 100644
--- a/apps/web/src/features/database/components/grid-cell.tsx
+++ b/apps/web/src/features/database/components/grid-cell.tsx
@@ -147,7 +147,7 @@ export function GridCell(props: GridCellProps) {
const [selectAll, setSelectAll] = createSignal(true);
const cellKind = createMemo<GridCellKind>(() =>
match({
- editing: editing(),
+ editing: editing() && !isEntity(),
boolean: isBoolean(),
date: isDate() && editable(),
option: isOptionColumn(props.column),
@@ -170,7 +170,7 @@ export function GridCell(props: GridCellProps) {
setSelectedMention(undefined);
if (isEntity()) {
setMentionSearch(seed?.replace(/^@/, '') ?? '');
- setDraft(`@${seed?.replace(/^@/, '') ?? ''}`);
+ setDraft(seed?.replace(/^@/, '') ?? '');
setSelectAll(false);
setEditing(true);
setMentionOpen(true);
@@ -269,53 +269,55 @@ export function GridCell(props: GridCellProps) {
);
onCleanup(() => props.onReady?.(undefined));
+ const renderEditor = () => (
+ <InlineEditor
+ column={props.column}
+ renderTextEditor={props.renderTextEditor}
+ onInferMention={selectMention}
+ originalValue={props.value}
+ emptyLabel={props.emptyLabel}
+ draft={draft()}
+ selectAll={selectAll()}
+ onDraft={updateDraft}
+ mentionOpen={mentionOpen()}
+ onMentionClose={closeMention}
+ onWrite={write}
+ onClose={finishEdit}
+ onEditorReady={(focus) => {
+ focusEditor = focus;
+ props.onEditorReady?.(focus);
+ }}
+ onNavigateRow={
+ props.onNavigateRow
+ ? (direction) => {
+ if (props.onNavigateRow?.(direction)) return true;
+ queueMicrotask(() => trigger?.focus());
+ return false;
+ }
+ : undefined
+ }
+ onNavigate={(direction) => {
+ if (props.onNavigate?.(direction)) return true;
+ const previousFocus = document.activeElement;
+ queueMicrotask(() => {
+ // Solid may still be replacing the input with its display trigger.
+ // Do not take focus back if another control received it meanwhile.
+ if (
+ document.activeElement === previousFocus ||
+ document.activeElement === document.body ||
+ document.activeElement === trigger
+ )
+ focusAdjacent(trigger, direction);
+ });
+ return true;
+ }}
+ />
+ );
+
return (
<div ref={cell} class="relative min-w-0">
<Switch>
- <Match when={cellKind() === 'editing'}>
- <InlineEditor
- column={props.column}
- renderTextEditor={props.renderTextEditor}
- onInferMention={selectMention}
- originalValue={props.value}
- emptyLabel={props.emptyLabel}
- draft={draft()}
- selectAll={selectAll()}
- onDraft={updateDraft}
- mentionOpen={mentionOpen()}
- onMentionClose={closeMention}
- onWrite={write}
- onClose={finishEdit}
- onEditorReady={(focus) => {
- focusEditor = focus;
- props.onEditorReady?.(focus);
- }}
- onNavigateRow={
- props.onNavigateRow
- ? (direction) => {
- if (props.onNavigateRow?.(direction)) return true;
- queueMicrotask(() => trigger?.focus());
- return false;
- }
- : undefined
- }
- onNavigate={(direction) => {
- if (props.onNavigate?.(direction)) return true;
- const previousFocus = document.activeElement;
- queueMicrotask(() => {
- // Solid may still be replacing the input with its display trigger.
- // Do not take focus back if another control received it meanwhile.
- if (
- document.activeElement === previousFocus ||
- document.activeElement === document.body ||
- document.activeElement === trigger
- )
- focusAdjacent(trigger, direction);
- });
- return true;
- }}
- />
- </Match>
+ <Match when={cellKind() === 'editing'}>{renderEditor()}</Match>
<Match when={cellKind() === 'boolean'}>
<BooleanCell
column={props.column}
@@ -363,26 +365,39 @@ export function GridCell(props: GridCellProps) {
</div>
</Match>
<Match when={cellKind() === 'text'}>
- <TextCell
- column={props.column}
- value={props.value}
- emptyLabel={props.emptyLabel}
- editable={editable()}
- isEntity={isEntity()}
- mentionPreview={mentionPreview()}
- hasResolvedMentionLabel={hasResolvedMentionLabel()}
- renderTextValue={props.renderTextValue}
- renderMentionValue={props.renderMentionValue}
- ref={(element) => {
- trigger = element;
- }}
- onNavigate={props.onNavigate}
- onBeginEdit={beginEdit}
- onClearEntity={() => {
- setSelectedMention(undefined);
- void write(null);
- }}
- />
+ <div class="relative">
+ {/* Keep the resolved label and its subscription alive while picking. */}
+ <div
+ inert={isEntity() && editing()}
+ classList={{
+ invisible: isEntity() && editing() && draft() !== '',
+ }}
+ >
+ <TextCell
+ column={props.column}
+ value={props.value}
+ emptyLabel={props.emptyLabel}
+ editable={editable()}
+ isEntity={isEntity()}
+ mentionPreview={mentionPreview()}
+ hasResolvedMentionLabel={hasResolvedMentionLabel()}
+ renderTextValue={props.renderTextValue}
+ renderMentionValue={props.renderMentionValue}
+ ref={(element) => {
+ trigger = element;
+ }}
+ onNavigate={props.onNavigate}
+ onBeginEdit={beginEdit}
+ onClearEntity={() => {
+ setSelectedMention(undefined);
+ void write(null);
+ }}
+ />
+ </div>
+ <Show when={isEntity() && editing()}>
+ <div class="absolute inset-x-0 top-0">{renderEditor()}</div>
+ </Show>
+ </div>
</Match>
</Switch>
<Show when={mentionOpen() && mentionsEnabled()}>
@@ -606,6 +621,10 @@ function InlineEditor(props: {
let textFocus: (() => void) | undefined;
const [error, setError] = createSignal('');
let finishing = false;
+ const showingReference = () =>
+ props.column.dataType === 'ENTITY' &&
+ props.originalValue !== null &&
+ props.draft === '';
const initialDraft =
props.originalValue === null ? '' : String(props.originalValue);
const focus = () => {
@@ -691,7 +710,7 @@ function InlineEditor(props: {
props.onEditorReady?.(focus);
}}
type="text"
- placeholder={props.emptyLabel}
+ placeholder={showingReference() ? undefined : props.emptyLabel}
inputmode={
props.column.dataType === 'NUMBER' ? 'decimal' : undefined
}
@@ -707,7 +726,11 @@ function InlineEditor(props: {
if (!props.mentionOpen) commit(false);
}}
onKeyDown={onKeyDown}
- class="min-h-9 w-full min-w-0 rounded border border-ink/40 bg-input-focus px-2.5 py-1.5 text-[13px] text-ink outline-none ring-2 ring-ink/10"
+ class="min-h-9 w-full min-w-0 rounded border border-ink/40 px-2.5 py-1.5 text-[13px] text-ink outline-none ring-2 ring-ink/10"
+ classList={{
+ 'bg-input-focus': !showingReference(),
+ 'bg-transparent caret-transparent': showingReference(),
+ }}
/>
}
>
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
index ae55c8f241..9b7227b177 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
@@ -167,3 +167,21 @@ it('offers CRM companies and contacts', () => {
expect(mocks.requestedBuckets).toContain('crm_company');
expect(mocks.requestedBuckets).toContain('crm_contact');
});
+
+it('opens cell pickers without replaying the menu entrance animation', () => {
+ const menu = createMenuOperations();
+ menu.openMenu();
+ const { container } = render(() => (
+ <MentionsMenu
+ menu={menu}
+ entities={() => []}
+ users={() => []}
+ sources={['users']}
+ anchor={document.createElement('div')}
+ onPick={vi.fn()}
+ animate={false}
+ />
+ ));
+ expect(screen.getByText('No results')).toBeTruthy();
+ expect(container.querySelector('.menu-open-animation')).toBeNull();
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
index 0b2971aab5..c73f9746df 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
@@ -103,6 +103,8 @@ type MentionsMenuProps = {
includeGroups?: boolean;
/** Disable CRM references for fields that only store Macro user identities. */
includeContacts?: boolean;
+ /** Repeated cell editing opens immediately instead of animating each picker. */
+ animate?: boolean;
} & (
| { editor: LexicalEditor; onPick?: never }
| { editor?: never; anchor: HTMLElement; onPick: (item: MentionItem) => void }
@@ -683,7 +685,8 @@ function MentionsMenuInner(props: MentionsMenuProps) {
<Show when={menuOpen()}>
<ScopedPortal scope={props.portalScope}>
<div
- class="w-96 max-w-[calc(100cqw-1rem-2px)] cursor-default select-none z-modal-content menu-open-animation"
+ class="w-96 max-w-[calc(100cqw-1rem-2px)] cursor-default select-none z-modal-content"
+ classList={{ 'menu-open-animation': props.animate !== false }}
on:touchstart={(e) => e.stopPropagation()}
onPointerDown={(event) => {
if (props.onPick) event.preventDefault();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithElement.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithElement.test.ts
new file mode 100644
index 0000000000..a7925215c2
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithElement.test.ts
@@ -0,0 +1,50 @@
+import { computePosition } from '@floating-ui/dom';
+import { createRoot } from 'solid-js';
+import { expect, it, vi } from 'vitest';
+import { floatWithElement } from './floatWithElement';
+
+vi.mock('@core/block', () => ({ isInBlock: () => false }));
+vi.mock('@core/signal/blockElement', () => ({ blockElementSignal: {} }));
+vi.mock('@floating-ui/dom', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('@floating-ui/dom')>()),
+ computePosition: vi.fn(),
+ autoUpdate: (
+ _reference: Element,
+ _floating: HTMLElement,
+ update: () => void
+ ) => {
+ update();
+ return () => {};
+ },
+}));
+
+it('keeps an anchored picker hidden until its first position is ready', async () => {
+ let resolve!: (position: Awaited<ReturnType<typeof computePosition>>) => void;
+ vi.mocked(computePosition).mockReturnValue(
+ new Promise((done) => {
+ resolve = done;
+ })
+ );
+ const floating = document.createElement('div');
+ const anchor = document.createElement('button');
+ let dispose!: () => void;
+ createRoot((cleanup) => {
+ dispose = cleanup;
+ floatWithElement(floating, () => ({ element: () => anchor }));
+ });
+ try {
+ expect(floating.style.visibility).toBe('hidden');
+ resolve({
+ x: 120,
+ y: 240,
+ placement: 'bottom-start',
+ strategy: 'absolute',
+ middlewareData: {},
+ });
+ await vi.waitFor(() => expect(floating.style.visibility).toBe('visible'));
+ expect(floating.style.left).toBe('120px');
+ expect(floating.style.top).toBe('240px');
+ } finally {
+ dispose();
+ }
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithElement.ts b/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithElement.ts
index 721f9cff20..78f1846613 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithElement.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithElement.ts
@@ -41,6 +41,8 @@ export function floatWithElement(
accessor: Accessor<FloatWithElementOptions | undefined>
) {
style(floatingEl, { position: 'absolute' });
+ // An anchored menu must not paint at its unpositioned portal location.
+ if (accessor()) style(floatingEl, { visibility: 'hidden' });
let referenceEl: Element | null;
let cleanup: () => void = () => {};
diff --git a/docs/AGENT_GUIDE/databases.md b/docs/AGENT_GUIDE/databases.md
index 596af669d3..ee8e7faadf 100644
--- a/docs/AGENT_GUIDE/databases.md
+++ b/docs/AGENT_GUIDE/databases.md
@@ -67,6 +67,10 @@ Calculation choices are local to the open table, not saved with the view.
## CRM pipelines
+Clicking a company/contact cell opens its picker while preserving the current
+label. Type to search for a replacement; Escape cancels and restores cell focus
+without changing the record. The picker opens without an entrance animation.
+
Pipelines are created from the CRM sidebar's **New pipeline** action. Their
records are read and edited through the pipeline's access; they are not standalone
database app entities and do not appear in the Databases list. Use **Share → Team access**