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(md): track mentions on /task create (#4291)

Seamusfbf6970dd419
diff --git a/js/app/packages/block-md/component/MarkdownEditor.tsx b/js/app/packages/block-md/component/MarkdownEditor.tsx
index 702d1811e0..a3fffdc92c 100644
--- a/js/app/packages/block-md/component/MarkdownEditor.tsx
+++ b/js/app/packages/block-md/component/MarkdownEditor.tsx
@@ -1054,7 +1054,14 @@ export function MarkdownEditor(props: {
sourceDocumentId={blockId}
/>
- <ActionMenu editor={editor} menu={actionsMenuOperations} />
+ <ActionMenu
+ editor={editor}
+ menu={actionsMenuOperations}
+ actionContext={{
+ sourceDocumentId: blockId,
+ sourceBlockName: blockName,
+ }}
+ />
<FloatingMenuGroup>
<FloatingLinkMenu autoLinkMatchMode="common-tlds" />
diff --git a/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx b/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
index ac10bb404a..cf166f3929 100644
--- a/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
+++ b/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
@@ -29,6 +29,7 @@ import {
getDefaultPinnedProperties,
SYSTEM_PROPERTY_IDS,
} from '@property/constants';
+import { useAttachmentReferencesQuery } from '@queries/storage/attachment-references';
import { useDocumentMetadataQuery } from '@queries/storage/document-metadata';
import { useDocumentGithubPullRequestsQuery } from '@queries/storage/github-pull-requests';
import {
@@ -36,17 +37,13 @@ import {
useSetDocumentTeamShareMutation,
} from '@queries/storage/team-share';
import type { EntityType as PropertiesEntityType } from '@service-properties/generated/schemas/entityType';
-import {
- blockNameToItemType,
- storageServiceClient,
-} from '@service-storage/client';
+import { blockNameToItemType } from '@service-storage/client';
import type { GithubPullRequest } from '@service-storage/generated/schemas';
import { createCallback } from '@solid-primitives/rootless';
import { cn, InlineCheckbox } from '@ui';
import {
createEffect,
createMemo,
- createResource,
createSignal,
For,
onCleanup,
@@ -439,24 +436,12 @@ function NotificationsSectionConditional(props: { entity: Entity }) {
// ─────────────────────────────────────────────────────────────────────────────
function ReferencesSectionConditional(props: { documentId: string }) {
- const [references] = createResource(
+ const references = useAttachmentReferencesQuery(
() => props.documentId,
- async (id) => {
- const response = await storageServiceClient.attachmentReferences({
- entity_type: 'document',
- entity_id: id,
- });
-
- if (response.isErr()) {
- console.error(response);
- return [];
- }
-
- return response.value.references;
- }
+ () => 'document'
);
- const count = createMemo(() => references()?.length ?? 0);
+ const count = createMemo(() => references.data?.length ?? 0);
return (
<Show when={count() > 0}>
diff --git a/js/app/packages/core/comments/discussion/configured-discussion-markdown-editor.ts b/js/app/packages/core/comments/discussion/configured-discussion-markdown-editor.ts
index df4b946d77..996553dd1d 100644
--- a/js/app/packages/core/comments/discussion/configured-discussion-markdown-editor.ts
+++ b/js/app/packages/core/comments/discussion/configured-discussion-markdown-editor.ts
@@ -38,6 +38,7 @@ export function createConfiguredDiscussionMarkdownEditor(
onCreate: options.onMentionCreate,
onRemove: options.onMentionRemove,
users: options.users,
+ disableMentionTracking: true,
});
}
diff --git a/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx b/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx
index 125a9322e1..0cfa23ad14 100644
--- a/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx
@@ -279,6 +279,12 @@ export const MarkdownShell: Component<
builderConfig.actions.ignoreActionIds) ||
undefined
}
+ actionContext={{
+ sourceDocumentId: builderConfig.mentions?.sourceDocumentId,
+ sourceBlockName: builderConfig.mentions?.block,
+ disableMentionTracking:
+ builderConfig.mentions?.disableMentionTracking,
+ }}
portalScope={props.portalScope}
/>
)}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx b/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
index c25ef165b3..48d451b7a0 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
@@ -24,7 +24,7 @@ import {
REMOVE_ACTION_SEARCH_COMMAND,
} from '../../plugins';
import { ACTIONS } from '../../plugins/actions/actions';
-import type { Action } from '../../plugins/actions/types';
+import type { Action, ActionContext } from '../../plugins/actions/types';
import type { MenuOperations } from '../../shared/inlineMenu';
import { useMenuKeyboardNavigation } from './useMenuKeyboardNavigation';
@@ -40,6 +40,7 @@ function ActionsMenuItem(props: {
index: number;
selected: boolean;
editor: LexicalEditor;
+ actionContext?: ActionContext;
setIndex: (index: number) => void;
setOpen: (open: boolean) => void;
}) {
@@ -70,7 +71,7 @@ function ActionsMenuItem(props: {
if (action) {
if (dependencies !== undefined) {
if (props.editor.hasNodes(dependencies)) {
- action(props.editor);
+ action(props.editor, props.actionContext);
} else {
console.error(
'Dispatched Action with missing dependencies:',
@@ -78,7 +79,7 @@ function ActionsMenuItem(props: {
);
}
} else {
- action(props.editor);
+ action(props.editor, props.actionContext);
}
}
props.setOpen(false);
@@ -114,6 +115,7 @@ export function ActionMenu(props: {
additionalActions?: Action[];
/** IDs of default actions to exclude from the menu. */
ignoreActionIds?: string[];
+ actionContext?: ActionContext;
}) {
const { isOpen, setIsOpen } = props.menu;
@@ -209,7 +211,7 @@ export function ActionMenu(props: {
const selectedItem = items[selectedIndex()];
props.editor.dispatchCommand(REMOVE_ACTION_SEARCH_COMMAND, undefined);
if (selectedItem) {
- selectedItem.action(props.editor);
+ selectedItem.action(props.editor, props.actionContext);
}
setIsOpen(false);
};
@@ -277,6 +279,7 @@ export function ActionMenu(props: {
index={index()}
selected={index() === selectedIndex()}
editor={props.editor}
+ actionContext={props.actionContext}
setIndex={setSelectedIndexFromMouse}
setOpen={setIsOpen}
/>
diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/actions/actions.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/actions/actions.ts
index 5200f84380..9deb8ade42 100644
--- a/js/app/packages/core/component/LexicalMarkdown/plugins/actions/actions.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/actions/actions.ts
@@ -1,5 +1,6 @@
import { globalSplitManager } from '@app/signal/splitLayout';
import type { ComposeTaskSuccess } from '@block-md/component/ComposeTask';
+import { trackMention } from '@core/signal/mention';
import { LinkNode } from '@lexical/link';
import { ListNode } from '@lexical/list';
import { HeadingNode, QuoteNode } from '@lexical/rich-text';
@@ -42,7 +43,23 @@ import { TRY_INSERT_LINK_COMMAND } from '../links';
import { TRY_INSERT_MEDIA_UPLOAD_COMMAND } from '../media';
import { INSERT_DOCUMENT_MENTION_COMMAND } from '../mentions/mentionsPlugin';
import { NODE_TRANSFORM } from '../node-transform';
-import { type Action, ActionCategory } from './types';
+import { type Action, ActionCategory, type ActionContext } from './types';
+
+async function trackSlashTaskMention(
+ context: ActionContext | undefined,
+ documentId: string
+) {
+ if (
+ !context?.sourceDocumentId ||
+ context.disableMentionTracking ||
+ context.sourceBlockName === 'channel' ||
+ context.sourceBlockName === 'chat'
+ ) {
+ return undefined;
+ }
+
+ return await trackMention(context.sourceDocumentId, 'document', documentId);
+}
export const ACTIONS: Action[] = [
{
@@ -157,19 +174,17 @@ export const ACTIONS: Action[] = [
keywords: ['task', 'todo', 'create'],
category: ActionCategory.ELEMENT,
icon: CheckSquare,
- action: (editor: LexicalEditor) => {
+ action: (editor: LexicalEditor, context?: ActionContext) => {
const splitManager = globalSplitManager();
if (!splitManager) return;
const awaitId = nanoid(21);
let placeholderInserted = false;
- console.log('[task-action] opening compose, awaitId=', awaitId);
splitManager.createPopoverSplit({
content: {
type: 'component',
id: 'task-compose',
params: {
onCreateStart: ({ title }: { title: string }) => {
- console.log('[task-action] onCreateStart fired, title=', title);
const handled = editor.dispatchCommand(
INSERT_AWAIT_NODE_COMMAND,
{
@@ -177,26 +192,16 @@ export const ACTIONS: Action[] = [
text: `Creating ${title}`,
}
);
- console.log(
- '[task-action] INSERT_AWAIT_NODE_COMMAND handled=',
- handled
- );
- placeholderInserted = true;
+ placeholderInserted = handled;
},
onCreateFailure: () => {
- console.log(
- '[task-action] onCreateFailure, placeholderInserted=',
- placeholderInserted
- );
if (!placeholderInserted) return;
editor.dispatchCommand(REPLACE_AWAIT_NODE_COMMAND, { awaitId });
placeholderInserted = false;
},
- onSuccess: (result: ComposeTaskSuccess) => {
- console.log(
- '[task-action] onSuccess, placeholderInserted=',
- placeholderInserted,
- 'documentId=',
+ onSuccess: async (result: ComposeTaskSuccess) => {
+ const mentionUuid = await trackSlashTaskMention(
+ context,
result.documentId
);
if (placeholderInserted) {
@@ -208,6 +213,7 @@ export const ACTIONS: Action[] = [
documentName: result.title,
blockName: 'task',
createdAt: Date.now(),
+ mentionUuid,
}),
});
placeholderInserted = false;
@@ -217,6 +223,7 @@ export const ACTIONS: Action[] = [
documentId: result.documentId,
documentName: result.title,
blockName: 'task',
+ mentionUuid,
});
},
},
diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/actions/types.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/actions/types.ts
index b43209745e..e5ca8809dc 100644
--- a/js/app/packages/core/component/LexicalMarkdown/plugins/actions/types.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/actions/types.ts
@@ -1,13 +1,19 @@
import type { KlassConstructor, LexicalEditor, LexicalNode } from 'lexical';
import type { Component } from 'solid-js';
+export type ActionContext = {
+ sourceDocumentId?: string;
+ sourceBlockName?: string;
+ disableMentionTracking?: boolean;
+};
+
export type Action = {
id: string;
name: string;
keywords: string[];
icon: Component<{ class: string }>;
category: string;
- action: (editor: LexicalEditor) => void;
+ action: (editor: LexicalEditor, context?: ActionContext) => void;
shortcut?: string;
dependencies?: Array<KlassConstructor<typeof LexicalNode>>;
};
diff --git a/js/app/packages/core/signal/mention.ts b/js/app/packages/core/signal/mention.ts
index 7bdbd0b79f..9672aa4030 100644
--- a/js/app/packages/core/signal/mention.ts
+++ b/js/app/packages/core/signal/mention.ts
@@ -1,4 +1,6 @@
import { ENABLE_MENTION_TRACKING } from '@core/constant/featureFlags';
+import { queryClient } from '@queries/client';
+import { attachmentReferencesKeys } from '@queries/storage/keys';
import { type ItemType, storageServiceClient } from '@service-storage/client';
import { getPermissionToken } from './token';
@@ -29,6 +31,9 @@ export async function trackMention(
return;
}
+ queryClient.invalidateQueries({
+ queryKey: attachmentReferencesKeys.list(targetType, targetId).queryKey,
+ });
return response.value?.id;
}
@@ -50,4 +55,8 @@ export async function untrackMention(
if (response.isErr()) {
console.error('Failed to untrack document mention', response);
}
+
+ queryClient.invalidateQueries({
+ queryKey: attachmentReferencesKeys.list._def,
+ });
}