fixed: Links in note preview not visible #16043#16267
fixed: Links in note preview not visible #16043#16267charlesBochet merged 4 commits intotwentyhq:mainfrom
Conversation
Greptile OverviewGreptile SummaryThis PR successfully fixes the missing link preview issue by introducing a recursive Key Changes:
Issues Found:
Confidence Score: 3/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant NoteTile
participant getActivityPreview
participant extractText
participant BlocknoteNode
NoteTile->>getActivityPreview: activityBody (JSON string)
getActivityPreview->>getActivityPreview: JSON.parse(activityBody)
loop For each block in noteBody
getActivityPreview->>extractText: node
alt node.type === 'text'
extractText-->>getActivityPreview: node.text
else node.type === 'link'
extractText->>extractText: recursively extract inner text
extractText->>extractText: format as "innerText (href)"
extractText-->>getActivityPreview: formatted link text
else node has content array
loop For each child in node.content
extractText->>extractText: recursively extract child text
end
extractText-->>getActivityPreview: joined child text
else
extractText-->>getActivityPreview: empty string
end
end
getActivityPreview->>getActivityPreview: filter empty strings
getActivityPreview->>getActivityPreview: join with newlines
getActivityPreview-->>NoteTile: preview text with links
|
packages/twenty-front/src/modules/activities/utils/getActivityPreview.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/activities/utils/getActivityPreview.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/activities/utils/getActivityPreview.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/activities/utils/getActivityPreview.ts
Outdated
Show resolved
Hide resolved
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:33758 This environment will automatically shut down when the PR is closed or after 5 hours. |
943f858 to
a7f1677
Compare
etiennejouan
left a comment
There was a problem hiding this comment.
Hi @piyush-rj, congrats for your first PR !! 👏
Good job, I took the liberty of updating the PR as it is small update.
Thank you for your contribution 🙏
Please, do not hesitate to tackle other issues.
| @@ -1,16 +1,56 @@ | |||
| // TODO: merge with getFirstNonEmptyLineOfRichText (and one duplicate I saw and also added a note on) | |||
There was a problem hiding this comment.
Rem : Not sure we can remove this TODO
| @@ -1,16 +1,56 @@ | |||
| // TODO: merge with getFirstNonEmptyLineOfRichText (and one duplicate I saw and also added a note on) | |||
| // Basic Rich-Text Node Types | |||
There was a problem hiding this comment.
nit : We avoid comment (in Twenty codebase). If you want to specify what is BaseNode, do not hesitate to be verbose :)
| @@ -1,16 +1,56 @@ | |||
| // TODO: merge with getFirstNonEmptyLineOfRichText (and one duplicate I saw and also added a note on) | |||
| // Basic Rich-Text Node Types | |||
| export interface BaseNode { | |||
There was a problem hiding this comment.
nit : Do not export these type if they are not used elsewhere. And if in future, they are used in an other file, export them from their own file
|
|
||
| switch (node.type) { | ||
| case 'text': | ||
| return (node as TextNode).text ?? ''; |
There was a problem hiding this comment.
nit : I prefer using type guard to avoid casting - not very useful here but good habit to take
| .map(child => extractText(child)) | ||
| .join(''); | ||
| const href = linkNode.href ?? ''; | ||
| return href ? `${innerText} (${href})` : innerText; |
There was a problem hiding this comment.
I think we don't want to preview href as we don't see it in editor view
|
Hey @charlesBochet! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
This PR fixes an issue where links added inside a note were not appearing in the preview shown under Company -> Notes. The link would only appear after opening the note, which led to inconsistent behavior.
Issue:
Blocknote represents text and links using different node types:
"type": "link",
"content": { "type": "text", "text": "Example" },
"href": "https://example.com"
}
The existing preview function only handled plain text nodes and completely ignored link nodes.
As a result:
Steps to Reproduce:
How I fixed it:
DisplayText (https://example.com)
Edit : closes #16043