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(tasks): various task routing bugs (#2782)

Seamus59ceac3ec842
diff --git a/js/app/packages/block-md/component/MarkdownEditor.tsx b/js/app/packages/block-md/component/MarkdownEditor.tsx
index 0406602379..c6d25bb1fa 100644
--- a/js/app/packages/block-md/component/MarkdownEditor.tsx
+++ b/js/app/packages/block-md/component/MarkdownEditor.tsx
@@ -114,7 +114,7 @@ import {
import { iosCursorScrollPlugin } from '@core/component/LexicalMarkdown/plugins/ios-cursor-scroll';
import { ScopedPortal } from '@core/component/ScopedPortal';
import { toast } from '@core/component/Toast/Toast';
-import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import { itemToBlockName } from '@core/constant/allBlocks';
import {
ENABLE_MARKDOWN_COMMENTS,
ENABLE_MARKDOWN_DIFF,
@@ -323,7 +323,7 @@ export function MarkdownEditor(props: { autoFocusOnMount?: boolean } = {}) {
clientY: currentPos.y,
};
const item = event.draggable.data;
- const blockName = fileTypeToBlockName(item.fileType ?? item.type);
+ const blockName = itemToBlockName(item);
if (!blockName) return;
let id = event.draggable.data.id as string;
if (event.draggable.data.type === 'channel_message') {
diff --git a/js/app/packages/core/component/DocumentPreview.tsx b/js/app/packages/core/component/DocumentPreview.tsx
index 1c91db498f..a38878f80b 100644
--- a/js/app/packages/core/component/DocumentPreview.tsx
+++ b/js/app/packages/core/component/DocumentPreview.tsx
@@ -10,6 +10,7 @@ import {
useMaybeBlockId,
useMaybeBlockName,
} from '@core/block';
+import { itemToBlockName } from '@core/constant/allBlocks';
// Components
import { ClippedPanel } from '@core/component/ClippedPanel';
import { toast } from '@core/component/Toast/Toast';
@@ -442,6 +443,17 @@ export function PopupPreview(props: {
const { item, ItemEntityIcon } = useItemPreviewData(itemPreviewEntity);
+ // Resolve the caller-provided type against the item's actual subType so
+ // that e.g. a markdown doc with `subType: { type: 'task' }` routes to the
+ // 'task' block alias instead of raw 'md'. Mirrors BlockLink/EntityMention.
+ const targetBlockType = createMemo<BlockName | BlockAlias>(() => {
+ const i = item();
+ if (isAccessiblePreviewItem(i)) {
+ return itemToBlockName(i);
+ }
+ return props.documentInfo.type;
+ });
+
// Derived state
const canOpenInChat = createCallback(() => {
if (blockName && ['chat'].includes(blockName)) {
@@ -464,10 +476,11 @@ export function PopupPreview(props: {
};
const openDocument = createCallback(async () => {
+ const type = targetBlockType();
const splitManager = globalSplitManager();
if (!splitManager) {
console.warn('No split manager found');
- let link = `/${props.documentInfo.type}/${props.documentInfo.id}`;
+ let link = `/${type}/${props.documentInfo.id}`;
if (props.documentInfo.params) {
const queryParams = new URLSearchParams(
props.documentInfo.params
@@ -479,7 +492,7 @@ export function PopupPreview(props: {
}
splitManager.replaceAllSplits({
- type: props.documentInfo.type,
+ type,
id: props.documentInfo.id,
params: props.documentInfo.params,
});
@@ -501,7 +514,7 @@ export function PopupPreview(props: {
if (hostname === 'localhost') {
hostname = 'dev.macro.com';
}
- let link = `https://${hostname}/app/${props.documentInfo.type}/${props.documentInfo.id}`;
+ let link = `https://${hostname}/app/${targetBlockType()}/${props.documentInfo.id}`;
if (
props.documentInfo.params &&
@@ -532,7 +545,7 @@ export function PopupPreview(props: {
const splitManager = globalSplitManager();
if (!splitManager) return false;
return !!splitManager.getSplitByContent(
- props.documentInfo.type,
+ targetBlockType(),
props.documentInfo.id
);
};
@@ -541,8 +554,9 @@ export function PopupPreview(props: {
const splitManager = globalSplitManager();
if (!splitManager) return;
+ const type = targetBlockType();
const existing = splitManager.getSplitByContent(
- props.documentInfo.type,
+ type,
props.documentInfo.id
);
if (existing) {
@@ -550,7 +564,7 @@ export function PopupPreview(props: {
} else {
splitManager.createNewSplit({
content: {
- type: props.documentInfo.type,
+ type,
id: props.documentInfo.id,
params: props.documentInfo.params,
},
@@ -558,12 +572,12 @@ export function PopupPreview(props: {
});
}
- if (!isBlockNameWithLocation(props.documentInfo.type)) return;
+ if (!isBlockNameWithLocation(type)) return;
const orchestrator = splitManager.getOrchestrator();
const handle = await orchestrator.getBlockHandle(
props.documentInfo.id,
- props.documentInfo.type
+ type
);
await handle?.goToLocationFromParams(props.documentInfo.params);
diff --git a/js/app/packages/entity/src/extractors-notification/mobile-notification-stacks.tsx b/js/app/packages/entity/src/extractors-notification/mobile-notification-stacks.tsx
index 8c27453f95..d74afa5e55 100644
--- a/js/app/packages/entity/src/extractors-notification/mobile-notification-stacks.tsx
+++ b/js/app/packages/entity/src/extractors-notification/mobile-notification-stacks.tsx
@@ -103,7 +103,17 @@ function MobileStackRow(props: {
const mostRecent = getMostRecentNotification(props.stack);
const splitManager = globalSplitManager();
if (!splitManager) return;
- await openNotification(mostRecent, splitManager, e.shiftKey);
+ const entity = props.entity;
+ const entityOverride = {
+ fileType: 'fileType' in entity ? entity.fileType : undefined,
+ subType: 'subType' in entity ? entity.subType : undefined,
+ };
+ await openNotification(
+ mostRecent,
+ splitManager,
+ e.shiftKey,
+ entityOverride
+ );
await notificationSource.markAsRead(mostRecent);
};
diff --git a/js/app/packages/entity/src/extractors-notification/notification-stacks.tsx b/js/app/packages/entity/src/extractors-notification/notification-stacks.tsx
index a4b607539d..14c070fab2 100644
--- a/js/app/packages/entity/src/extractors-notification/notification-stacks.tsx
+++ b/js/app/packages/entity/src/extractors-notification/notification-stacks.tsx
@@ -51,6 +51,7 @@ interface NotificationStacksProps {
function NotificationStackRow(props: {
stack: NotificationStack;
+ entity: EntityData;
onClick?: (e: PointerEvent | MouseEvent | KeyboardEvent) => void;
content?: JSX.Element;
}) {
@@ -67,7 +68,17 @@ function NotificationStackRow(props: {
if (!splitManager) return;
e.stopPropagation();
- await openNotification(mostRecent, splitManager, e.shiftKey);
+ const entity = props.entity;
+ const entityOverride = {
+ fileType: 'fileType' in entity ? entity.fileType : undefined,
+ subType: 'subType' in entity ? entity.subType : undefined,
+ };
+ await openNotification(
+ mostRecent,
+ splitManager,
+ e.shiftKey,
+ entityOverride
+ );
await notificationSource.markAsRead(mostRecent);
props.onClick?.(e);
};
@@ -189,7 +200,11 @@ export function NotificationStacks(props: NotificationStacksProps) {
togglePosition="bottom"
>
{(stack) => (
- <NotificationStackRow stack={stack} onClick={props.onClick} />
+ <NotificationStackRow
+ stack={stack}
+ entity={props.entity}
+ onClick={props.onClick}
+ />
)}
</CollapsibleList>
</Show>
diff --git a/js/app/packages/notifications/notification-navigation.ts b/js/app/packages/notifications/notification-navigation.ts
index c6eb07ee65..510a31479d 100644
--- a/js/app/packages/notifications/notification-navigation.ts
+++ b/js/app/packages/notifications/notification-navigation.ts
@@ -1,6 +1,6 @@
import type { SplitManager } from '@app/component/split-layout/layoutManager';
import type { BlockAlias, BlockName } from '@core/block';
-import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import { itemToBlockName } from '@core/constant/allBlocks';
import type { NotificationType } from '@core/types';
import type { UnifiedNotification } from './types';
import { getNotificationById } from '@queries/notification/user-notifications';
@@ -90,8 +90,27 @@ async function openChannelNotification(
});
}
-function safeFileTypeToBlockName(fileType: string | undefined | null) {
- return fileTypeToBlockName(fileType) ?? 'unknown';
+// Minimal entity shape — the live entity from the UI is authoritative when
+// available (notification metadata is a snapshot at notification time and may
+// lack `subType` for older events).
+export type NotificationEntityOverride = {
+ fileType?: string | null;
+ subType?: { type: string } | null;
+};
+
+// Resolve the block type for a document notification, honoring `subType` so
+// that e.g. a markdown doc with `subType: { type: 'task' }` routes to the
+// 'task' block alias instead of raw 'md'. Prefers the live entity's fields
+// over the notification-metadata snapshot when provided.
+function safeDocumentContentToBlockName(
+ content: NotificationEntityOverride,
+ entity?: NotificationEntityOverride
+) {
+ return itemToBlockName({
+ type: 'document',
+ fileType: entity?.fileType ?? content.fileType ?? undefined,
+ subType: entity?.subType ?? content.subType ?? undefined,
+ } as Parameters<typeof itemToBlockName>[0]);
}
type NotSupportedError = {
@@ -107,7 +126,8 @@ type NotFoundError = {
export type OpenNotificationFromIdError = NotSupportedError | NotFoundError;
function getSupportedHandler(
- notification: UnifiedNotification
+ notification: UnifiedNotification,
+ entity?: NotificationEntityOverride
): ((layoutManager: SplitManager, newSplit?: boolean) => Promise<void>) | null {
const tag = notification.notification_metadata.tag;
@@ -145,7 +165,7 @@ function getSupportedHandler(
return async (lm: SplitManager, newSplit: boolean = false) =>
openSplitIfNotOpen(
lm,
- safeFileTypeToBlockName(meta.content.fileType),
+ safeDocumentContentToBlockName(meta.content, entity),
notification.entity_id,
{ newSplit }
);
@@ -164,7 +184,7 @@ function getSupportedHandler(
return async (lm: SplitManager, newSplit: boolean = false) =>
openSplitIfNotOpen(
lm,
- safeFileTypeToBlockName(meta.content.fileType),
+ safeDocumentContentToBlockName(meta.content, entity),
notification.entity_id,
{ newSplit }
);
@@ -175,7 +195,7 @@ function getSupportedHandler(
return async (lm: SplitManager, newSplit: boolean = false) =>
openSplitIfNotOpen(
lm,
- safeFileTypeToBlockName(meta.content.fileType),
+ safeDocumentContentToBlockName(meta.content, entity),
notification.entity_id,
{ newSplit }
);
@@ -186,7 +206,7 @@ function getSupportedHandler(
return async (lm: SplitManager, newSplit: boolean = false) =>
openSplitIfNotOpen(
lm,
- safeFileTypeToBlockName(meta.content.fileType),
+ safeDocumentContentToBlockName(meta.content, entity),
notification.entity_id,
{ newSplit }
);
@@ -201,9 +221,11 @@ function getSupportedHandler(
export function openNotification(
notification: UnifiedNotification,
layoutManager: SplitManager,
- newSplit: boolean = false
+ newSplit: boolean = false,
+ entity?: NotificationEntityOverride
): ResultAsync<void, NotSupportedError> {
- const handler = getSupportedHandler(notification);
+ console.log('NOTIF', notification);
+ const handler = getSupportedHandler(notification, entity);
if (!handler) {
return errAsync({
tag: 'NotSupportedError',