Skip to content

The open alternative to Salesforce, designed for AI.

fixed: Links in note preview not visible #16043 (#16267)

Piyush9c334b5f0324
diff --git a/packages/twenty-front/src/modules/activities/utils/getActivityPreview.ts b/packages/twenty-front/src/modules/activities/utils/getActivityPreview.ts
index 0b171d2451f..91426553cc2 100644
--- a/packages/twenty-front/src/modules/activities/utils/getActivityPreview.ts
+++ b/packages/twenty-front/src/modules/activities/utils/getActivityPreview.ts
@@ -1,16 +1,57 @@
// TODO: merge with getFirstNonEmptyLineOfRichText (and one duplicate I saw and also added a note on)
-export const getActivityPreview = (activityBody: string | null) => {
- const noteBody = activityBody ? JSON.parse(activityBody) : [];
+import { isArray, isNonEmptyString } from '@sniptt/guards';
+
+interface BaseNode {
+ type: string;
+ content?: RichTextNode[];
+ [key: string]: unknown;
+}
+
+interface TextNode extends BaseNode {
+ type: 'text';
+ text: string;
+}
+
+interface LinkNode extends BaseNode {
+ type: 'link';
+ href?: string;
+ content?: RichTextNode[];
+}
+
+type RichTextNode = TextNode | LinkNode | BaseNode;
+
+const isTextNode = (node: RichTextNode): node is TextNode =>
+ node.type === 'text';
+
+const isLinkNode = (node: RichTextNode): node is LinkNode =>
+ node.type === 'link';
+
+export const getActivityPreview = (activityBody: string | null): string => {
+ const noteBody: RichTextNode[] = activityBody ? JSON.parse(activityBody) : [];
+
+ const extractText = (node: RichTextNode | undefined | null): string => {
+ if (!node) return '';
+
+ if (isTextNode(node)) {
+ return node.text ?? '';
+ }
+
+ if (isLinkNode(node)) {
+ return node.content?.map(extractText).join(' ') ?? '';
+ }
+
+ if (isArray(node.content)) {
+ return node.content.map(extractText).join(' ');
+ }
+
+ return '';
+ };
return noteBody.length
? noteBody
- .map((x: any) =>
- Array.isArray(x.content)
- ? x.content?.map((content: any) => content?.text).join(' ')
- : x.content?.text,
- )
- .filter((x: string) => x)
+ .map((node) => extractText(node))
+ .filter(isNonEmptyString)
.join('\n')
: '';
};