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(mentions): calls in mentions, mention loading improvements, optimisitic preview on create (#2867)

Seamus3912be0884ec
diff --git a/js/app/packages/app/component/Launcher.tsx b/js/app/packages/app/component/Launcher.tsx
index 1b5de80537..6aff2b94ee 100644
--- a/js/app/packages/app/component/Launcher.tsx
+++ b/js/app/packages/app/component/Launcher.tsx
@@ -137,7 +137,7 @@ const createComponent = async (spec: {
};
export function runCreateAction(
- blockName: BlockName,
+ blockName: BlockName | BlockAlias,
options: { shouldInsert?: boolean } = {}
) {
const shouldInsert = options.shouldInsert ?? false;
@@ -236,7 +236,7 @@ export function runCreateAction(
export type CreatableBlock = Omit<HotkeyRegistrationOptions, 'scopeId'> & {
label: string;
- blockName: BlockName;
+ blockName: BlockName | BlockAlias;
altHotkeyToken?: HotkeyToken;
animatedIcon?: Component<{ triggerAnimation?: boolean }>;
};
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx
index caff83cb58..a444720d9c 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx
@@ -9,7 +9,7 @@ import {
openFolderPicker,
} from '@core/util/upload';
import { useHandleFileUpload } from '@app/util/handleFileUpload';
-import type { BlockName } from '@core/block';
+import type { BlockAlias, BlockName } from '@core/block';
import ChevronDownIcon from '@icon/regular/caret-down.svg';
import UploadIcon from '@icon/regular/upload-simple.svg';
import { DropdownMenu } from '@kobalte/core/dropdown-menu';
@@ -18,7 +18,9 @@ import { Button } from '@ui/components/Button';
import { NewCallButton } from './NewCallButton';
// Which blocks to show as create options per view, in order
-const VIEW_CREATE_BLOCKNAMES: Partial<Record<ListView, BlockName[]>> = {
+const VIEW_CREATE_BLOCKNAMES: Partial<
+ Record<ListView, (BlockName | BlockAlias)[]>
+> = {
documents: ['md', 'canvas', 'code'],
tasks: ['task'],
agents: ['chat', 'automation'],
@@ -28,7 +30,7 @@ const VIEW_CREATE_BLOCKNAMES: Partial<Record<ListView, BlockName[]>> = {
};
type CreateOption = {
- id: BlockName | 'import-file' | 'import-folder';
+ id: BlockName | BlockAlias | 'import-file' | 'import-folder';
label: string;
};
@@ -46,9 +48,10 @@ const IMPORT_FOLDER_OPTION: CreateOption = {
* (and thus aren't in CREATABLE_BLOCKS) but still need a create entry in
* specific list views.
*/
-const VIEW_ONLY_BLOCK_LABELS: Partial<Record<BlockName, string>> = {
- automation: 'Automation',
-};
+const VIEW_ONLY_BLOCK_LABELS: Partial<Record<BlockName | BlockAlias, string>> =
+ {
+ automation: 'Automation',
+ };
function getViewCreateOptions(view: ListView): CreateOption[] {
const createNames = VIEW_CREATE_BLOCKNAMES[view] ?? [];
@@ -70,7 +73,7 @@ function getViewCreateOptions(view: ListView): CreateOption[] {
}
function CreateOptionIcon(props: {
- id: BlockName | 'import-file' | 'import-folder';
+ id: BlockName | BlockAlias | 'import-file' | 'import-folder';
}) {
return (
<Show
diff --git a/js/app/packages/block-canvas/component/CanvasController.tsx b/js/app/packages/block-canvas/component/CanvasController.tsx
index a2d97b780b..3fbf5577ca 100644
--- a/js/app/packages/block-canvas/component/CanvasController.tsx
+++ b/js/app/packages/block-canvas/component/CanvasController.tsx
@@ -864,7 +864,6 @@ export function CanvasController(props: ParentProps) {
const entityType = event.draggable.data.type;
// TODO: add channel message support
if (entityType === 'channel_message') return;
- if (entityType === 'call') return;
// Automation entities aren't yet renderable as canvas mentions.
if (entityType === 'automation') return;
diff --git a/js/app/packages/block-canvas/model/CanvasModel.ts b/js/app/packages/block-canvas/model/CanvasModel.ts
index 495efe9dfc..90a48c303f 100644
--- a/js/app/packages/block-canvas/model/CanvasModel.ts
+++ b/js/app/packages/block-canvas/model/CanvasModel.ts
@@ -167,7 +167,14 @@ export const EntityMentionSchema = z.preprocess(
},
BaseNodeSchema.extend({
type: z.literal('entitymention'),
- entityType: z.enum(['document', 'chat', 'project', 'channel', 'email']),
+ entityType: z.enum([
+ 'document',
+ 'chat',
+ 'project',
+ 'channel',
+ 'email',
+ 'call',
+ ]),
file: z.string(),
subpath: z.string().optional(),
mentionUuid: z.string().optional(),
diff --git a/js/app/packages/block-md/component/MarkdownEditor.tsx b/js/app/packages/block-md/component/MarkdownEditor.tsx
index d3b452d4c4..87e1668e1f 100644
--- a/js/app/packages/block-md/component/MarkdownEditor.tsx
+++ b/js/app/packages/block-md/component/MarkdownEditor.tsx
@@ -377,6 +377,7 @@ export function MarkdownEditor(props: { autoFocusOnMount?: boolean } = {}) {
blockName: res.blockName,
blockParams,
mentionUuid: mentionId,
+ createdAt: Date.now(),
});
if (position === 'before') {
diff --git a/js/app/packages/core/block.ts b/js/app/packages/core/block.ts
index e2596379ae..227187395d 100644
--- a/js/app/packages/core/block.ts
+++ b/js/app/packages/core/block.ts
@@ -59,7 +59,6 @@ export const BlockRegistry = [
'video',
'email',
'contact',
- 'task',
'automation',
] as const;
@@ -103,7 +102,7 @@ export const NonDocumentBlockTypes = [
* allowed blocks on the right.
*/
export type BlockCombinationRules = {
- [Key in BlockName]: Set<BlockName>;
+ [Key in BlockName | BlockAlias]: Set<BlockName>;
};
export type PreviewState = {
@@ -146,6 +145,7 @@ export const ValidBlockCombinations: BlockCombinationRules = {
contact: allBlockNames,
task: allBlockNames,
automation: allBlockNames,
+ csv: allBlockNames,
} as const;
// maps block name to valid parents
@@ -166,6 +166,7 @@ export const ValidNestingCombinations: BlockCombinationRules = {
contact: new Set([]),
task: new Set([]),
automation: new Set([]),
+ csv: new Set([]),
};
export const LoadErrors = {
diff --git a/js/app/packages/core/component/DocumentPreview.tsx b/js/app/packages/core/component/DocumentPreview.tsx
index f935fa401c..1c5ed7fd73 100644
--- a/js/app/packages/core/component/DocumentPreview.tsx
+++ b/js/app/packages/core/component/DocumentPreview.tsx
@@ -1,4 +1,3 @@
-// URL params constants
import { URL_PARAMS as URL_PARAMS_CANVAS } from '@block-canvas/constants';
import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
import { useOpenChatForAttachment } from '@block-chat/client';
@@ -11,8 +10,8 @@ import {
useMaybeBlockId,
useMaybeBlockName,
} from '@core/block';
-import { itemToBlockName } from '@core/constant/allBlocks';
-// Components
+import { itemToBlockName, resolveBlockAlias } from '@core/constant/allBlocks';
+import { EntityIcon } from '@core/component/EntityIcon';
import { Panel } from '@ui';
import { toast } from '@core/component/Toast/Toast';
import {
@@ -24,7 +23,6 @@ import { blockNameToItemType } from '@service-storage/client';
import { copyBranchNameToClipboard } from '@core/util/branchName';
import { tryMacroId, useDisplayName } from '@core/user';
import { matches } from '@core/util/match';
-// Icon imports
import CollapseInlinePreview from '@icon/regular/arrows-in-line-horizontal.svg';
import OpenIcon from '@icon/regular/arrows-out.svg';
import ExpandInlinePreview from '@icon/regular/arrows-out-line-horizontal.svg';
@@ -66,7 +64,6 @@ import { Dynamic } from 'solid-js/web';
import { useEntityProperties } from '@core/component/Properties/hooks';
import { SYSTEM_PROPERTY_IDS } from '@core/component/Properties/constants';
import { PropertyValue } from '@core/component/Properties/component/propertyValue/PropertyValue';
-
import { formatDate } from '../util/date';
import NotFound from './AccessErrorViews/NotFound';
import Unauthorized from './AccessErrorViews/Unauthorized';
@@ -436,6 +433,7 @@ export function PopupPreview(props: {
date: string;
characterCount?: number;
};
+ useFallbackData?: boolean;
}) {
// Hooks
const navigate = useNavigate();
@@ -591,7 +589,7 @@ export function PopupPreview(props: {
const orchestrator = splitManager.getOrchestrator();
const handle = await orchestrator.getBlockHandle(
props.documentInfo.id,
- type
+ resolveBlockAlias(type)
);
await handle?.goToLocationFromParams(props.documentInfo.params);
@@ -720,7 +718,7 @@ export function PopupPreview(props: {
onMouseEnter={props.mouseEnter}
onMouseLeave={props.mouseLeave}
>
- <Panel active>
+ <Panel active class="py-2">
<Switch>
{/* Loading state */}
<Match when={item().loading}>
@@ -871,13 +869,37 @@ export function PopupPreview(props: {
{/* No access / does not exist errors */}
<Match when={matches(item(), isPreviewItemNoAccess)}>
{(noAccessItem) => (
- <div class="text-sm p-4">
- {noAccessItem().access === 'no_access' ? (
- <Unauthorized />
- ) : (
- <NotFound />
- )}
- </div>
+ <Show
+ when={
+ noAccessItem().access === 'does_not_exist' &&
+ props.useFallbackData &&
+ props.documentInfo.name
+ }
+ fallback={
+ <div class="text-sm p-4">
+ {noAccessItem().access === 'no_access' ? (
+ <Unauthorized />
+ ) : (
+ <NotFound />
+ )}
+ </div>
+ }
+ >
+ <div class="w-full flex flex-col">
+ <div class="flex items-center justify-between gap-2 px-3 pt-3 pb-2">
+ <div class="flex items-center gap-2 min-w-0">
+ <EntityIcon
+ targetType={props.documentInfo.type}
+ size="sm"
+ />
+ </div>
+ <div class="flex shrink-0">{renderActionButtons()}</div>
+ </div>
+ <div class="line-clamp-2 break-words px-2 mb-2">
+ {props.documentInfo.name}
+ </div>
+ </div>
+ </Show>
)}
</Match>
</Switch>
diff --git a/js/app/packages/core/component/FileList/itemOperations.ts b/js/app/packages/core/component/FileList/itemOperations.ts
index c0d4091336..f7c6eee444 100644
--- a/js/app/packages/core/component/FileList/itemOperations.ts
+++ b/js/app/packages/core/component/FileList/itemOperations.ts
@@ -183,9 +183,11 @@ export async function deleteItem(args: {
itemType === 'channel' ||
itemType === 'email' ||
itemType === 'channel_message' ||
- itemType === 'automation'
+ itemType === 'automation' ||
+ itemType === 'call'
)
return false;
+
const removed = await removeHistoryItem(itemType, id);
if (!removed) return false;
}
diff --git a/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx b/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx
index cbd4bde311..c43f5d3675 100644
--- a/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx
@@ -19,7 +19,7 @@ import {
} from 'solid-js';
import { FloatingMenuGroup } from '../context/FloatingMenuContext';
import { LexicalWrapperContext } from '../context/LexicalWrapperContext';
-import { registerCommandEffect } from '../plugins';
+import { autoRegister, registerCommandEffect } from '../plugins';
import {
createFilesReadyHandler,
getDragDropPosition,
@@ -97,10 +97,11 @@ export const MarkdownShell: Component<
);
// Placeholder visibility
- createEffect(() => {
- markdownState();
- setShowPlaceholder(editorIsEmpty(editor));
- });
+ autoRegister(
+ editor.registerUpdateListener(({ editorState }) => {
+ setShowPlaceholder(editorIsEmpty(editorState));
+ })
+ );
// Register key handlers
registerCommandEffect(
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/core/BlockLink.tsx b/js/app/packages/core/component/LexicalMarkdown/component/core/BlockLink.tsx
index 0f0f152680..982049381f 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/core/BlockLink.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/BlockLink.tsx
@@ -1,6 +1,6 @@
import { useGlobalBlockOrchestrator } from '@app/component/GlobalAppState';
import { useSplitLayout } from '@app/component/split-layout/layout';
-import { useMaybeBlockId } from '@core/block';
+import { useMaybeBlockId, type BlockName, type BlockAlias } from '@core/block';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
import { createCallback } from '@solid-primitives/rootless';
@@ -19,7 +19,7 @@ export const blockNamesWithLocations = [
export type BlockNameWithLocations = (typeof blockNamesWithLocations)[number];
export function isBlockNameWithLocation(
- name: string
+ name: BlockName | BlockAlias
): name is BlockNameWithLocations {
return blockNamesWithLocations.includes(name as BlockNameWithLocations);
}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
index ddd5a10392..3eaa9833b7 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
@@ -1,41 +1,47 @@
+import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
import {
type BlockAlias,
type BlockName,
useMaybeBlockId,
useMaybeBlockName,
} from '@core/block';
-import { EntityIcon } from '@core/component/EntityIcon';
import {
getMentionsIcon,
mentionsAccessories,
PopupPreview,
} from '@core/component/DocumentPreview';
+import { EntityIcon } from '@core/component/EntityIcon';
+import { HoverCard } from '@core/component/HoverCard';
import { useItemPreviewData } from '@core/component/ItemPreview';
+import { PropertyValueIcon } from '@core/component/Properties/component/propertyValue/PropertyValueIcon';
+import { SYSTEM_PROPERTY_IDS } from '@core/component/Properties/constants';
+import { useEntityProperties } from '@core/component/Properties/hooks';
+import { UserIcon } from '@core/component/UserIcon';
import {
itemToBlockName,
resolveBlockAlias,
verifyBlockName,
} from '@core/constant/allBlocks';
import { ENABLE_BLOCK_IN_BLOCK } from '@core/constant/featureFlags';
-import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
import { canNestBlock } from '@core/orchestrator';
-import {
- isAccessiblePreviewItem,
- type PreviewItemNoAccess,
- type ItemEntity,
-} from '@queries/preview';
+import { formatDate } from '@core/util/date';
import { matches } from '@core/util/match';
import { openInNewSplitForMention } from '@core/util/openInNewSplit';
import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
import EyeSlashDuo from '@icon/duotone/eye-slash-duotone.svg';
import TrashSimple from '@icon/duotone/trash-simple-duotone.svg';
-import LoadingSpinner from '@icon/regular/spinner.svg';
import {
$convertMentionToCard,
$isDocumentMentionNode,
DocumentCardNode,
type DocumentMentionDecoratorProps,
} from '@lexical-core';
+import {
+ type ItemEntity,
+ isAccessiblePreviewItem,
+ type PreviewItemNoAccess,
+ useItemPreview,
+} from '@queries/preview';
import { blockNameToItemType } from '@service-storage/client';
import { createCallback } from '@solid-primitives/rootless';
import {
@@ -55,16 +61,28 @@ import {
Switch,
useContext,
} from 'solid-js';
-import { HoverCard } from '@core/component/HoverCard';
-import { useEntityProperties } from '@core/component/Properties/hooks';
-import { SYSTEM_PROPERTY_IDS } from '@core/component/Properties/constants';
-import { PropertyValueIcon } from '@core/component/Properties/component/propertyValue/PropertyValueIcon';
-import { UserIcon } from '@core/component/UserIcon';
import { LexicalWrapperContext } from '../../context/LexicalWrapperContext';
import { autoRegister, UPDATE_DOCUMENT_NAME_COMMAND } from '../../plugins';
import { openDocument } from '../core/BlockLink';
import { MentionTooltip } from './MentionTooltip';
+// Time threshold for showing fallback state for recently created mentions (1 minute)
+const RECENT_MENTION_THRESHOLD_MS = 1 * 60 * 1000;
+
+/**
+ * Determine if we should use fallback data for a mention due to stale preview cache.
+ * This happens when a mention is very recent and the preview API returns does_not_exist
+ * (likely due to cache staleness rather than actual deletion).
+ */
+function shouldUseFallbackForRecentMention(
+ previewItem: { loading: boolean; access?: string },
+ isRecent: boolean
+): boolean {
+ return (
+ !previewItem.loading && previewItem.access === 'does_not_exist' && isRecent
+ );
+}
+
function MentionContainer(props: {
icon: JSX.Element;
text: JSX.Element;
@@ -84,23 +102,6 @@ function MentionContainer(props: {
);
}
-function Spinner() {
- return (
- <div class="animate-spin">
- <LoadingSpinner />
- </div>
- );
-}
-
-function Loading(props: { collapsed?: boolean }) {
- return (
- <MentionContainer
- icon={<Spinner />}
- text={props.collapsed ? '' : 'Loading'}
- />
- );
-}
-
function InlineTaskProperties(props: { taskId: string }) {
const { properties, isLoading } = useEntityProperties(
props.taskId,
@@ -168,13 +169,78 @@ function InlinePreview(props: {
blockParams: Record<string, string>;
theme?: EditorThemeClasses;
collapsed?: boolean;
+ documentName?: string;
+ createdAt?: number;
+ isRecentMention: () => boolean;
}) {
const { item, ItemEntityIcon } = useItemPreviewData(() => props.entity);
+ const shouldShowFallback = createMemo(() => {
+ return (
+ shouldUseFallbackForRecentMention(item(), props.isRecentMention()) &&
+ props.documentName
+ );
+ });
return (
<Switch>
<Match when={item().loading}>
- <Loading />
+ <MentionContainer
+ icon={
+ <EntityIcon
+ targetType={props.blockName as any}
+ size="fill"
+ class="animate-pulse"
+ />
+ }
+ text={
+ <span
+ data-document-mention="true"
+ data-document-id={props.entity.id}
+ data-block-name={props.blockName}
+ data-document-name={props.documentName}
+ class="opacity-50"
+ >
+ <Show when={props.documentName} fallback={'Loading...'}>
+ {(name) => name().replaceAll('\n', ' ').trim()}
+ </Show>
+ </span>
+ }
+ collapsed={props.collapsed}
+ />
+ </Match>
+ <Match when={shouldShowFallback()}>
+ <MentionContainer
+ icon={<EntityIcon targetType={props.blockName as any} size="fill" />}
+ text={
+ <span
+ data-document-mention="true"
+ data-document-id={props.entity.id}
+ data-block-name={props.blockName}
+ data-document-name={props.documentName}
+ >
+ <Show when={props.documentName} fallback={'Unknown'}>
+ {(name) => name().replaceAll('\n', ' ').trim()}
+ </Show>
+ <span class="relative text-[0.8em] text-current/50 rounded-xs">
+ {(() => {
+ const accessories = mentionsAccessories(
+ props.blockName as BlockName,
+ props.blockParams
+ );
+ if (accessories) {
+ return (
+ <>
+ {` ${accessories.note ?? ''}`}
+ {getMentionsIcon(accessories.icon)}
+ </>
+ );
+ }
+ })()}
+ </span>
+ </span>
+ }
+ collapsed={props.collapsed}
+ />
</Match>
<Match when={matches(item(), isAccessiblePreviewItem)}>
{(accessibleItem) => (
@@ -198,6 +264,20 @@ function InlinePreview(props: {
data-document-name={accessibleItem().name}
>
{accessibleItem().name.replaceAll('\n', ' ').trim()}
+ <Show
+ when={
+ accessibleItem().type === 'call' &&
+ accessibleItem().updatedAt
+ }
+ >
+ {(timeStamp) => {
+ return (
+ <span class="text-current/50 text-[0.8em]">
+ {` ${formatDate(timeStamp(), { showTime: true })}`}
+ </span>
+ );
+ }}
+ </Show>
<span class="relative text-[0.8em] text-current/50 rounded-xs">
{(() => {
const accessories = mentionsAccessories(
@@ -282,6 +362,13 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
return lexicalWrapper?.isInteractable() ?? false;
});
+ // Check if this is a recently created mention that we should show fallback for
+ const isRecentMention = createMemo(() => {
+ if (!props.createdAt) return false;
+ const age = Date.now() - props.createdAt;
+ return age < RECENT_MENTION_THRESHOLD_MS;
+ });
+
const showEmbedOption = createMemo(() => {
if (!lexicalWrapper?.isInteractable()) return false;
if (!lexicalWrapper?.editor.hasNode(DocumentCardNode)) return false;
@@ -313,7 +400,7 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
return baseEntity;
};
- const { item } = useItemPreviewData(itemEntity);
+ const [item] = useItemPreview(itemEntity);
const isSelectedAsNode = createMemo(() => {
const sel = selection();
@@ -372,11 +459,14 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
});
});
} else if (i.access === 'does_not_exist') {
- setTimeout(() => {
- editor?.dispatchCommand(UPDATE_DOCUMENT_NAME_COMMAND, {
- [props.documentId]: 'Deleted',
+ // Don't update to "Deleted" if this is a recent mention
+ if (!isRecentMention()) {
+ setTimeout(() => {
+ editor?.dispatchCommand(UPDATE_DOCUMENT_NAME_COMMAND, {
+ [props.documentId]: 'Deleted',
+ });
});
- });
+ }
}
});
@@ -401,7 +491,12 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
const navHandlers = useSplitNavigationHandler<HTMLSpanElement>((e) => {
e.stopPropagation();
- if (matches(item(), (i) => !i.loading && i.access === 'access')) {
+ const i = item();
+ if (
+ !i.loading &&
+ (i.access === 'access' ||
+ shouldUseFallbackForRecentMention(i, isRecentMention()))
+ ) {
open(e);
}
});
@@ -421,9 +516,6 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
{...navHandlers}
>
<Switch>
- <Match when={item().loading}>
- <Loading collapsed={isCollapsed()} />
- </Match>
<Match when={item()}>
<InlinePreview
entity={itemEntity()}
@@ -431,6 +523,9 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
blockParams={props.blockParams || {}}
theme={props.theme}
collapsed={isCollapsed()}
+ documentName={props.documentName}
+ createdAt={props.createdAt}
+ isRecentMention={isRecentMention}
/>
</Match>
</Switch>
@@ -459,6 +554,12 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
}}
documentInfo={{
id: props.documentId,
+ name: (() => {
+ const i = item();
+ return shouldUseFallbackForRecentMention(i, isRecentMention())
+ ? props.documentName
+ : undefined;
+ })(),
type: verifyBlockName(props.blockName),
params: props.blockParams ?? {},
isOpenable: currentBlockId !== props.documentId,
@@ -468,6 +569,10 @@ export function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
showPreview: showEmbedOption(),
handlePreviewToggle: convertToCard,
}}
+ useFallbackData={shouldUseFallbackForRecentMention(
+ item(),
+ isRecentMention()
+ )}
/>
}
/>
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 f4797ef327..0d6e03bdae 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
@@ -318,7 +318,7 @@ export function ActionMenu(props: {
use:clickOutside={clickOutsideHandler}
ref={menuRef}
>
- <Panel active>
+ <Panel active class="py-2">
<div
class="overflow-y-auto scrollbar-hidden"
style={{
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx b/js/app/packages/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx
index 90b00d804a..a9f0b35c55 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/EmojiMenu.tsx
@@ -245,7 +245,7 @@ export function EmojiMenu(props: EmojiMenuProps) {
}}
ref={menuRef}
>
- <Panel active>
+ <Panel active class="py-2">
<div class="flex flex-col gap-1 px-2 w-full">
<Show
when={emojiOptions().length > 0}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
index 1c69b54ad5..e2145964e7 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
@@ -528,7 +528,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
clickOutside(el, () => clickOutsideHandler);
}}
>
- <Panel active>
+ <Panel active class="py-2">
<Show
when={controller.combinedItems().length > 0}
fallback={<div class="px-2 text-ink-extra-muted">No results</div>}
diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts
index f7fe4544ed..6cf66c46e6 100644
--- a/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts
@@ -38,7 +38,7 @@ import {
} from '@lexical-core';
import { $getId } from '@lexical-core/plugins/nodeIdPlugin';
import type { MentionNode } from '@lexical-core/utils/mentions';
-import { blockNameToItemType } from '@service-storage/client';
+import { blockNameToItemType, type ItemType } from '@service-storage/client';
import {
$createParagraphNode,
$createTextNode,
@@ -65,6 +65,7 @@ import type { Setter } from 'solid-js';
import type { MenuOperations } from '../../shared/inlineMenu';
import { $collapseSelection, $traverseNodes, nodeByKey } from '../../utils';
import { mapRegisterDelete } from '../shared';
+import { match } from 'ts-pattern';
export const INSERT_DOCUMENT_MENTION_COMMAND: LexicalCommand<DocumentMentionInfo> =
createCommand('INSERT_DOCUMENT_MENTION_COMMAND');
@@ -120,7 +121,9 @@ export type ItemMention = {
| 'thread'
| 'unknown'
| 'color'
- | 'group';
+ | 'call'
+ | 'group'
+ | 'automation';
itemId: string;
fileType?: string;
documentName?: string;
@@ -144,6 +147,7 @@ export function $isMentionNode(
$isGroupMentionNode(node)
);
}
+
export function $mentionItemFromNode(node: MentionNode): ItemMention {
if ($isDocumentMentionNode(node)) {
let fileType = '';
@@ -241,18 +245,16 @@ const getDocumentMentionItemType = (
): ItemMention['itemType'] => {
const blockName = node.__blockName;
const itemType = blockNameToItemType(verifyBlockName(blockName));
- switch (itemType) {
- case 'document':
- case 'chat':
- case 'channel':
- case 'project':
- return itemType;
- case 'email':
- return 'thread';
- default:
- console.error(`Invalid item type: ${itemType} for document mention node`);
- return 'document';
- }
+ return match<ItemType, ItemMention['itemType']>(itemType)
+ .with('email', () => 'thread')
+ .with('document', () => 'document')
+ .with('chat', () => 'chat')
+ .with('channel', () => 'channel')
+ .with('project', () => 'project')
+ .with('channel_message', () => 'channel')
+ .with('automation', () => 'automation')
+ .with('call', () => 'call')
+ .exhaustive();
};
export type MentionsPluginProps = {
@@ -337,7 +339,10 @@ function registerMentionsPlugin(
(payload) => {
editor.update(() => {
const selection = $getSelection();
- const mentionNode = $createDocumentMentionNode(payload);
+ const mentionNode = $createDocumentMentionNode({
+ ...payload,
+ createdAt: payload.createdAt ?? Date.now(),
+ });
if (payload.mentionUuid) {
mentionNode.setMentionUuid(payload.mentionUuid);
diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.ts
index 75899e6de1..641dfde981 100644
--- a/js/app/packages/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/text-paste/textPastePlugin.ts
@@ -1,4 +1,9 @@
-import type { BlockAlias, BlockName } from '@core/block';
+import {
+ BlockAliasRegistry,
+ BlockRegistry,
+ type BlockAlias,
+ type BlockName,
+} from '@core/block';
import { mergeRegister } from '@lexical/utils';
import { parseThemeV1Json } from '@theme/utils/themeValidation';
import {
@@ -19,13 +24,17 @@ type MacroAppUrlParsed = {
block: BlockName | BlockAlias | undefined;
params: Record<string, string> | undefined;
};
+
const Hosts = {
Prod: 'macro.com',
Dev: 'dev.macro.com',
- Staging: 'staging.macro.com',
Localhost: 'localhost',
} as const;
+const IgnoredParams = new Set(['referral_code']);
+
+const ValidBlockNames = [...BlockRegistry, ...BlockAliasRegistry];
+
function cleanHostname(hostname: string): string {
return hostname.replace('www.', '').toLowerCase();
}
@@ -70,21 +79,8 @@ export function parseMacroAppUrl(text: string): MacroAppUrlParsed {
};
}
- const validTypes: Array<BlockName | BlockAlias> = [
- 'chat',
- 'write',
- 'pdf',
- 'md',
- 'task',
- 'code',
- 'image',
- 'canvas',
- 'channel',
- 'project',
- 'email',
- ];
const _block: string = pathParts[1];
- if (!validTypes.includes(_block as any)) {
+ if (!ValidBlockNames.includes(_block as any)) {
return {
isValid: false,
id: undefined,
@@ -108,6 +104,7 @@ export function parseMacroAppUrl(text: string): MacroAppUrlParsed {
const id: string = pathParts[2];
const params: Record<string, string> = {};
url.searchParams.forEach((value, key) => {
+ if (IgnoredParams.has(key)) return;
params[key] = value;
});
diff --git a/js/app/packages/core/component/LexicalMarkdown/utils.ts b/js/app/packages/core/component/LexicalMarkdown/utils.ts
index 2fda9f8746..b6b6ecde95 100644
--- a/js/app/packages/core/component/LexicalMarkdown/utils.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/utils.ts
@@ -23,6 +23,7 @@ import {
} from '@lexical/utils';
import {
$isDocumentMentionNode,
+ $isMentionNode,
$isWatermarkNode,
ALL_TRANSFORMERS,
EXTERNAL_TRANSFORMERS,
@@ -413,6 +414,10 @@ export function $isEmpty() {
if (!$isParagraphNode(firstChild)) {
return false;
}
+ // Early return on pasted mentions before preview can fetch their names.
+ $traverseNodes(child, (n) => {
+ if ($isMentionNode(n)) return false;
+ });
}
if (child.getTextContent() !== '') return false;
diff --git a/js/app/packages/core/orchestrator.tsx b/js/app/packages/core/orchestrator.tsx
index 9ebdc82a08..05a1256ea2 100644
--- a/js/app/packages/core/orchestrator.tsx
+++ b/js/app/packages/core/orchestrator.tsx
@@ -12,6 +12,7 @@ import {
import { createStore } from 'solid-js/store';
import { Dynamic } from 'solid-js/web';
import {
+ type BlockAlias,
type BlockAliasContext,
Block as BlockComponent,
type BlockComponentProps,
@@ -285,6 +286,10 @@ type GetBlockHandleFn = {
blockId: string,
blockType: T
): Promise<BlockHandle<BlockMethodsFor<T>> | undefined>;
+ <T extends BlockAlias>(
+ blockId: string,
+ blockType: T
+ ): Promise<BlockHandle<any> | undefined>;
(blockId: string): Promise<BlockHandle<any> | undefined>;
};
@@ -350,10 +355,10 @@ export function createBlockOrchestrator(): BlockOrchestrator {
setBlocks(id, undefined!);
};
- const getBlockHandle: GetBlockHandleFn = async function <T extends BlockName>(
+ const getBlockHandle: GetBlockHandleFn = async function (
blockId: string,
- blockType?: T
- ): Promise<BlockHandle<BlockMethodsFor<T>> | undefined> {
+ blockType?: BlockName | BlockAlias
+ ): Promise<BlockHandle<any> | undefined> {
await awaitBlockRegistered(blocks as any, blockId);
const block = (blocks as any)[blockId] as BlockWithHandle | undefined;
if (!block) return;
@@ -364,7 +369,7 @@ export function createBlockOrchestrator(): BlockOrchestrator {
return;
}
const [registry] = block.handle.registry;
- return createBlockHandle<BlockMethodsFor<T>>(block, registry);
+ return createBlockHandle<any>(block, registry);
};
function createManagedBlockInstance(
diff --git a/js/app/packages/core/util/create.ts b/js/app/packages/core/util/create.ts
index 57566dd92e..769863254a 100644
--- a/js/app/packages/core/util/create.ts
+++ b/js/app/packages/core/util/create.ts
@@ -16,6 +16,7 @@ import {
import { queryClient } from '@queries/client';
import { cognitionApiServiceClient } from '@service-cognition/client';
import type { CreateChatRequest } from '@service-cognition/generated/schemas';
+import { DEFAULT_CHAT_NAME } from '@block-chat/definition';
import { staticFileClient } from '@service-static-files/client';
import { storageServiceClient } from '@service-storage/client';
import type { PropertyInput } from '@service-storage/generated/schemas/propertyInput';
@@ -31,6 +32,7 @@ import {
import { isPaymentError } from './handlePaymentError';
import { err, isErr, ok } from './maybeResult';
import { refetchSoupEntity } from '@queries/soup/cache';
+import { setPreviewOnCreate } from '@queries/preview/preview';
/**
* Generate a fake sha256 hash
@@ -90,6 +92,12 @@ export async function createMarkdownFile(
if (isErr(res)) {
return;
}
+ setPreviewOnCreate({
+ itemId: documentId,
+ itemType: 'document',
+ name: args?.title ?? '',
+ fileType: 'md',
+ });
refetchSoupEntity(documentId, 'document');
return documentId;
}
@@ -159,6 +167,13 @@ export async function createTask(
// Task was created, just without content - still return the id
}
+ setPreviewOnCreate({
+ itemId: documentId,
+ itemType: 'document',
+ name: args?.title ?? '',
+ fileType: 'md',
+ subType: { type: 'task', is_completed: false },
+ });
refetchSoupEntity(documentId, 'document');
return documentId;
}
@@ -226,6 +241,12 @@ export async function createCodeFileFromText({
});
if (isErr(uploadResult)) return err('SERVER_ERROR', 'Failed to upload file');
postNewHistoryItem('document', document.metadata.documentId);
+ setPreviewOnCreate({
+ itemId: document.metadata.documentId,
+ itemType: 'document',
+ name: title ?? 'New Code File',
+ fileType: finalExtension,
+ });
refetchSoupEntity(document.metadata.documentId, 'document');
return ok({ documentId: document.metadata.documentId });
}
@@ -260,6 +281,12 @@ export async function createCanvasFileFromJsonString(args: {
if (isErr(uploadResult)) return { error: 'Failed to upload file.' };
postNewHistoryItem('document', canvas.metadata.documentId);
+ setPreviewOnCreate({
+ itemId: canvas.metadata.documentId,
+ itemType: 'document',
+ name: title ?? 'New Canvas',
+ fileType: 'canvas',
+ });
refetchSoupEntity(canvas.metadata.documentId, 'document');
return { documentId: canvas.metadata.documentId };
}
@@ -289,6 +316,11 @@ export async function createChat(args?: CreateChatRequest) {
}
const [, chat] = maybeChat;
postNewHistoryItem('chat', chat.id);
+ setPreviewOnCreate({
+ itemId: chat.id,
+ itemType: 'chat',
+ name: args?.name ?? DEFAULT_CHAT_NAME,
+ });
refetchSoupEntity(chat.id, 'chat');
return { chatId: chat.id };
}
diff --git a/js/app/packages/macro-entity/src/queries/rename.ts b/js/app/packages/macro-entity/src/queries/rename.ts
index 75287f2206..250cfff495 100644
--- a/js/app/packages/macro-entity/src/queries/rename.ts
+++ b/js/app/packages/macro-entity/src/queries/rename.ts
@@ -113,7 +113,8 @@ const renameDssSetData = (
} else if (
itemType !== 'email' &&
itemType !== 'channel_message' &&
- itemType !== 'automation'
+ itemType !== 'automation' &&
+ itemType !== 'call'
) {
txns.set(
id,
diff --git a/js/app/packages/queries/preview/fetchers.ts b/js/app/packages/queries/preview/fetchers.ts
index 991ed6d537..028654e590 100644
--- a/js/app/packages/queries/preview/fetchers.ts
+++ b/js/app/packages/queries/preview/fetchers.ts
@@ -120,6 +120,43 @@ async function fetchDocumentPreviews(ids: string[]): Promise<PreviewItem[]> {
});
}
+async function fetchCallPreviews(ids: string[]): Promise<PreviewItem[]> {
+ const result = await storageServiceClient.getBatchCallPreviews({
+ call_ids: ids,
+ });
+
+ if (isErr(result)) {
+ console.error('Failed to fetch call previews');
+ return [];
+ }
+
+ const [, data] = result;
+ return data.previews.map((call) => {
+ const base = {
+ id: call.callId,
+ type: 'call',
+ } as const;
+
+ switch (call.type) {
+ case 'exists':
+ return {
+ ...base,
+ access: 'access' as const,
+ loading: false,
+ rawName: call.channelName ?? '',
+ name: call.channelName ?? 'Unknown Call',
+ updatedAt: call.startedAt,
+ };
+ case 'does_not_exist':
+ return {
+ ...base,
+ access: call.type,
+ loading: false,
+ };
+ }
+ });
+}
+
async function fetchChatPreviews(ids: string[]): Promise<PreviewItem[]> {
const result = await cognitionApiServiceClient.getBatchChatPreviews({
chat_ids: ids,
@@ -252,6 +289,10 @@ export async function fetchPreviewBatch(
.filter((i) => i.type === 'email' || !i.type)
.map((i) => i.id);
+ const callItems = items
+ .filter((i) => i.type === 'call' || !i.type)
+ .map((i) => i.id);
+
const [
chatResults,
documentResults,
@@ -260,6 +301,7 @@ export async function fetchPreviewBatch(
emailResults,
] = await Promise.all([
chatItems.length > 0 ? fetchChatPreviews(chatItems) : Promise.resolve([]),
+ callItems.length > 0 ? fetchCallPreviews(callItems) : Promise.resolve([]),
documentItems.length > 0
? fetchDocumentPreviews(documentItems)
: Promise.resolve([]),
diff --git a/js/app/packages/queries/preview/index.ts b/js/app/packages/queries/preview/index.ts
index 5e5449c1a0..ecc1dd5644 100644
--- a/js/app/packages/queries/preview/index.ts
+++ b/js/app/packages/queries/preview/index.ts
@@ -5,6 +5,7 @@ export {
invalidatePreview,
setPreviewName,
setPreviewFileType,
+ setPreviewOnCreate,
} from './preview';
export type {
PreviewItem,
diff --git a/js/app/packages/queries/preview/preview.ts b/js/app/packages/queries/preview/preview.ts
index d75ec35368..3842e56df1 100644
--- a/js/app/packages/queries/preview/preview.ts
+++ b/js/app/packages/queries/preview/preview.ts
@@ -1,3 +1,4 @@
+import { queryReadyGate } from '@queries/gate';
import { DEFAULT_ITEM_TYPE, type ItemType } from '@service-storage/client';
import { useQuery } from '@tanstack/solid-query';
import type { Accessor, Setter } from 'solid-js';
@@ -6,15 +7,36 @@ import { queryClient } from '../client';
import { previewDataLoader } from './dataloader';
import { defaultNameTransform, fetchMessageContext } from './fetchers';
import { previewKeys } from './keys';
-import type { ItemEntity, PreviewItem, AccessiblePreviewItem } from './types';
-import { queryReadyGate } from '@queries/gate';
+import type { AccessiblePreviewItem, ItemEntity, PreviewItem } from './types';
+
+// DEBUG VARS
+const SIMULATE_BACKEND_DELAY_MS = 0;
+const SIMULATE_FAILURE = false;
const PREVIEW_STALE_TIME = 60 * 1000 * 60 * 24; // 24 hours
function itemPreviewQueryOptions(item: ItemEntity) {
return {
queryKey: previewKeys.item(item.id).queryKey,
- queryFn: () => previewDataLoader.load(item),
+ queryFn: async () => {
+ // Simulate backend propagation delay for testing race conditions
+ if (SIMULATE_BACKEND_DELAY_MS > 0) {
+ await new Promise((resolve) =>
+ setTimeout(resolve, SIMULATE_BACKEND_DELAY_MS)
+ );
+ }
+
+ if (SIMULATE_FAILURE) {
+ return Promise.resolve({
+ id: item.id,
+ type: item.type ?? DEFAULT_ITEM_TYPE,
+ access: 'does_not_exist',
+ loading: false,
+ } as PreviewItem);
+ }
+
+ return previewDataLoader.load(item);
+ },
staleTime: PREVIEW_STALE_TIME,
};
}
@@ -138,3 +160,76 @@ export function setPreviewName({
return res;
}
+
+/**
+ * Optimistically populate preview cache for a newly created item.
+ * This prevents race conditions where a fetch might return 'does_not_exist'
+ * before the backend has fully propagated the new item.
+ *
+ * Call this immediately after creating an item to ensure the preview cache
+ * has valid data before any components try to fetch it.
+ *
+ * @param itemId - The unique identifier of the newly created item
+ * @param itemType - The type of item ('document', 'chat', 'project', etc.)
+ * @param name - Optional name for the item. Defaults to empty string if not provided
+ * @param fileType - Optional file type (e.g., 'md', 'canvas', 'py'). Used for documents
+ * @param subType - Optional subType to distinguish special document types.
+ * **Important**: For tasks, you MUST pass `{ type: 'task', is_completed: false }`
+ * to properly identify the document as a task rather than a regular markdown file.
+ * Without this, tasks will appear as generic markdown documents in the UI.
+ *
+ * @example
+ * // Creating a regular markdown document
+ * setPreviewOnCreate({
+ * itemId: docId,
+ * itemType: 'document',
+ * name: 'My Document',
+ * fileType: 'md',
+ * });
+ *
+ * @example
+ * // Creating a task - note the subType parameter
+ * setPreviewOnCreate({
+ * itemId: taskId,
+ * itemType: 'document',
+ * name: 'My Task',
+ * fileType: 'md',
+ * subType: { type: 'task', is_completed: false },
+ * });
+ */
+export function setPreviewOnCreate({
+ itemId,
+ itemType,
+ name,
+ fileType,
+ subType,
+}: {
+ itemId: string;
+ itemType: ItemType;
+ name?: string;
+ fileType?: string;
+ subType?: { type: 'task'; is_completed?: boolean };
+}) {
+ const defaultPreviewItem: AccessiblePreviewItem = {
+ id: itemId,
+ rawName: name ?? '',
+ name: name ?? '',
+ loading: false,
+ access: 'access',
+ type: itemType,
+ fileType: fileType as any,
+ subType: subType as any,
+ updatedAt: new Date().toISOString(),
+ };
+
+ // Optimistically set the preview data
+ setPreviewData(itemId, (_prev) => defaultPreviewItem);
+
+ // Schedule a background refetch to get the real data from the server
+ // Use a small delay to give the backend time to propagate
+ setTimeout(() => {
+ queryClient.invalidateQueries({
+ queryKey: previewKeys.item(itemId).queryKey,
+ });
+ }, 100);
+}
diff --git a/js/app/packages/queries/storage/projects.ts b/js/app/packages/queries/storage/projects.ts
index 4c107434b4..02d888332b 100644
--- a/js/app/packages/queries/storage/projects.ts
+++ b/js/app/packages/queries/storage/projects.ts
@@ -13,6 +13,7 @@ import {
useUpsertToHistoryMutation,
refetchHistory,
} from '@queries/history/history';
+import { setPreviewOnCreate } from '@queries/preview/preview';
const PROJECTS_STALE_TIME = 5 * 60 * 1000;
const PROJECTS_GC_TIME = 10 * 60 * 1000;
@@ -99,6 +100,11 @@ export async function createProject(params: {
if (isOk(maybeResult)) {
const projectId = maybeResult[1].id;
+ setPreviewOnCreate({
+ itemId: projectId,
+ itemType: 'project',
+ name: params.name,
+ });
await storageServiceClient.upsertItemToUserHistory({
itemId: projectId,
itemType: 'project',
@@ -187,8 +193,13 @@ export function useCreateProjectMutation(
return { previousData, tempProjectId };
},
- onSuccess: (projectId, _params, _context) => {
+ onSuccess: (projectId, params, _context) => {
if (projectId) {
+ setPreviewOnCreate({
+ itemId: projectId,
+ itemType: 'project',
+ name: params.name,
+ });
upsertToHistoryMutation.mutate({
itemId: projectId,
itemType: 'project',
diff --git a/js/app/packages/service-clients/service-storage/client.ts b/js/app/packages/service-clients/service-storage/client.ts
index f03ff65ff9..84643d5ff8 100644
--- a/js/app/packages/service-clients/service-storage/client.ts
+++ b/js/app/packages/service-clients/service-storage/client.ts
@@ -34,6 +34,7 @@ import type { IDocumentStorageServiceFile } from '@filesystem/file';
import { platformFetch } from 'core/util/platformFetch';
import type {
AccessLevel,
+ CallRecordPreview,
PostSoupRequest,
SoupPage,
View,
@@ -127,16 +128,20 @@ export type ItemType =
| 'channel'
| 'email'
| 'channel_message'
+ | 'call'
| 'automation';
export const DEFAULT_ITEM_TYPE: ItemType = 'document';
const itemTypeSet = new Set([
'document',
- 'channel',
- 'email',
'chat',
'project',
+ 'channel',
+ 'email',
+ 'channel_message',
+ 'call',
+ 'automation',
'thread',
]);
@@ -150,6 +155,8 @@ export function blockNameToItemType(
switch (blockName) {
case 'chat':
return 'chat';
+ case 'call':
+ return 'call';
case 'channel':
return 'channel';
case 'project':
@@ -542,6 +549,7 @@ export const storageServiceClient = {
(result) => result.data
);
},
+
async getBatchDocumentPreviews(args: { document_ids: string[] }) {
return mapOk(
await dssFetch<{ previews: DocumentPreview[] }>(`/documents/preview`, {
@@ -554,6 +562,21 @@ export const storageServiceClient = {
);
},
+ async getBatchCallPreviews(args: { call_ids: string[] }) {
+ return mapOk(
+ await dssFetch<{ previews: CallRecordPreview[] }>(
+ `/call/record/preview`,
+ {
+ method: 'POST',
+ body: JSON.stringify({ callIds: args.call_ids }),
+ }
+ ),
+ (result) => ({
+ previews: result.previews,
+ })
+ );
+ },
+
async getDocumentProcessingResult<T extends ProcessingResultType>(params: {
documentId: string;
type: T;
diff --git a/js/lexical-core/nodes/DocumentMentionNode.ts b/js/lexical-core/nodes/DocumentMentionNode.ts
index 72dbc5206b..19bf3598d0 100644
--- a/js/lexical-core/nodes/DocumentMentionNode.ts
+++ b/js/lexical-core/nodes/DocumentMentionNode.ts
@@ -25,6 +25,8 @@ export type DocumentMentionInfo = {
collapsed?: boolean;
// for channels
channelType?: string;
+ // timestamp when mention was created
+ createdAt?: number;
};
export type SerializedDocumentMentionNode = Spread<
@@ -47,6 +49,7 @@ export class DocumentMentionNode extends DecoratorNode<
__mentionUuid: string | undefined;
__collapsed: boolean;
__channelType: string | undefined;
+ __createdAt: number | undefined;
static getType() {
return 'document-mention';
@@ -69,6 +72,7 @@ export class DocumentMentionNode extends DecoratorNode<
node.__mentionUuid,
node.__collapsed,
node.__channelType,
+ node.__createdAt,
node.__key
);
}
@@ -81,6 +85,7 @@ export class DocumentMentionNode extends DecoratorNode<
mentionUuid?: string,
collapsed?: boolean,
channelType?: string,
+ createdAt?: number,
key?: NodeKey
) {
super(key);
@@ -91,6 +96,7 @@ export class DocumentMentionNode extends DecoratorNode<
this.__mentionUuid = mentionUuid;
this.__collapsed = collapsed ?? false;
this.__channelType = channelType;
+ this.__createdAt = createdAt;
}
static importJSON(serializedNode: SerializedDocumentMentionNode) {
@@ -102,6 +108,7 @@ export class DocumentMentionNode extends DecoratorNode<
mentionUuid: serializedNode.mentionUuid,
collapsed: serializedNode.collapsed ?? false,
channelType: serializedNode.channelType,
+ createdAt: serializedNode.createdAt,
});
$applyIdFromSerialized(node, serializedNode);
return node;
@@ -117,6 +124,7 @@ export class DocumentMentionNode extends DecoratorNode<
mentionUuid: this.__mentionUuid,
collapsed: this.__collapsed,
channelType: this.__channelType,
+ createdAt: this.__createdAt,
type: DocumentMentionNode.getType(),
version: VERSION,
};
@@ -131,6 +139,7 @@ export class DocumentMentionNode extends DecoratorNode<
mentionUuid: this.__mentionUuid,
collapsed: this.__collapsed,
channelType: this.__channelType,
+ createdAt: this.__createdAt,
};
}
@@ -155,6 +164,7 @@ export class DocumentMentionNode extends DecoratorNode<
const collapsed = domNode.getAttribute('data-collapsed') === 'true';
const channelType =
domNode.getAttribute('data-channel-type') || undefined;
+ const createdAt = domNode.getAttribute('data-created-at');
if (documentId && blockName) {
const node = $createDocumentMentionNode({
@@ -165,6 +175,7 @@ export class DocumentMentionNode extends DecoratorNode<
mentionUuid,
collapsed,
channelType,
+ createdAt: createdAt ? parseInt(createdAt, 10) : undefined,
});
return { node };
}
@@ -193,6 +204,7 @@ export class DocumentMentionNode extends DecoratorNode<
'data-block-params': JSON.stringify(this.__blockParams),
'data-mention-uuid': this.__mentionUuid || '',
'data-channel-type': this.__channelType || '',
+ 'data-created-at': this.__createdAt?.toString() || '',
DOMConversionMap: this.__collapsed.toString(),
};
}
@@ -245,6 +257,10 @@ export class DocumentMentionNode extends DecoratorNode<
return this.__channelType;
}
+ getCreatedAt(): number | undefined {
+ return this.__createdAt;
+ }
+
setDocumentId(documentId: string) {
const writable = this.getWritable();
writable.__documentId = documentId;
@@ -287,6 +303,12 @@ export class DocumentMentionNode extends DecoratorNode<
return writable;
}
+ setCreatedAt(createdAt: number | undefined) {
+ const writable = this.getWritable();
+ writable.__createdAt = createdAt;
+ return writable;
+ }
+
decorate(_: LexicalEditor, config: EditorConfig) {
const decorator =
getDecorator<DocumentMentionDecoratorProps>(DocumentMentionNode);
@@ -300,6 +322,7 @@ export class DocumentMentionNode extends DecoratorNode<
mentionUuid: this.__mentionUuid,
collapsed: this.__collapsed,
channelType: this.__channelType,
+ createdAt: this.__createdAt,
key: this.getKey(),
theme: config.theme,
});
@@ -317,7 +340,8 @@ export function $createDocumentMentionNode(
params.blockParams,
params.mentionUuid,
params.collapsed,
- params.channelType
+ params.channelType,
+ params.createdAt ?? Date.now()
);
return $applyNodeReplacement(node);
}