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(databases): open file references on click and edit on right-click (#8999)

Wolf Mermelsteind3b6c5be09f2
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 83ab522222..e9a169d992 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -28,6 +28,12 @@ Split dragging and composer reflow have a backend-free browser regression:
`bunx playwright test --config src/lib/core/component/Resize/browser-test/playwright.config.ts`.
It exercises the real resize solver, scroll container, and Lexical layout primitive.
+Database document-reference cells have a backend-free desktop/touch regression:
+`bunx playwright test --config src/features/block-database/browser-test/playwright.config.ts references.browser.e2e.ts`.
+It uses the real records view with a local source and picker to exercise opening,
+replacement, cancellation, keyboard editing, and read-only references. Navigation
+adapter tests separately check file types, access failures, and split selection.
+
Discussion link scrolling has a backend-free browser regression:
`bunx playwright test --config src/lib/core/messages/browser-test/playwright.config.ts`.
diff --git a/apps/web/src/features/block-database/browser-test/records.tsx b/apps/web/src/features/block-database/browser-test/records.tsx
index f1dfeedef8..abc0d75f1a 100644
--- a/apps/web/src/features/block-database/browser-test/records.tsx
+++ b/apps/web/src/features/block-database/browser-test/records.tsx
@@ -1,7 +1,7 @@
import '@app/index.css';
import { okAsync, ResultAsync } from 'neverthrow';
-import { createSignal } from 'solid-js';
-import { render } from 'solid-js/web';
+import { createSignal, onMount, Show } from 'solid-js';
+import { Portal, render } from 'solid-js/web';
import { CellMentionEditor } from '../../../components/cell-text-editor/CellMentionEditor';
import type {
DatabaseRowsSnapshot,
@@ -13,6 +13,8 @@ import { DatabaseRecordsView } from '../../database/views/database-records-view'
// A host owns the records and writes. No database entity, saved view, or app provider.
function RecordsFixture() {
+ const references = new URLSearchParams(location.search).has('references');
+ const [opened, setOpened] = createSignal('');
const rapid = new URLSearchParams(location.search).has('rapid');
const holdWrites = new URLSearchParams(location.search).has('holdWrites');
let releaseWrites!: () => void;
@@ -31,6 +33,14 @@ function RecordsFixture() {
options: [],
},
];
+ if (references)
+ initialColumns.push({
+ ...initialColumns[0],
+ id: 'file',
+ name: 'File',
+ dataType: 'ENTITY',
+ specificEntityType: 'DOCUMENT',
+ });
if (rapid)
initialColumns.push(
...['notes', 'detail'].map((id) => ({
@@ -41,7 +51,15 @@ function RecordsFixture() {
);
const [columns, setColumns] = createSignal(initialColumns);
const [snapshot, setSnapshot] = createSignal<DatabaseRowsSnapshot>({
- rows: [{ rowId: 'one', cells: { name: 'First record' } }],
+ rows: [
+ {
+ rowId: 'one',
+ cells: {
+ name: 'First record',
+ ...(references ? { file: 'project-plan' } : {}),
+ },
+ },
+ ],
retained: [],
version: 1,
});
@@ -115,34 +133,100 @@ function RecordsFixture() {
{JSON.stringify(snapshot().rows)}
</output>
</div>
- <DatabaseRecordsView
- name="Embedded records"
- source={source}
- canEdit={canEdit()}
- renderTextEditor={
- rapid
- ? (props) => (
- <CellMentionEditor
- {...props}
- convertPaste={(text) => text}
- renderMenu={() => null}
- />
- )
- : undefined
- }
- view={{
- query: { filter: null },
- layout: { kind: 'table', columns: [] },
- }}
- stored={false}
- boardPositions={{
- state: () => ({ kind: 'ready', positions: [] }),
- setPositions: () => {},
- move: () => okAsync({ positions: [], tableVersion: 1 }),
- }}
- />
+ <div class="flex min-h-0 flex-1">
+ <section class="flex min-w-0 flex-1 flex-col">
+ <DatabaseRecordsView
+ name="Embedded records"
+ source={source}
+ canEdit={canEdit()}
+ onOpenDocumentMention={setOpened}
+ renderMentionValue={(id) => (
+ <span>
+ {id === 'project-plan' ? 'Project plan' : 'Design notes'}
+ </span>
+ )}
+ renderMentionPicker={(picker) => <ReferencePicker {...picker} />}
+ renderTextEditor={
+ rapid
+ ? (props) => (
+ <CellMentionEditor
+ {...props}
+ convertPaste={(text) => text}
+ renderMenu={() => null}
+ />
+ )
+ : undefined
+ }
+ view={{
+ query: { filter: null },
+ layout: { kind: 'table', columns: [] },
+ }}
+ stored={false}
+ boardPositions={{
+ state: () => ({ kind: 'ready', positions: [] }),
+ setPositions: () => {},
+ move: () => okAsync({ positions: [], tableVersion: 1 }),
+ }}
+ />
+ </section>
+ <Show when={opened()}>
+ <aside
+ aria-label="Opened file"
+ class="w-80 border-l border-edge-muted p-4"
+ >
+ <h1>
+ {opened() === 'project-plan' ? 'Project plan' : 'Design notes'}
+ </h1>
+ <p>Referenced file opened beside the database.</p>
+ </aside>
+ </Show>
+ </div>
</main>
);
}
+function ReferencePicker(
+ props: import('../../database/components/grid-cell').DatabaseMentionPickerProps
+) {
+ let input!: HTMLInputElement;
+ onMount(() => input.focus());
+ return (
+ <Portal mount={props.mount}>
+ <div
+ role="dialog"
+ aria-label="Choose file"
+ class="menu-surface fixed z-50 flex flex-col gap-2 p-3"
+ style={{
+ top: `${props.anchor?.getBoundingClientRect().bottom ?? 0}px`,
+ left: `${props.anchor?.getBoundingClientRect().left ?? 0}px`,
+ }}
+ >
+ <input
+ ref={input}
+ aria-label="Find a file"
+ value={props.search}
+ onInput={(event) => props.onSearchChange?.(event.currentTarget.value)}
+ onKeyDown={(event) => {
+ if (event.key === 'Escape') {
+ event.stopPropagation();
+ props.onClose();
+ }
+ }}
+ />
+ <button
+ onClick={() =>
+ props.onSelect({
+ id: 'design-notes',
+ entityType: 'DOCUMENT',
+ label: 'Design notes',
+ })
+ }
+ >
+ Design notes
+ </button>
+ </div>
+ </Portal>
+ );
+}
+
render(() => <RecordsFixture />, document.getElementById('root')!);
diff --git a/apps/web/src/features/block-database/browser-test/references.browser.e2e.ts b/apps/web/src/features/block-database/browser-test/references.browser.e2e.ts
new file mode 100644
index 0000000000..e2ac16ab26
--- /dev/null
+++ b/apps/web/src/features/block-database/browser-test/references.browser.e2e.ts
@@ -0,0 +1,81 @@
+import { expect, test } from '@playwright/test';
+import { openFixture } from './open-fixture';
+
+test('opens file references and replaces them from the cell context menu', async ({
+ page,
+}) => {
+ await page.route('https://**', (route) => route.abort());
+ await page.route('**/__macro_dev/**', (route) => route.abort());
+ await openFixture(
+ page,
+ '/src/features/block-database/browser-test/records.html?references'
+ );
+ const grid = page.getByRole('grid', { name: 'Embedded records' });
+ const file = page.getByRole('button', { name: 'File: Project plan' });
+ await file.click();
+ await expect(page.getByRole('dialog')).toHaveCount(0);
+ await expect(
+ page.getByRole('complementary', { name: 'Opened file' })
+ ).toContainText('Project plan');
+ await expect(grid).toBeVisible();
+ await file.click({ button: 'right' });
+ const picker = page.getByRole('dialog', { name: 'Choose file' });
+ await expect(picker).toBeVisible();
+ await expect(page.getByRole('menu')).toHaveCount(0);
+ await page.getByRole('textbox', { name: 'Find a file' }).press('Escape');
+ await expect(picker).toHaveCount(0);
+ await expect(file).toBeFocused();
+ await file.click({ button: 'right' });
+ await picker.getByRole('button', { name: 'Design notes' }).click();
+ const replacement = page.getByRole('button', { name: 'File: Design notes' });
+ await expect(replacement).toBeVisible();
+ await expect(page.getByLabel('Stored records')).toContainText('design-notes');
+ await replacement.focus();
+ await replacement.press('Enter');
+ await expect(
+ page.getByRole('complementary', { name: 'Opened file' })
+ ).toContainText('Design notes');
+ await replacement.press('F2');
+ await expect(picker).toBeVisible();
+ await page.getByRole('textbox', { name: 'Find a file' }).press('Escape');
+ await page.getByRole('button', { name: 'Read only', exact: true }).click();
+ await replacement.click();
+ await expect(grid).toBeVisible();
+ await replacement.click({ button: 'right' });
+ await expect(picker).toHaveCount(0);
+});
+
+test.describe('touch references', () => {
+ test.use({
+ viewport: { width: 390, height: 844 },
+ hasTouch: true,
+ isMobile: true,
+ });
+ test('empty file references still pick on click and touch taps open populated files', async ({
+ page,
+ }) => {
+ await page.emulateMedia({ reducedMotion: 'reduce' });
+ await page.route('https://**', (route) => route.abort());
+ await page.route('**/__macro_dev/**', (route) => route.abort());
+ await openFixture(
+ page,
+ '/src/features/block-database/browser-test/records.html?references'
+ );
+ const file = page.getByRole('button', { name: 'File: Project plan' });
+ await file.focus();
+ await file.press('Delete');
+ const empty = page.getByRole('button', { name: /^File: Empty/ }).first();
+ await empty.click();
+ await page
+ .getByRole('dialog', { name: 'Choose file' })
+ .getByRole('button', { name: 'Design notes' })
+ .click();
+ await page.getByRole('button', { name: 'File: Design notes' }).tap();
+ await expect(
+ page.getByRole('complementary', { name: 'Opened file' })
+ ).toContainText('Design notes');
+ await expect(
+ page.getByRole('grid', { name: 'Embedded records' })
+ ).toBeVisible();
+ });
+});
diff --git a/apps/web/src/features/block-database/component/DatabaseGrid.tsx b/apps/web/src/features/block-database/component/DatabaseGrid.tsx
index bff35f651f..5b379a7973 100644
--- a/apps/web/src/features/block-database/component/DatabaseGrid.tsx
+++ b/apps/web/src/features/block-database/component/DatabaseGrid.tsx
@@ -52,6 +52,7 @@ import {
DatabaseTextEditor,
DatabaseTextValue,
} from '../database-mentions';
+import { createDatabaseDocumentNavigation } from '../navigation-adapter';
import {
type DatabaseGridHost,
trackQueryRuns,
@@ -163,6 +164,7 @@ function RelatedDatabaseSync(props: {
function TableAdapter(props: DatabaseGridProps & { tableId: string }) {
const queryClient = useQueryClient();
+ const openDocumentMention = createDatabaseDocumentNavigation();
// Keep the final schema for this table available to already-queued writes
// after its tab is closed; a new selected table must never redirect them.
let ownedTable = props.table;
@@ -359,6 +361,7 @@ function TableAdapter(props: DatabaseGridProps & { tableId: string }) {
renderTextValue={renderTextValue}
renderMentionPicker={renderMentionPicker}
renderMentionValue={renderMentionValue}
+ onOpenDocumentMention={openDocumentMention}
renderRelationCell={(cell) => (
<DatabaseRelationCell
{...cell}
diff --git a/apps/web/src/features/block-database/navigation-adapter.test.ts b/apps/web/src/features/block-database/navigation-adapter.test.ts
new file mode 100644
index 0000000000..8963eb627c
--- /dev/null
+++ b/apps/web/src/features/block-database/navigation-adapter.test.ts
@@ -0,0 +1,76 @@
+import { createRoot } from 'solid-js';
+import { beforeEach, expect, it, vi } from 'vitest';
+import { createDatabaseDocumentNavigation } from './navigation-adapter';
+
+const { openWithSplit, getItemPreview, isTouchDevice } = vi.hoisted(() => ({
+ openWithSplit: vi.fn(),
+ getItemPreview: vi.fn(),
+ isTouchDevice: vi.fn(() => false),
+}));
+vi.mock('@components/app/split-layout/layout', () => ({
+ useSplitLayout: () => ({ openWithSplit }),
+}));
+vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice }));
+vi.mock('@queries/preview', async (original) => ({
+ ...(await original<typeof import('@queries/preview')>()),
+ getItemPreview,
+}));
+beforeEach(() => {
+ vi.clearAllMocks();
+ isTouchDevice.mockReturnValue(false);
+});
+
+it.each(['md', 'pdf', 'png'] as const)(
+ 'opens a %s file beside the database after resolving its type',
+ async (fileType) => {
+ getItemPreview.mockResolvedValue({
+ loading: false,
+ access: 'access',
+ fileType,
+ });
+ createRoot((dispose) => {
+ createDatabaseDocumentNavigation()('file-id');
+ dispose();
+ });
+ await vi.waitFor(() => expect(openWithSplit).toHaveBeenCalledOnce());
+ expect(getItemPreview).toHaveBeenCalledWith({
+ type: 'document',
+ id: 'file-id',
+ });
+ expect(openWithSplit).toHaveBeenCalledWith(
+ { type: fileType === 'png' ? 'image' : fileType, id: 'file-id' },
+ { preferNewSplit: true }
+ );
+ }
+);
+
+it.each(['no_access', 'does_not_exist'])(
+ 'does not navigate for a %s reference',
+ async (access) => {
+ getItemPreview.mockResolvedValue({ loading: false, access });
+ createRoot((dispose) => {
+ createDatabaseDocumentNavigation()('file-id');
+ dispose();
+ });
+ await getItemPreview.mock.results[0].value;
+ expect(openWithSplit).not.toHaveBeenCalled();
+ }
+);
+
+it('uses forward navigation on touch', async () => {
+ isTouchDevice.mockReturnValue(true);
+ getItemPreview.mockResolvedValue({
+ loading: false,
+ access: 'access',
+ fileType: 'md',
+ });
+ createRoot((dispose) => {
+ createDatabaseDocumentNavigation()('file-id');
+ dispose();
+ });
+ await vi.waitFor(() => expect(openWithSplit).toHaveBeenCalledOnce());
+ expect(openWithSplit).toHaveBeenCalledWith(
+ { type: 'md', id: 'file-id' },
+ { preferNewSplit: false }
+ );
+});
diff --git a/apps/web/src/features/block-database/navigation-adapter.ts b/apps/web/src/features/block-database/navigation-adapter.ts
new file mode 100644
index 0000000000..3b7e020e31
--- /dev/null
+++ b/apps/web/src/features/block-database/navigation-adapter.ts
@@ -0,0 +1,26 @@
+import { useSplitLayout } from '@components/app/split-layout/layout';
+import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import { fireAndForget } from '@core/util/fireAndForget';
+import { openInNewSplitForMention } from '@core/util/openInNewSplit';
+import { Telemetry } from '@macro-inc/observability';
+import { getItemPreview, isAccessiblePreviewItem } from '@queries/preview';
+
+/** Capture the database's source panel before the authorized preview resolves. */
+export function createDatabaseDocumentNavigation() {
+ const { openWithSplit } = useSplitLayout();
+ async function open(id: string) {
+ await Telemetry.span('database.reference.open', async (span) => {
+ span.setAttr('document.id', id);
+ const preview = await getItemPreview({ type: 'document', id });
+ if (!isAccessiblePreviewItem(preview)) return;
+ openWithSplit(
+ {
+ type: fileTypeToBlockName(preview.subType?.type ?? preview.fileType),
+ id,
+ },
+ { preferNewSplit: openInNewSplitForMention(undefined, true) }
+ );
+ });
+ }
+ return (id: string) => fireAndForget(open(id), 'database');
+}
diff --git a/apps/web/src/features/database/components/grid-cell.test.tsx b/apps/web/src/features/database/components/grid-cell.test.tsx
index 4149c8281a..bb92151352 100644
--- a/apps/web/src/features/database/components/grid-cell.test.tsx
+++ b/apps/web/src/features/database/components/grid-cell.test.tsx
@@ -675,6 +675,48 @@ describe('grid cell', () => {
expect(onWrite).not.toHaveBeenCalled();
});
+ it.each([true, false])(
+ 'right-click changes an openable reference only when editable (%s)',
+ async (canEdit) => {
+ const onOpenMention = vi.fn();
+ const onMention = vi.fn(async () => true);
+ render(() => (
+ <GridCell
+ column={{
+ ...column,
+ name: 'File',
+ dataType: 'ENTITY',
+ specificEntityType: 'DOCUMENT',
+ }}
+ value="project-plan"
+ canEdit={canEdit}
+ onWrite={vi.fn(async () => true)}
+ onAddOption={vi.fn(async () => true)}
+ onOpenMention={onOpenMention}
+ onMention={onMention}
+ renderMentionValue={() => <span>Project plan</span>}
+ renderMentionPicker={(props) => <MentionPicker {...props} />}
+ />
+ ));
+ const button = screen.getByRole('button', { name: 'File: Project plan' });
+ fireEvent.contextMenu(button);
+ expect(onOpenMention).not.toHaveBeenCalled();
+ if (canEdit) {
+ await screen.findByRole('textbox', { name: 'Find an item' });
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() => expect(document.activeElement).toBe(button));
+ expect(onMention).not.toHaveBeenCalled();
+ } else {
+ expect(screen.queryByRole('dialog')).toBeNull();
+ fireEvent.click(button);
+ expect(onOpenMention).toHaveBeenCalledExactlyOnceWith(
+ 'project-plan',
+ 'DOCUMENT'
+ );
+ }
+ }
+ );
+
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.tsx
index 6b2b6310a0..2781715621 100644
--- a/apps/web/src/features/database/components/grid-cell.tsx
+++ b/apps/web/src/features/database/components/grid-cell.tsx
@@ -597,6 +597,12 @@ function TextCell(props: {
(!props.isEntity && formatted()) ||
undefined
}
+ onContextMenu={(event) => {
+ if (!props.onOpen || !props.editable) return;
+ event.preventDefault();
+ event.stopPropagation();
+ props.onBeginEdit(undefined, event);
+ }}
onClick={(event) => {
if (props.onOpen) props.onOpen();
else if (props.editable) props.onBeginEdit(undefined, event);
diff --git a/apps/web/src/features/database/views/database-records-view.tsx b/apps/web/src/features/database/views/database-records-view.tsx
index f2b856d8b4..9c0fb76aac 100644
--- a/apps/web/src/features/database/views/database-records-view.tsx
+++ b/apps/web/src/features/database/views/database-records-view.tsx
@@ -125,6 +125,8 @@ export type DatabaseRecordsViewProps = {
renderTextValue?: GridCellProps['renderTextValue'];
renderMentionPicker?: GridCellProps['renderMentionPicker'];
renderMentionValue?: GridCellProps['renderMentionValue'];
+ /** Opens document/file references in any column, including record panel fields. */
+ onOpenDocumentMention?: (id: string) => void;
/** 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;
@@ -347,7 +349,14 @@ export function DatabaseRecordsView(props: DatabaseRecordsViewProps) {
renderTextValue={props.renderTextValue}
renderMentionPicker={props.renderMentionPicker}
renderMentionValue={props.renderMentionValue}
- onOpenMention={isTitle() ? props.onOpenTitleMention : undefined}
+ onOpenMention={
+ column().specificEntityType === 'DOCUMENT' &&
+ props.onOpenDocumentMention
+ ? props.onOpenDocumentMention
+ : isTitle()
+ ? props.onOpenTitleMention
+ : undefined
+ }
onMention={(mention) =>
writeValue(row(), column(), mention.id, undefined, {
dataType: 'ENTITY',
diff --git a/docs/agent-guide/databases.md b/docs/agent-guide/databases.md
index dbe1b282e0..3c6700138a 100644
--- a/docs/agent-guide/databases.md
+++ b/docs/agent-guide/databases.md
@@ -221,7 +221,12 @@ text. Choosing Text explicitly disables inference. Populated columns never infer
new type. Reference cells use Macro’s native mention menu, limited to the selected
kind (for example, People shows users, Tasks shows tasks). Arrow keys navigate and
Enter chooses; Escape returns without changing the value. Delete clears a selected
-reference cell. Text supports markdown and inline native mentions such as
+reference cell. Click a populated document/file reference (or press Enter) to open
+it in another split while keeping the database open. On touch, tapping uses the
+app's normal forward navigation. Right-click a populated editable reference to
+choose a replacement; F2 also opens the picker, and Escape cancels. Empty
+references still open the picker on click. Read-only references can be opened but
+not changed. Text supports markdown and inline native mentions such as
`Say hi to @Maya`, stored using the same mention encoding as documents. A mention
inside a sentence preserves Text.