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
feat(crm): open a pipeline row's company from its cell (#7852)
teoe6770728c787
diff --git a/apps/web/src/features/crm/context/pipelines.ts b/apps/web/src/features/crm/context/pipelines.tsindex a8e45e26f6..d064af1b75 100644--- a/apps/web/src/features/crm/context/pipelines.ts+++ b/apps/web/src/features/crm/context/pipelines.ts@@ -15,6 +15,8 @@ export type PipelineEditor = Component<{pipeline: Pipeline;/** Compact host actions placed alongside the editor's record controls. */actions?: JSX.Element;+ /** Show the company or contact a row is for. */+ onOpenRecord?(record: { type: 'company' | 'contact'; id: string }): void;}>;export type PipelineSharing = Component<{diff --git a/apps/web/src/features/crm/pipeline-adapter.tsx b/apps/web/src/features/crm/pipeline-adapter.tsxindex e349814881..d304b095e0 100644--- a/apps/web/src/features/crm/pipeline-adapter.tsx+++ b/apps/web/src/features/crm/pipeline-adapter.tsx@@ -74,6 +74,7 @@ export function PipelineShare(props: {export function PipelineDatabaseEditor(props: {pipeline: Pipeline;actions?: JSX.Element;+ onOpenRecord?(record: { type: 'company' | 'contact'; id: string }): void;}) {return (<div@@ -90,6 +91,7 @@ export function PipelineDatabaseEditor(props: {<PipelineRecordspipeline={props.pipeline}actions={props.actions}+ onOpenRecord={props.onOpenRecord}/>)}</Show>@@ -101,7 +103,11 @@ export function PipelineDatabaseEditor(props: {const viewFailure = (failure: DatabaseOpFailure) =>toast.failure(databaseOpMessage(failure, 'this view'));-function PipelineRecords(props: { pipeline: Pipeline; actions?: JSX.Element }) {+function PipelineRecords(props: {+ pipeline: Pipeline;+ actions?: JSX.Element;+ onOpenRecord?(record: { type: 'company' | 'contact'; id: string }): void;+}) {const deps = { storage: storageServiceClient, client: useQueryClient() };const tableQuery = usePipelineTableQuery(deps, props.pipeline);const views = createPipelineViews(deps, props.pipeline);@@ -179,6 +185,12 @@ function PipelineRecords(props: { pipeline: Pipeline; actions?: JSX.Element }) {renderMentionValue={(id, entityType) => (<DatabaseMentionValue id={id} entityType={entityType} />)}+ onOpenTitleMention={(id, entityType) => {+ if (entityType === 'COMPANY')+ props.onOpenRecord?.({ type: 'company', id });+ else if (entityType === 'CONTACT')+ props.onOpenRecord?.({ type: 'contact', id });+ }}renderToolbar={(actions) => (<PipelineToolbarviews={views}diff --git a/apps/web/src/features/crm/views/crm-workspace.test.tsx b/apps/web/src/features/crm/views/crm-workspace.test.tsxindex 908b63391a..a67765217e 100644--- a/apps/web/src/features/crm/views/crm-workspace.test.tsx+++ b/apps/web/src/features/crm/views/crm-workspace.test.tsx@@ -13,6 +13,8 @@ const fixture = vi.hoisted(() => ({workspace: undefined as unknown,pipelinesEnabled: true,listsEnabled: true,+ touch: true,+ openWithSplit: vi.fn(),}));vi.mock('@app/components/view-shell', () => ({@@ -32,7 +34,9 @@ vi.mock('@app/components/view-shell', () => ({vi.mock('@app/preferences/use-preference', () => ({usePreference: () => createSignal(false),}));-vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice: () => true }));+vi.mock('@core/mobile/isTouchDevice', () => ({+ isTouchDevice: () => fixture.touch,+}));vi.mock('@core/mobile/haptics', () => ({ hapticImpact: vi.fn() }));vi.mock('@core/mobile/virtualKeyboard', () => ({virtualKeyboardVisible: () => false,@@ -111,12 +115,32 @@ vi.mock('../components/pipeline-sidebar', () => ({vi.mock('../components/pipeline-dialog', () => ({PipelineDialog: () => null,}));-vi.mock('./record-detail', () => ({ CrmRecordDetail: () => null }));+vi.mock('./record-detail', () => ({+ CrmRecordDetail: (props: {+ viewName: string;+ record: { type: string; id: string };+ }) => (+ <div>+ {props.viewName} record {props.record.type}:{props.record.id}+ </div>+ ),+}));vi.mock('./export-companies', () => ({ CrmExport: () => null }));vi.mock('./import-companies', () => ({ CrmImport: () => null }));vi.mock('./pipeline', () => ({- PipelineView: (props: { pipeline: { name: string } }) => (- <div>{props.pipeline.name} table</div>+ PipelineView: (props: {+ pipeline: { name: string };+ onOpenRecord(record: { type: 'company'; id: string }): void;+ }) => (+ <div>+ {props.pipeline.name} table+ <button+ type="button"+ onClick={() => props.onOpenRecord({ type: 'company', id: 'acme' })}+ >+ Open Acme+ </button>+ </div>),}));vi.mock('./saved-views-menu', () => ({@@ -130,6 +154,7 @@ vi.mock('../context/crm-context', () => ({useCrmContext: () => ({pipelinesEnabled: () => () => fixture.pipelinesEnabled,listsEnabled: () => () => fixture.listsEnabled,+ createNavigation: () => ({ openWithSplit: fixture.openWithSplit }),createPipelines: () => ({pipelines: () => [{ id: 'sales', name: 'Sales' }],loading: () => false,@@ -166,14 +191,22 @@ afterEach(() => {cleanup();fixture.pipelinesEnabled = true;fixture.listsEnabled = true;+ fixture.touch = true;+ fixture.openWithSplit.mockReset();});-function setup() {- const [activeTab, setActiveTab] = createSignal<string | undefined>('active');+function setup(initialTab = 'active') {+ const [activeTab, setActiveTab] = createSignal<string | undefined>(+ initialTab+ );fixture.workspace = {activeTab,setActiveTab,- host: { scopeId: 'crm', isActive: () => true },+ host: {+ scopeId: 'crm',+ isActive: () => true,+ captureEntryState: vi.fn(),+ },source: {},queryFilters: { state: { include: {} } },};@@ -220,3 +253,22 @@ it('omits pipelines and lists when those features are disabled', () => {tabs.getAllByRole('button').map((button) => button.textContent)).toEqual(['Companies', 'People']);});++it('shows the company of a pipeline row in place of the pipeline on desktop', () => {+ fixture.touch = false;+ setup('pipeline:sales');+ fireEvent.click(screen.getByRole('button', { name: 'Open Acme' }));+ expect(screen.getByText('Sales record company:acme')).toBeTruthy();+ expect(screen.queryByText('Sales table')).toBeNull();+ expect(fixture.openWithSplit).not.toHaveBeenCalled();+});++it('opens the company of a pipeline row in its own split on touch', () => {+ setup('pipeline:sales');+ fireEvent.click(screen.getByRole('button', { name: 'Open Acme' }));+ expect(fixture.openWithSplit).toHaveBeenCalledExactlyOnceWith(+ { type: 'company', id: 'acme' },+ { activate: true }+ );+ expect(screen.getByText('Sales table')).toBeTruthy();+});diff --git a/apps/web/src/features/crm/views/crm-workspace.tsx b/apps/web/src/features/crm/views/crm-workspace.tsxindex 9213dcae14..3841347584 100644--- a/apps/web/src/features/crm/views/crm-workspace.tsx+++ b/apps/web/src/features/crm/views/crm-workspace.tsx@@ -206,8 +206,13 @@ export function CrmWorkspaceView(props: {copyViewLink,} = useCrmContext();const view = useCrmWorkspace();+ const { openWithSplit } = useCrmContext().createNavigation();const [selectedRecord, setSelectedRecord] = createSignal<CrmRecordRef>();const closeRecord = () => setSelectedRecord(undefined);+ const showRecord = (record: CrmRecordRef) => {+ view.host.captureEntryState();+ setSelectedRecord(record);+ };const openRecord = (entity: EntityData) => {const type = isCrmCompanyEntity(entity)? 'company'@@ -216,10 +221,17 @@ export function CrmWorkspaceView(props: {: undefined;if (!type) return false;view.soup.focus.set(entity.id);- view.host.captureEntryState();- setSelectedRecord({ type, id: entity.id, name: entity.name });+ showRecord({ type, id: entity.id, name: entity.name });return true;};+ // Touch shows records in their own split, as the lists do.+ const openPipelineRecord = (record: {+ type: 'company' | 'contact';+ id: string;+ }) =>+ isTouchDevice()+ ? openWithSplit(record, { activate: true })+ : showRecord({ ...record, name: '' });const apply = useApplyCrmView();const [collapsed, setCollapsed] = usePreference('macro:pref:crm:sidebar-collapsed',@@ -392,7 +404,7 @@ export function CrmWorkspaceView(props: {{(record) => (<CrmRecordDetailrecord={record}- viewName={title()}+ viewName={activePipeline()?.name ?? title()}onClose={closeRecord}navigation={<NavigationToggle onExpand={() => setCollapsed(false)}>@@ -402,7 +414,7 @@ export function CrmWorkspaceView(props: {/>)}</Show>- <Show when={pipelineId()} keyed>+ <Show when={!selectedRecord() && pipelineId()} keyed>{(id) => (<Show when={activePipeline()}>{(pipeline) => (@@ -418,6 +430,7 @@ export function CrmWorkspaceView(props: {})}onTrashed={() => navigate('active')}+ onOpenRecord={openPipelineRecord}navigation={<Show when={!isTouchDevice()}><NavigationToggle onExpand={() => setCollapsed(false)}>diff --git a/apps/web/src/features/crm/views/pipeline.tsx b/apps/web/src/features/crm/views/pipeline.tsxindex b1927fb3f0..50f3eba554 100644--- a/apps/web/src/features/crm/views/pipeline.tsx+++ b/apps/web/src/features/crm/views/pipeline.tsx@@ -27,6 +27,7 @@ export function PipelineView(props: {onCopyLink(): void;/** After the pipeline moves to trash, leave its page. */onTrashed(): void;+ onOpenRecord?(record: { type: 'company' | 'contact'; id: string }): void;}) {const [pending, setPending] = createSignal(false);const [error, setError] = createSignal('');@@ -145,6 +146,7 @@ export function PipelineView(props: {</Show><props.Editorpipeline={props.pipeline}+ onOpenRecord={props.onOpenRecord}actions={<Show when={isTouchDevice()}><Buttondiff --git a/apps/web/src/features/database/components/grid-cell.test.tsx b/apps/web/src/features/database/components/grid-cell.test.tsxindex 1b8740d0e6..765e8b54ef 100644--- a/apps/web/src/features/database/components/grid-cell.test.tsx+++ b/apps/web/src/features/database/components/grid-cell.test.tsx@@ -503,6 +503,48 @@ describe('grid cell', () => {expect(onWrite).toHaveBeenCalledExactlyOnceWith(null);});+ it('opens an entity it is given an opener for on click and Enter, and still edits with F2', async () => {+ const onOpenMention = vi.fn();+ const onWrite = vi.fn(async () => true);+ const [value, setValue] = createSignal<DatabaseCellValue>('company-1');+ render(() => (+ <GridCell+ column={{+ ...column,+ name: 'Company',+ dataType: 'ENTITY',+ specificEntityType: 'COMPANY',+ }}+ value={value()}+ canEdit+ onWrite={onWrite}+ onAddOption={vi.fn(async () => true)}+ onMention={vi.fn(async () => true)}+ onOpenMention={onOpenMention}+ renderMentionValue={() => <span>Acme</span>}+ renderMentionPicker={(props) => <MentionPicker {...props} />}+ />+ ));+ const button = screen.getByRole('button', { name: 'Company: Acme' });+ expect(button.getAttribute('aria-description')).toBe('Click to open');+ fireEvent.click(button);+ expect(onOpenMention).toHaveBeenLastCalledWith('company-1', 'COMPANY');+ expect(screen.queryByRole('dialog')).toBeNull();+ fireEvent.keyDown(button, { key: 'Enter' });+ expect(onOpenMention).toHaveBeenCalledTimes(2);+ expect(screen.queryByRole('dialog')).toBeNull();+ fireEvent.keyDown(button, { key: 'F2' });+ await screen.findByRole('textbox', { name: 'Find an item' });+ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());+ // An empty cell has nothing to open, so a click picks one.+ setValue(null);+ fireEvent.click(screen.getByRole('button', { name: /Company: Empty/ }));+ await screen.findByRole('textbox', { name: 'Find an item' });+ expect(onOpenMention).toHaveBeenCalledTimes(2);+ expect(onWrite).not.toHaveBeenCalled();+ });+it('keeps the selected label through a delayed write and hands it to the entity renderer when the schema arrives', async () => {const [value, setValue] = createSignal<DatabaseCellValue>(null);const [schema, setSchema] = createSignal<DatabaseViewColumn>({diff --git a/apps/web/src/features/database/components/grid-cell.tsx b/apps/web/src/features/database/components/grid-cell.tsxindex 9bbd681af6..62449ccefa 100644--- a/apps/web/src/features/database/components/grid-cell.tsx+++ b/apps/web/src/features/database/components/grid-cell.tsx@@ -68,6 +68,8 @@ export type GridCellProps = GridCellEditorOptions & {renderMentionPicker?: (props: DatabaseMentionPickerProps) => JSX.Element;renderMentionValue?: (id: string, type: DatabaseEntityType) => JSX.Element;onMention?: (mention: DatabaseMention) => Promise<boolean>;+ /** Click and Enter open the cell's mention instead of editing it; F2 and typing still edit. */+ onOpenMention?: (id: string, type: DatabaseEntityType) => void;onWrite: (value: DatabaseCellValue) => Promise<boolean>;onAddOption: (label: string, value?: DatabaseCellValue) => Promise<boolean>;};@@ -130,6 +132,14 @@ export function GridCell(props: GridCellProps) {};const hasResolvedMentionLabel = () =>isEntity() && props.value !== null && !mentionPreview();+ const openMention = () => {+ const open = props.onOpenMention;+ const id = props.value;+ const type = props.column.specificEntityType;+ return open && isEntity() && typeof id === 'string' && type+ ? () => open(id, type)+ : undefined;+ };let cell: HTMLDivElement | undefined;const isBoolean = () =>props.column.dataType === 'BOOLEAN' && !props.column.isMultiSelect;@@ -387,6 +397,7 @@ export function GridCell(props: GridCellProps) {trigger = element;}}onNavigate={props.onNavigate}+ onOpen={openMention()}onBeginEdit={beginEdit}onClearEntity={() => {setSelectedMention(undefined);@@ -494,12 +505,15 @@ function TextCell(props: {renderMentionValue?: (id: string, type: DatabaseEntityType) => JSX.Element;ref: (element: HTMLButtonElement) => void;onNavigate?: (direction: 1 | -1) => boolean;+ onOpen?: () => void;onBeginEdit: (seed?: string, event?: Event) => void;onClearEntity: () => void;}) {// Refreshes rebuild row objects; only a changed value may rerun renderers and remount previews.const value = createMemo(() => props.value);const formatted = () => formatCellValue(props.column, value());+ const hint = () =>+ props.onOpen ? 'Click to open' : props.editable ? 'Click to edit' : '';return (<buttonref={props.ref}@@ -513,12 +527,10 @@ function TextCell(props: {aria-label={props.hasResolvedMentionLabel? undefined- : `${props.column.name}: ${props.mentionPreview?.mention.label || formatted() || props.emptyLabel || 'Empty'}${props.editable ? '. Click to edit' : ''}`+ : `${props.column.name}: ${props.mentionPreview?.mention.label || formatted() || props.emptyLabel || 'Empty'}${hint() ? `. ${hint()}` : ''}`}aria-description={- props.hasResolvedMentionLabel && props.editable- ? 'Click to edit'- : undefined+ props.hasResolvedMentionLabel && hint() ? hint() : undefined}aria-readonly={!props.editable}title={@@ -526,8 +538,24 @@ function TextCell(props: {(!props.isEntity && formatted()) ||undefined}- onClick={(event) => props.editable && props.onBeginEdit(undefined, event)}+ onClick={(event) => {+ if (props.onOpen) props.onOpen();+ else if (props.editable) props.onBeginEdit(undefined, event);+ }}onKeyDown={(event) => {+ if (+ props.onOpen &&+ event.key === 'Enter' &&+ !isComposingKey(event) &&+ !event.metaKey &&+ !event.ctrlKey &&+ !event.altKey+ ) {+ event.preventDefault();+ event.stopPropagation();+ props.onOpen();+ return;+ }if (!props.editable) return;if (isComposingKey(event)) {props.onBeginEdit('', event);diff --git a/apps/web/src/features/database/views/database-records-view.tsx b/apps/web/src/features/database/views/database-records-view.tsxindex 0fcb463e28..b1a8fdeaa7 100644--- a/apps/web/src/features/database/views/database-records-view.tsx+++ b/apps/web/src/features/database/views/database-records-view.tsx@@ -32,7 +32,10 @@ import { filterConditionCount } from '../components/database-view-filters';import { GridCell, type GridCellProps } from '../components/grid-cell';import { RecordPanel } from '../components/record-panel';import type { DatabaseRowsSource } from '../context/table-source';-import type { DatabaseColumnType } from '../core/column-inference';+import type {+ DatabaseColumnType,+ DatabaseEntityType,+} from '../core/column-inference';import type {DatabaseColumnCastsSource,DatabaseColumnConversion,@@ -110,6 +113,8 @@ export type DatabaseRecordsViewProps = {renderTextValue?: GridCellProps['renderTextValue'];renderMentionPicker?: GridCellProps['renderMentionPicker'];renderMentionValue?: GridCellProps['renderMentionValue'];+ /** Opens what a record's title mentions, such as a pipeline row's company, in place of editing it. */+ onOpenTitleMention?: (id: string, type: DatabaseEntityType) => void;renderRelationCell?: (props: RelationCellProps) => JSX.Element;relationTables?: { id: string; name: string }[];columnCasts?: DatabaseColumnCastsSource;@@ -273,6 +278,7 @@ export function DatabaseRecordsView(props: DatabaseRecordsViewProps) {) {const write = (value: DatabaseCellValue) =>writeValue(row(), column(), value);+ const isTitle = () => column().id === titleColumn(columns())?.id;const relationCell = () => {const render = props.renderRelationCell;const current = column();@@ -287,15 +293,14 @@ export function DatabaseRecordsView(props: DatabaseRecordsViewProps) {<GridCell{...options}column={column()}- emptyLabel={- column().id === titleColumn(columns())?.id ? 'Unnamed' : undefined- }+ emptyLabel={isTitle() ? 'Unnamed' : undefined}value={rowValue(row(), column().id)}canEdit={props.canEdit}renderTextEditor={props.renderTextEditor}renderTextValue={props.renderTextValue}renderMentionPicker={props.renderMentionPicker}renderMentionValue={props.renderMentionValue}+ onOpenMention={isTitle() ? props.onOpenTitleMention : undefined}onMention={(mention) =>writeValue(row(), column(), mention.id, undefined, {dataType: 'ENTITY',diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.mdindex cac63d9f80..b128c1d804 100644--- a/docs/AGENT_GUIDE/surfaces.md+++ b/docs/AGENT_GUIDE/surfaces.md@@ -2037,10 +2037,15 @@ and can change access later through the standard **Share** dialog. Underpipeline private. **Copy Link** copies a CRM link that opens this pipeline foranyone who has access. On mobile, team access is in the **Team** tab.-The first column is a required company/contact reference. The same company or-contact can occur in multiple rows in a pipeline and can also belong to other-pipelines. Each row has its own field values; **Duplicate** copies a row into a new-entry referencing the same company or contact. The reference column+The first column is a required company/contact reference. Clicking a filled+reference, or pressing Enter on it, opens that company or contact; on desktop it+opens in place with the pipeline name in its breadcrumb (choose it to return),+and on mobile in its own view. The same applies to the reference shown as a+board card's or record panel's title. To change which record a row references,+focus the cell and press F2 or start typing; an empty reference cell opens the+picker on click. The same company or contact can occur in multiple rows in a+pipeline and can also belong to other pipelines. Each row has its own field+values; **Duplicate** copies a row into a new entry referencing the same company or contact. The reference columncan be renamed but cannot be removed or changed to another type. Stage, Owner,and Revenue are independent pipeline fields; editing them does not modify thecompany's CRM fields. Use **Add column** or a column header's menu to customize