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(mentions): convert a mention to plain text from its menu (#9100)
gbirmane6683947c6d9
diff --git a/apps/web/src/features/calendar-view/copy-event-mention.ts b/apps/web/src/features/calendar-view/copy-event-mention.tsindex 2073d204d8..5c1019d82f 100644--- a/apps/web/src/features/calendar-view/copy-event-mention.ts+++ b/apps/web/src/features/calendar-view/copy-event-mention.ts@@ -6,6 +6,7 @@ import {} from '@app/features/calendar-view/calendar-url';import { toast } from '@core/component/Toast/Toast';import { writeClipboardData } from '@core/util/dataTransfer';+import { getWebOrigin } from '@core/util/webOrigin';/** What a copied event needs to come back as a mention or a deep link. */export type CalendarMentionTarget = {@@ -41,23 +42,16 @@ function mentionHtml(target: CalendarMentionTarget): string {return span.outerHTML;}-/**- * Deep link to one event on the singleton Calendar view, using the same- * host convention as the copy-link actions elsewhere in the app.- */+/** Deep link to one event on the singleton Calendar view. */export function calendarEventDeepLink(target: {eventId: string;occurrenceKey?: string;}): string {- let hostname = window.location.hostname.replace('www.', '').toLowerCase();- if (hostname === 'localhost') {- hostname = 'dev.macro.com';- }const params = new URLSearchParams({[calendarFocusedEventSearchKey()]: target.eventId,});const path = calendarPath(getPreferredCalendarPeriodView());- return `https://${hostname}/app${path}?${params.toString()}`;+ return `${getWebOrigin()}/app${path}?${params.toString()}`;}/**diff --git a/apps/web/src/lib/core/component/DocumentPreview.tsx b/apps/web/src/lib/core/component/DocumentPreview.tsxindex 2268e1b0b8..a5d40739f8 100644--- a/apps/web/src/lib/core/component/DocumentPreview.tsx+++ b/apps/web/src/lib/core/component/DocumentPreview.tsx@@ -5,6 +5,7 @@ import {import { SharedEventActions } from '@app/features/calendar-view/components/SharedEventActions';import {type CalendarMentionTarget,+ calendarEventDeepLink,copyCalendarEventMentionTarget,} from '@app/features/calendar-view/copy-event-mention';import { calendarMentionOpen } from '@app/features/calendar-view/mention-open-target';@@ -40,7 +41,7 @@ import { copyBranchNameToClipboard } from '@core/util/branchName';import { fireAndForget } from '@core/util/fireAndForget';import { parseLocalDate } from '@core/util/local-date';import { matches } from '@core/util/match';-import { openExternalUrl } from '@core/util/url';+import { buildSimpleEntityUrl, openExternalUrl } from '@core/util/url';import MacroEmbed from '@icon/macro-embed.svg';import CollapseInlinePreview from '@icon/system/regular/arrows-in-line-horizontal.svg';import ExpandInlinePreview from '@icon/system/regular/arrows-out-line-horizontal.svg';@@ -58,6 +59,7 @@ import MapPinIcon from '@icon/system/regular/map-pin-simple.svg';import SparkleIcon from '@icon/system/regular/sparkle.svg';import LoadingSpinner from '@icon/system/regular/spinner.svg';import TextAlignLeftIcon from '@icon/system/regular/text-align-left.svg';+import TextTIcon from '@icon/system/regular/text-t.svg';import TrashSimple from '@icon/system/regular/trash-simple.svg';import UsersIcon from '@icon/system/regular/users.svg';import {@@ -493,6 +495,7 @@ export function CalendarEventPreviewDetails(props: {*/export type DocumentPreviewContentProps = {delete?: () => void;+ convertToText?: (link: string) => void;collapseInfo?: {isCollapsable: boolean;isCollapsed: boolean;@@ -721,31 +724,24 @@ export function DocumentPreviewContent(props: DocumentPreviewContentProps) {};};+ const documentLink = () => {+ const mentionTarget = calendarMentionTarget();+ if (mentionTarget) return calendarEventDeepLink(mentionTarget);+ return buildSimpleEntityUrl(+ { type: targetBlockType(), id: props.documentInfo.id },+ props.documentInfo.params+ );+ };+const handleCopy = async () => {try {- let hostname = window.location.hostname.replace('www.', '').toLowerCase();- if (hostname === 'localhost') {- hostname = 'dev.macro.com';- }-const mentionTarget = calendarMentionTarget();if (mentionTarget) {await copyCalendarEventMentionTarget(mentionTarget);return;}- let link = `https://${hostname}/app/${targetBlockType()}/${props.documentInfo.id}`;-- if (- props.documentInfo.params &&- Object.keys(props.documentInfo.params).length > 0- ) {- const queryParams = new URLSearchParams(- props.documentInfo.params- ).toString();- link += `?${queryParams}`;- }- await navigator.clipboard.writeText(link);+ await navigator.clipboard.writeText(documentLink());toast.success('Copied document link to clipboard');} catch (e) {console.error(e);@@ -865,6 +861,14 @@ export function DocumentPreviewContent(props: DocumentPreviewContentProps) {: 'Convert to Card View'}</Dropdown.Item></Show>+ <Show when={props.convertToText}>+ <Dropdown.Item+ onSelect={() => props.convertToText?.(documentLink())}+ >+ <TextTIcon class="size-4" />+ Convert to Plain Text+ </Dropdown.Item>+ </Show><Show when={props.collapseInfo?.isCollapsable}><Dropdown.Item onSelect={handleToggleCollapse}><Show@@ -1129,7 +1133,14 @@ export function DocumentPreviewContent(props: DocumentPreviewContentProps) {props.documentInfo.name}fallback={- <div class="text-sm p-4">+ <div class="relative text-sm p-4">+ {/* An editor can still turn a reference the viewer can't+ open back into its link. */}+ <Show when={props.convertToText}>+ <div class="absolute top-3 right-3">+ {renderActionButtons()}+ </div>+ </Show>{noAccessItem().access === 'no_access' ? (<Unauthorized noun={itemNoun()} />) : (@@ -1185,6 +1196,7 @@ export function PopupPreview(<Suspense fallback={<DocumentPreviewSkeleton />}><DocumentPreviewContentdelete={props.delete}+ convertToText={props.convertToText}collapseInfo={props.collapseInfo}documentInfo={props.documentInfo}previewInfo={props.previewInfo}diff --git a/apps/web/src/lib/core/component/DocumentPreviewSheet.tsx b/apps/web/src/lib/core/component/DocumentPreviewSheet.tsxindex 08f0b26f06..a99066c115 100644--- a/apps/web/src/lib/core/component/DocumentPreviewSheet.tsx+++ b/apps/web/src/lib/core/component/DocumentPreviewSheet.tsx@@ -36,6 +36,7 @@ export function DocumentPreviewSheet(<Suspense fallback={<DocumentPreviewSkeleton />}><DocumentPreviewContentdelete={props.delete}+ convertToText={props.convertToText}collapseInfo={props.collapseInfo}documentInfo={props.documentInfo}previewInfo={props.previewInfo}diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsxindex ecb246df75..8520685702 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx@@ -67,6 +67,7 @@ import { blockNameToItemType } from '@service-storage/client';import { createCallback } from '@solid-primitives/rootless';import { Button, Tooltip } from '@ui';import {+ $createTextNode,$getNodeByKey,COMMAND_PRIORITY_NORMAL,type EditorThemeClasses,@@ -1115,6 +1116,14 @@ function DocumentMentionInner(props: DocumentMentionDecoratorProps) {});};+ const convertToText = (link: string) => {+ editor?.update(() => {+ const node = $getNodeByKey(props.key);+ if (!$isDocumentMentionNode(node)) return;+ node.replace($createTextNode(link));+ });+ };+const convertToCard = () => {if (!editor) return;editor.update(() => {@@ -1146,6 +1155,9 @@ function DocumentMentionInner(props: DocumentMentionDecoratorProps) {get delete() {return editor?.isEditable() ? deleteMention : undefined;},+ get convertToText() {+ return editor?.isEditable() ? convertToText : undefined;+ },get collapseInfo() {return {isCollapsed: isCollapsed(),diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/unavailable-mention.browser.e2e.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/unavailable-mention.browser.e2e.tsindex 2824e10897..091cb78644 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/unavailable-mention.browser.e2e.ts+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/unavailable-mention.browser.e2e.ts@@ -23,6 +23,7 @@ const cases = [['Deleted skill', 'Deleted', "This skill was deleted or doesn't exist."],['Deleted routine', 'Deleted', "This routine was deleted or doesn't exist."],['Hidden routine', 'No Access', "You don't have access to this routine"],+ ['Hidden channel', 'No Access', "You don't have access to this channel"],['Deleted agent session','Deleted agent session',@@ -89,6 +90,26 @@ test('Enter on a deleted chip selected in a composer keeps its card open', asyncawait expect(composer.locator('p')).toHaveCount(1);});+test('a hidden channel chip in a composer converts to its link as plain text', async ({+ page,+}) => {+ await page.goto(fixture);+ const composer = page.getByRole('textbox', { name: 'Composer' });+ await composer.getByText('No Access', { exact: true }).click();+ await expect(+ page.getByText("You don't have access to this channel", { exact: true })+ ).toBeVisible();++ await page.getByRole('button', { name: 'Reference actions' }).click();+ await page.getByRole('menuitem', { name: 'Convert to Plain Text' }).click();++ const origin = new URL(page.url()).origin;+ await expect(composer).toContainText(+ `after ${origin}/app/channel/01a16d55-0000-7000-8000-00000000000f end`+ );+ await expect(composer.getByText('No Access', { exact: true })).toBeHidden();+});+test.describe('on a phone', () => {test.use({viewport: { width: 390, height: 844 },diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/unavailable-mention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/unavailable-mention.tsxindex c327b99e55..efe630f7ed 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/unavailable-mention.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/unavailable-mention.tsx@@ -108,6 +108,12 @@ const mentions = [blockName: 'routine',preview: { type: 'routine', access: 'no_access' },},+ {+ label: 'Hidden channel',+ id: '01a16d55-0000-7000-8000-00000000000f',+ blockName: 'channel',+ preview: { type: 'channel', access: 'no_access' },+ },] as const satisfies ReadonlyArray<{label: string;id: string;@@ -214,7 +220,7 @@ declare global {}}-/** An editable editor holding the deleted document's chip. */+/** An editable editor holding the deleted document's and hidden channel's chips. */function Composer() {const wrapper = createLexicalWrapper({type: 'chat',@@ -228,7 +234,11 @@ function Composer() {documentId: mentions[1].id,blockName: mentions[1].blockName,documentName: 'Planning',- })}</m-document-mention> after`+ })}</m-document-mention> after <m-document-mention>${JSON.stringify({+ documentId: mentions[11].id,+ blockName: mentions[11].blockName,+ documentName: 'Planning',+ })}</m-document-mention> end`);// Selects the chip as a node, as arrowing onto it in a composer does.window.selectComposerMention = () =>diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.mdindex 713feeed69..f79ceaf497 100644--- a/docs/agent-guide/documents.md+++ b/docs/agent-guide/documents.md@@ -2605,7 +2605,10 @@ after an expanded reference remains in separate paragraphs.Hover a document reference chip to open its preview without navigating. Withthe preview open, the compact header shows a tinted icon, title, and author/timebyline. Click the title to open the document; the Reference actions ellipsis menu contains copy-link, split, embed/collapse, AI, and delete actions when applicable. The preview+link, split, embed/collapse, AI, and delete actions when applicable. In an editable+editor it also offers **Convert to Plain Text**, which replaces the chip with the+item's link as ordinary text, so sending it shares nothing; the `No Access` and+`Deleted` cards show the menu there too. The previewstays open while this menu is active, and moving over other reference chips mustnot open their previews. Click outside or press Escape to dismiss the menu;other references can then be hovered again. Images use an inset frame and task chips