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): make task creation not fail when listitem text length exceeds backend limit (#2556)

Seamusdeded37b93f6
diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/checkbox-to-task/checkboxParsing.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/checkbox-to-task/checkboxParsing.ts
index 0d59c39826..fbe190e42c 100644
--- a/js/app/packages/core/component/LexicalMarkdown/plugins/checkbox-to-task/checkboxParsing.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/checkbox-to-task/checkboxParsing.ts
@@ -1,9 +1,11 @@
import type { ListItemNode } from '@lexical/list';
+import { $isDateMentionNode, $isUserMentionNode } from '@lexical-core';
import {
parseContactMentions,
parseDocumentMentions,
parseGroupMentions,
} from '@lexical-core/utils/parsers';
+import { $isElementNode, type LexicalNode } from 'lexical';
import { $elementNodeToMarkdown } from '../../utils';
import type { ParsedCheckbox } from './types';
import { isValid } from 'date-fns';
@@ -74,6 +76,27 @@ export function extractTitleFromMarkdown(markdownText: string): string {
return title.trim().replace(/\s+/g, ' ');
}
+/**
+ * Get plain text title from a ListItemNode, collecting text from all children
+ * except user/date mentions (which become task properties instead).
+ */
+function $extractTitleFromNode(node: ListItemNode): string {
+ return $collectTextContent(node).trim().replace(/\s+/g, ' ');
+}
+
+function $collectTextContent(node: LexicalNode): string {
+ if ($isUserMentionNode(node) || $isDateMentionNode(node)) {
+ return '';
+ }
+ if ($isElementNode(node)) {
+ return node
+ .getChildren()
+ .map((child) => $collectTextContent(child))
+ .join('');
+ }
+ return node.getTextContent();
+}
+
/**
* Parse a ListItemNode checkbox into structured data for task creation.
* Must be called within Lexical update context (not read) because
@@ -84,7 +107,7 @@ export function $parseCheckboxNode(node: ListItemNode): ParsedCheckbox {
return {
nodeKey: node.getKey(),
- title: extractTitleFromMarkdown(rawMarkdown),
+ title: $extractTitleFromNode(node),
rawMarkdown,
assigneeUserIds: extractUserMentions(rawMarkdown),
dueDate: extractDateMention(rawMarkdown),
diff --git a/js/app/packages/core/util/taskCreation.ts b/js/app/packages/core/util/taskCreation.ts
index 7c094e87b6..b377e0aeda 100644
--- a/js/app/packages/core/util/taskCreation.ts
+++ b/js/app/packages/core/util/taskCreation.ts
@@ -5,8 +5,17 @@ import {
import type { PropertyInput } from '@service-storage/generated/schemas/propertyInput';
import { createTask } from './create';
+/**
+ * Maximum task name length in grapheme clusters, matching the backend validation
+ * in rust/cloud-storage/documents/src/domain/service.rs (limit: 100).
+ * Small buffer accounts for possible Unicode version differences between
+ * JS Intl.Segmenter and Rust's unicode-segmentation crate.
+ */
+export const MAX_TASK_NAME_LENGTH = 97;
+
export type TaskData = {
title: string;
+ rawMarkdown: string;
assigneeUserIds: string[];
dueDate: Date | null;
};
@@ -73,17 +82,29 @@ function buildPropertyInputs(
return properties;
}
+function toGraphemes(text: string): string[] {
+ const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
+ return Array.from(segmenter.segment(text)).map((s) => s.segment);
+}
+
export async function createTaskFromData(
task: TaskData,
options: TaskCreationOptions
): Promise<string | null> {
if (!task.title.trim()) return null;
+ const graphemes = toGraphemes(task.title);
+ const titleExceedsLimit = graphemes.length > MAX_TASK_NAME_LENGTH;
+ const title = titleExceedsLimit
+ ? graphemes.slice(0, MAX_TASK_NAME_LENGTH).join('')
+ : task.title;
+ const content = titleExceedsLimit ? task.rawMarkdown : '';
+
const propertyValues = buildPropertyInputs(task, options);
const documentId = await createTask({
- title: task.title,
- content: '',
+ title,
+ content,
propertyValues: propertyValues.length > 0 ? propertyValues : undefined,
});