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(databases): open the full table from a row clicked in a document (#9778)

Wolf Mermelsteindac67be4c45d
diff --git a/apps/web/src/features/block-database/browser-test/document.browser.e2e.ts b/apps/web/src/features/block-database/browser-test/document.browser.e2e.ts
index 452ad6c2d7..3fcb165cd4 100644
--- a/apps/web/src/features/block-database/browser-test/document.browser.e2e.ts
+++ b/apps/web/src/features/block-database/browser-test/document.browser.e2e.ts
@@ -64,40 +64,42 @@ async function fixture(page: Page, multipleTables = false) {
const request = route.request();
const url = new URL(request.url());
if (url.pathname.endsWith('/items/soup/graphql')) {
- await route.fulfill({
- json: {
- data: {
- user: {
- soup: {
- nextCursor: null,
- items: [storedName, ...externalRows].map((name, index) => ({
- __typename: 'GraphqlSoupDatabaseRow',
- id: index
- ? `${rowId.slice(0, -4)}${String(index + 1).padStart(4, '0')}`
- : rowId,
- tableId,
- position: '80',
- ownerId: detail.database.owner_id,
- createdAt: detail.database.created_at,
- updatedAt: detail.database.created_at,
- cacheProjection: null,
- notifications: [],
- properties: [
- {
- id: definitionId,
- propertyDefinitionId: definitionId,
- value: {
- __typename: 'GraphqlStringPropertyValue',
- stringValue: name,
- },
- },
- ],
- })),
- },
+ const items = [storedName, ...externalRows].map((name, index) => ({
+ __typename: 'GraphqlSoupDatabaseRow',
+ id: index
+ ? `${rowId.slice(0, -4)}${String(index + 1).padStart(4, '0')}`
+ : rowId,
+ tableId,
+ position: '80',
+ ownerId: detail.database.owner_id,
+ createdAt: detail.database.created_at,
+ updatedAt: detail.database.created_at,
+ cacheProjection: null,
+ notifications: [],
+ properties: [
+ {
+ id: definitionId,
+ propertyDefinitionId: definitionId,
+ value: {
+ __typename: 'GraphqlStringPropertyValue',
+ stringValue: name,
},
},
- },
- });
+ ],
+ }));
+ // Rows are read through the view's own page; other queries read soup.
+ const user =
+ request.postDataJSON()?.operationName === 'DatabaseViewRows'
+ ? {
+ id: detail.database.owner_id,
+ databaseViewRows: {
+ items,
+ nextCursor: null,
+ version: detail.tables[0].table.version,
+ },
+ }
+ : { soup: { nextCursor: null, items } };
+ await route.fulfill({ json: { data: { user } } });
return;
}
if (url.pathname.endsWith('/databases') && request.method() === 'POST') {
@@ -258,6 +260,45 @@ test('the shared toolbar changes inline filters and sorting without writing the
expect(saved.errors).toEqual([]);
});
+for (const viewport of [
+ { name: 'desktop', width: 1280, height: 800 },
+ { name: 'phone', width: 390, height: 844 },
+]) {
+ test(`a clicked row opens the underlying table at that row on ${viewport.name}`, async ({
+ page,
+ }) => {
+ const saved = await fixture(page);
+ await page.setViewportSize(viewport);
+ await page
+ .getByRole('button', { name: 'Mention existing database' })
+ .click();
+ await page.getByRole('button', { name: 'Expand database' }).click();
+ await expect(page.getByRole('grid', { name: 'Tasks' })).toBeVisible();
+ await page.getByRole('row', { name: /Finish onboarding/ }).hover();
+ await page
+ .getByRole('button', { name: 'Open Finish onboarding', exact: true })
+ .click();
+ await expect
+ .poll(async () =>
+ JSON.parse(
+ (await page.getByLabel('Opened split').textContent()) || 'null'
+ )
+ )
+ .toEqual({
+ type: 'database',
+ id: databaseId,
+ params: {
+ databaseId,
+ tableId,
+ viewId: tableId,
+ rowId,
+ },
+ });
+ await expect(page.getByRole('dialog')).toHaveCount(0);
+ expect(saved.errors).toEqual([]);
+ });
+}
+
test('the app table picker switches tables with the keyboard and restores focus when dismissed', async ({
page,
}) => {
diff --git a/apps/web/src/features/block-database/browser-test/document.tsx b/apps/web/src/features/block-database/browser-test/document.tsx
index e02bdbbbd7..a32900a08b 100644
--- a/apps/web/src/features/block-database/browser-test/document.tsx
+++ b/apps/web/src/features/block-database/browser-test/document.tsx
@@ -1,6 +1,11 @@
import '@app/index.css';
import { AnalyticsContextProvider } from '@app/lib/analytics/analytics-context';
import { PosthogProvider } from '@app/lib/analytics/posthog';
+import { setGlobalSplitManager } from '@app/signal/splitLayout';
+import type {
+ SplitContent,
+ SplitManager,
+} from '@components/app/split-layout/layoutManager';
import { DecoratorRenderer } from '@core/component/LexicalMarkdown/component/core/DecoratorRenderer';
import { DatabaseCard } from '@core/component/LexicalMarkdown/component/decorator/DatabaseCard';
import { DatabaseQuery } from '@core/component/LexicalMarkdown/component/decorator/DatabaseQuery';
@@ -46,6 +51,13 @@ queryClient.setQueryData(
databasesKeys.detail(databaseId).queryKey,
documentDatabaseDetail()
);
+// Stands in for the app's splits: shows where the card asked to navigate.
+setGlobalSplitManager({
+ openWithSplit(content: SplitContent) {
+ document.getElementById('opened')!.textContent = JSON.stringify(content);
+ return { status: 'navigating' };
+ },
+} as SplitManager);
queryClient.setQueryData(contactsKeys.all.queryKey, { contacts: [] });
queryClient.setQueryData(authKeys.userInfo.queryKey, {
id: 'macro|[email protected]',
@@ -138,6 +150,7 @@ function DocumentFixture() {
actionContext={{ disableMentionTracking: true }}
/>
</div>
+ <output id="opened" aria-label="Opened split" class="sr-only" />
<output aria-label="Document state" class="sr-only">
{state()}
</output>
diff --git a/apps/web/src/features/block-database/component/DatabaseGrid.tsx b/apps/web/src/features/block-database/component/DatabaseGrid.tsx
index dc29345ad9..064f33558e 100644
--- a/apps/web/src/features/block-database/component/DatabaseGrid.tsx
+++ b/apps/web/src/features/block-database/component/DatabaseGrid.tsx
@@ -89,6 +89,8 @@ export type DatabaseGridProps = {
actionsRef?: (actions: DatabaseRecordsActions) => void;
renderToolbar?: (actions: DatabaseRecordsActions) => JSX.Element;
onOpenRelated?: (destination: DatabaseRelatedDestination) => void;
+ /** Opens a clicked record somewhere else in place of the record panel; returns whether it did. */
+ onOpenRecord?: (rowId: string) => boolean;
};
/** Production composition. A table switch owns a new query/controller lifetime. */
@@ -342,6 +344,7 @@ function TableAdapter(props: DatabaseGridProps & { tableId: string }) {
renderMentionPicker={renderMentionPicker}
renderMentionValue={renderMentionValue}
onOpenDocumentMention={openDocumentMention}
+ onOpenRecord={props.onOpenRecord}
renderRelationCell={(cell) => (
<DatabaseRelationCell
{...cell}
diff --git a/apps/web/src/features/block-database/document-database.tsx b/apps/web/src/features/block-database/document-database.tsx
index b9a5d7ee55..b552cc3cad 100644
--- a/apps/web/src/features/block-database/document-database.tsx
+++ b/apps/web/src/features/block-database/document-database.tsx
@@ -281,6 +281,17 @@ export function DocumentDatabase(props: {
})
}
onOpenRelated={openRelated}
+ // The card is too small for the record panel: a clicked row opens in the full table.
+ // Hosts without splits, such as call chat, keep the panel.
+ onOpenRecord={(rowId) => {
+ const opened = open({
+ databaseId,
+ tableId: shown().table.id,
+ viewId: currentView().id,
+ rowId,
+ });
+ return !!opened && opened.status !== 'unavailable';
+ }}
actionsRef={setRecordActions}
/>
</div>
diff --git a/apps/web/src/features/database/README.md b/apps/web/src/features/database/README.md
index 3307d909e7..8ca422c989 100644
--- a/apps/web/src/features/database/README.md
+++ b/apps/web/src/features/database/README.md
@@ -57,6 +57,13 @@ to the host's API/service; UI capabilities only determine which controls appear.
creation. It receives the selected lane/group and date-range values before any
row is written; hosts without a composer retain direct row creation.
+`onOpenRecord` takes over opening a record someone clicks (a row's open button,
+a board card, a timeline bar, a saved-record notice), in place of the record
+panel, and returns whether it opened it; when it could not, the panel opens. A
+document's database card opens the full database at that row, and keeps the panel
+where there are no splits (call chat). Records the view opens itself, such as one
+just created, keep the panel.
+
`editRows` and `editColumns` enable their respective controls. Optional record-view
props supply persisted board positions, conversion previews, relationships,
presence, and stored-view changes. Omit an unsupported action. A board can render
diff --git a/apps/web/src/features/database/views/database-records-view.test.tsx b/apps/web/src/features/database/views/database-records-view.test.tsx
index 752c54daca..cffccfac1d 100644
--- a/apps/web/src/features/database/views/database-records-view.test.tsx
+++ b/apps/web/src/features/database/views/database-records-view.test.tsx
@@ -830,6 +830,103 @@ describe('database table view', () => {
expect(await screen.findByRole('dialog')).toBeTruthy();
});
+ it.each([
+ ['a table row', allRecords],
+ ['a board card', statusBoard],
+ ])(
+ 'hands %s to the host that opens records elsewhere',
+ async (_layout, view) => {
+ const fixture = createFakeRowsSource({
+ columns,
+ table: {
+ version: 1,
+ rows: [
+ { rowId: 'row', cells: { title: 'Plan launch', status: 'To do' } },
+ ],
+ },
+ view: allRecords,
+ });
+ const onOpenRecord = vi.fn(() => true);
+ render(() => (
+ <DatabaseRecordsView
+ name="Projects"
+ source={fixture.source}
+ canEdit
+ view={view}
+ stored={false}
+ addColumn={() => null}
+ boardPositions={unplacedCards}
+ onOpenRecord={onOpenRecord}
+ />
+ ));
+ fireEvent.click(
+ await screen.findByRole('button', { name: 'Open Plan launch' })
+ );
+ expect(onOpenRecord).toHaveBeenCalledWith('row');
+ expect(screen.queryByRole('dialog')).toBeNull();
+ }
+ );
+
+ it('opens the record panel when the host cannot open the record elsewhere', async () => {
+ const fixture = createFakeRowsSource({
+ columns,
+ table: {
+ version: 1,
+ rows: [
+ { rowId: 'row', cells: { title: 'Plan launch', status: 'To do' } },
+ ],
+ },
+ view: allRecords,
+ });
+ const onOpenRecord = vi.fn(() => false);
+ render(() => (
+ <DatabaseRecordsView
+ name="Projects"
+ source={fixture.source}
+ canEdit
+ view={allRecords}
+ stored={false}
+ addColumn={() => null}
+ boardPositions={unplacedCards}
+ onOpenRecord={onOpenRecord}
+ />
+ ));
+ fireEvent.click(
+ await screen.findByRole('button', { name: 'Open Plan launch' })
+ );
+ expect(onOpenRecord).toHaveBeenCalledWith('row');
+ expect(await screen.findByRole('dialog')).toBeTruthy();
+ });
+
+ it('keeps a record created on a board in place when the host opens records elsewhere', async () => {
+ const fixture = createFakeRowsSource({
+ columns,
+ table: { version: 1, rows: [] },
+ view: allRecords,
+ });
+ fixture.persistWrites();
+ const onOpenRecord = vi.fn(() => true);
+ let actions!: DatabaseRecordsActions;
+ render(() => (
+ <DatabaseRecordsView
+ name="Projects"
+ source={fixture.source}
+ canEdit
+ view={statusBoard}
+ stored={false}
+ addColumn={() => null}
+ boardPositions={unplacedCards}
+ onOpenRecord={onOpenRecord}
+ actionsRef={(ready) => {
+ actions = ready;
+ }}
+ />
+ ));
+ await actions.createRow({ values: {}, open: true });
+ expect(await screen.findByRole('dialog')).toBeTruthy();
+ expect(onOpenRecord).not.toHaveBeenCalled();
+ });
+
it('cancels pending initial cell focus when the table is unmounted', async () => {
const fixture = createFakeRowsSource({
columns,
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 6dac641492..2dcf8c0557 100644
--- a/apps/web/src/features/database/views/database-records-view.tsx
+++ b/apps/web/src/features/database/views/database-records-view.tsx
@@ -129,6 +129,8 @@ export type DatabaseRecordsViewProps = {
renderTextValue?: GridCellProps['renderTextValue'];
renderMentionPicker?: GridCellProps['renderMentionPicker'];
renderMentionValue?: GridCellProps['renderMentionValue'];
+ /** Opens a record someone clicks somewhere else, in place of the record panel, as a view in a document opens its database; returns whether it did, else the panel opens. */
+ onOpenRecord?: (rowId: string) => boolean;
/** 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. */
@@ -225,6 +227,12 @@ export function DatabaseRecordsView(props: DatabaseRecordsViewProps) {
constrained: filtered,
editCell,
});
+ // Records the view itself opens, such as one just created, stay in its panel.
+ function openRecord(rowId: string) {
+ const savedId = draftRows.savedRowId(rowId);
+ if (savedId && props.onOpenRecord?.(savedId)) return;
+ records.open(rowId);
+ }
const gridRows = createHeldGridRows({
rows: () =>
props.canEdit && visibleColumns().some(canEditCell)
@@ -485,7 +493,7 @@ export function DatabaseRecordsView(props: DatabaseRecordsViewProps) {
? 'Open the record to view or edit it.'
: `“${rowTitle(row(), columns())}” doesn’t match your filters.`
}
- onOpen={() => records.open(row().rowId)}
+ onOpen={() => openRecord(row().rowId)}
onDismiss={records.dismissHiddenRecord}
/>
)}
@@ -550,7 +558,7 @@ export function DatabaseRecordsView(props: DatabaseRecordsViewProps) {
rowPending={controller.rowPending}
createPending={controller.createPending}
createComplete={controller.createComplete}
- onOpen={records.open}
+ onOpen={openRecord}
onCreate={records.createRow}
onCompose={props.onComposeRecord}
controlsRef={(controls) => {
@@ -570,7 +578,7 @@ export function DatabaseRecordsView(props: DatabaseRecordsViewProps) {
!props.stored || props.canEdit ? props.onViewChange : undefined
}
rowPending={controller.rowPending}
- onOpen={records.open}
+ onOpen={openRecord}
onCreate={records.createRow}
onWrite={writeRowCell}
onCompose={props.onComposeRecord}
@@ -656,7 +664,7 @@ export function DatabaseRecordsView(props: DatabaseRecordsViewProps) {
controlsRef={tableReady}
titleColumnId={titleColumn(columns())?.id}
getRowTitle={(row) => rowTitle(row, columns())}
- onOpen={records.open}
+ onOpen={openRecord}
onDuplicate={records.duplicateRow}
onRequestDelete={records.requestDelete}
relationTables={props.relationTables}
diff --git a/docs/agent-guide/databases.md b/docs/agent-guide/databases.md
index eee7c5c524..53af1430fd 100644
--- a/docs/agent-guide/databases.md
+++ b/docs/agent-guide/databases.md
@@ -864,6 +864,11 @@ opens the editor. **Collapse** returns it to a small mention. Cell and schema
edits use the same database grid and authorization as the standalone app. The
document stores only the database reference and selected table/view, never a
copy of its rows. See [Databases in documents](documents.md#databases-in-documents).
+Opening a row there (its row-number button, **Open record**, a board card, or a
+timeline bar) opens the database in its own split at that table and view, with
+the row highlighted or its record panel open; the card shows no record panel of
+its own. A record just created in the card still opens in place, and so does
+every record where the card has no splits to open into (call chat).
The shared editor also runs under a host's `DatabaseProvider`, using schema reads,
row queries and operation batches from that host's API. Verify cell edits and
diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.md
index 63e21833c3..a75c6188a2 100644
--- a/docs/agent-guide/documents.md
+++ b/docs/agent-guide/documents.md
@@ -334,7 +334,9 @@ The **Filter** and **Sort** icons open their panels. The pickers support keyboar
navigation and mark the selected table. Rows added or edited elsewhere, including
by AI, appear through the database's gateway subscription. The editor catches up after
reconnecting or returning to the tab after a long absence.
-Edits write to the original database. **Open** opens the full database.
+Edits write to the original database. **Open** opens the full database; opening
+a row (its row-number button, a board card or a timeline bar) opens the full
+database at that row.
**Collapse** converts the editor to a small mention; **Expand** brings it back.
Removing either reference leaves the database and its rows intact.