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): let channel query controls handle clicks and Enter (#7413)

Wolf Mermelstein3d07be3808b0
diff --git a/apps/web/src/features/database-query/views/query-editor.test.tsx b/apps/web/src/features/database-query/views/query-editor.test.tsx
index b6c504e5af..9c56d7167b 100644
--- a/apps/web/src/features/database-query/views/query-editor.test.tsx
+++ b/apps/web/src/features/database-query/views/query-editor.test.tsx
@@ -29,6 +29,47 @@ describe('question editor', () => {
showDatabaseSql.enabled = false;
});
+ it('handles prompt Enter before a composer shell can send the message', async () => {
+ const send = vi.fn();
+ const generate = vi.fn(() =>
+ okAsync({
+ sql: 'SELECT COUNT(*) FROM projects',
+ explanation: '',
+ displayMode: 'scalar' as const,
+ })
+ );
+ const save = vi.fn();
+ const result = render(() => (
+ <div
+ on:keydown={(event) => {
+ send();
+ event.stopPropagation();
+ }}
+ >
+ <PlainAnswerDisplay>
+ <QueryEditor
+ initial={{
+ sql: '',
+ prompt: 'Count projects',
+ displayMode: 'scalar',
+ }}
+ schema={{ name: 'Projects', databaseId: 'db', tables: [] }}
+ capabilities={{ generate, read: () => okAsync(answer) }}
+ onSave={save}
+ />
+ </PlainAnswerDisplay>
+ </div>
+ ));
+ const input = result.getByRole('textbox', { name: 'Ask your database' });
+ fireEvent.keyDown(input, { key: 'Enter' });
+ await waitFor(() => expect(generate).toHaveBeenCalledTimes(1));
+ await result.findByRole('button', { name: 'Insert' });
+ fireEvent.keyDown(input, { key: 'Enter' });
+ await waitFor(() => expect(save).toHaveBeenCalledTimes(1));
+ expect(send).not.toHaveBeenCalled();
+ result.unmount();
+ });
+
it('regenerates a saved question and saves only its successful current answer', async () => {
const save = vi.fn();
const read = vi.fn(() => okAsync(answer));
diff --git a/apps/web/src/features/database-query/views/query-editor.tsx b/apps/web/src/features/database-query/views/query-editor.tsx
index 7d2160b47f..fc83c9bb5a 100644
--- a/apps/web/src/features/database-query/views/query-editor.tsx
+++ b/apps/web/src/features/database-query/views/query-editor.tsx
@@ -191,10 +191,11 @@ export function QueryEditor(props: {
<div
class="flex min-h-0 flex-col gap-3 p-4"
data-database-query-editor
- onKeyDown={(event) => {
+ on:keydown={(event) => {
if (!isPlainEnter(event) || !canAccept() || ownsEnter(event.target))
return;
event.preventDefault();
+ event.stopPropagation();
accept();
}}
>
@@ -217,7 +218,7 @@ export function QueryEditor(props: {
placeholder="Ask anything about your data…"
value={composer.prompt()}
onInput={(event) => composer.setPrompt(event.currentTarget.value)}
- onKeyDown={(event) => {
+ on:keydown={(event) => {
if (event.isComposing || event.keyCode === 229) return;
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DatabaseQuery.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DatabaseQuery.test.tsx
index 2429a14cd3..0788d2a8c7 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DatabaseQuery.test.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DatabaseQuery.test.tsx
@@ -34,6 +34,7 @@ const control = vi.hoisted(() => ({
enabled: (): boolean => false,
mounts: 0,
cleanups: 0,
+ clicks: 0,
}));
vi.mock('@core/constant/featureFlags', () => ({
enableDatabases: { key: 'enable-databases' },
@@ -57,7 +58,9 @@ vi.mock('@app/features/database-query/database-query', () => ({
<div contentEditable={false}>
<div data-testid="header">
<span>RSVP Counts</span>
- <button type="button">Details</button>
+ <button type="button" onClick={() => control.clicks++}>
+ Details
+ </button>
</div>
<details>
<summary>View data</summary>
@@ -222,6 +225,46 @@ describe('database answer while databases are off', () => {
});
});
+describe('database controls in a composer shell', () => {
+ it('lets delegated clicks reach embedded controls without stealing focus', async () => {
+ const test = createTestEditor();
+ control.enabled = () => true;
+ control.clicks = 0;
+ const focus = vi.fn();
+ const rendered = render(() => (
+ <div
+ on:click={(event) => {
+ if (
+ event.target instanceof Element &&
+ event.target.closest('[data-lexical-interactive]')
+ )
+ return;
+ event.stopPropagation();
+ focus();
+ }}
+ >
+ <LexicalWrapperContext.Provider value={test.wrapper}>
+ <DatabaseQuery
+ key={test.blockKey}
+ theme={{}}
+ queryId="query"
+ prompt="Count"
+ displayMode="table"
+ />
+ </LexicalWrapperContext.Provider>
+ </div>
+ ));
+ const details = await rendered.findByRole('button', { name: 'Details' });
+ details.focus();
+ fireEvent.click(details);
+ expect(control.clicks).toBe(1);
+ expect(focus).not.toHaveBeenCalled();
+ expect(document.activeElement).toBe(details);
+ rendered.unmount();
+ test.root.remove();
+ });
+});
+
describe('pressing a database answer block', () => {
it('selects the block on the press itself, without placing a caret first', async () => {
const test = createTestEditor();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DatabaseQuery.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DatabaseQuery.tsx
index ef71cd26df..5c6b9607dd 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DatabaseQuery.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DatabaseQuery.tsx
@@ -169,6 +169,7 @@ export function DatabaseQuery(props: DatabaseQueryDecoratorProps) {
when={props.displayMode !== 'scalar'}
fallback={
<span
+ data-lexical-interactive
data-database-query-selected={isSelectedAsNode() || undefined}
class={cn(
'rounded-lg',
@@ -182,7 +183,12 @@ export function DatabaseQuery(props: DatabaseQueryDecoratorProps) {
{/* The block's spacing is padding, not the card's margin, so a press
beside the card still lands on the block instead of the text
around it. */}
- <div class="py-1" onMouseDown={selectOnPress} onClick={selectOnClick}>
+ <div
+ data-lexical-interactive
+ class="py-1"
+ onMouseDown={selectOnPress}
+ onClick={selectOnClick}
+ >
<div
data-database-query-selected={isSelectedAsNode() || undefined}
class={cn(
diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.md
index e21e1705dd..0570725e3d 100644
--- a/docs/AGENT_GUIDE/channels.md
+++ b/docs/AGENT_GUIDE/channels.md
@@ -962,3 +962,5 @@ Picture changes refresh other participants' open sessions, including after
reconnecting.
Members see the picture without editing controls. One-to-one direct messages
continue to show the other person's user picture.
+
+When Databases is enabled, type `/database` in a channel message or thread reply and choose **Database** to insert a live question. Ask with Enter or the Ask button, then accept the answer before sending the message. Enter in the question box belongs to the question and must not send the channel draft. Recipients can read the live answer subject to their database access.
diff --git a/docs/AGENT_GUIDE/databases.md b/docs/AGENT_GUIDE/databases.md
index af96039431..d669dc11e4 100644
--- a/docs/AGENT_GUIDE/databases.md
+++ b/docs/AGENT_GUIDE/databases.md
@@ -370,7 +370,7 @@ a scalar answer, or compatible bar, line, area, scatter, and pie charts. A saved
offers **Open view**, which opens that database/table and selects the created view.
The same tools are exposed to agent sessions through the Macro MCP server.
-In a document, `/database` → **Database** opens the question box with the AI prompt focused
+In a document or channel composer, `/database` → **Database** opens the question box with the AI prompt focused
immediately. The empty input rotates through example questions; a selected database
uses its actual table and column names. Typing hides these hints, and reduced-motion
preferences keep them static. Use the searchable source picker below the question to