Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Notes to PDF/Word Feature Implementation (#8439) #9269

Conversation

samyakpiya
Copy link
Contributor

Closes #8439

Overview

This PR implements functionality to export notes/tasks to PDF and Word formats.

All.-.People.mp4

Testing

  • Verified that the export functionality works for both notes and tasks, whether exporting immediately after opening the editor or after editing.
  • Ensured the export button appears in the action menu only when the object is a note/task.
  • Ensured the export button appears in the RightDrawerActionMenuDropdown for a note/task.

Notes

  • The code already supports exporting to Word, but only PDF export is currently available. To enable Word export, we just need a UI option allowing users to choose between PDF and Word.
  • After upgrading the Blocknote packages to the latest version, dependency conflicts arose with tiptap and prosemirror-model. To address this, all tiptap dependencies were consolidated in the root package.json, and a resolution was added for prosemirror-model. Also, some methods in CustomAddBlockItem.tsx were missing in the newer version, so I updated the code to accommodate these changes.
  • Exporting a note with an image works only if the image is embedded, as Blocknote doesn’t support actual image uploads. Uploaded images are omitted in the PDF export, while the text is retained.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds PDF and Word export functionality for notes and tasks using BlockNote's export features, with PDF currently enabled and Word export ready for future UI implementation.

  • Added new useExportNoteAction.ts with PDF/DOCX export functions using BlockNote's xl-pdf-exporter and xl-docx-exporter packages
  • Upgraded BlockNote packages from v0.15.3 to v0.22.0 and consolidated TipTap dependencies to resolve conflicts
  • Added export action to menu configuration in DefaultSingleRecordActionsConfigV2.ts with IconFileExport icon
  • Updated CustomAddBlockItem.tsx to use newer BlockNote API methods like insertInlineContent instead of deprecated ones
  • Added Buffer polyfill and handling for embedded vs uploaded images in exports (uploaded images omitted while preserving text)

6 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile

position: 0,
isPinned: true,
Icon: IconFileExport,
availableOn: [ActionAvailableOn.SHOW_PAGE],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: export action is only available on show page while similar actions like favorites are available on both index and show pages - consider adding INDEX_PAGE_SINGLE_RECORD_SELECTION if export should work from list views

Comment on lines 36 to 38
const currentBlock = editor.getTextCursorPosition().block;

editor.insertBlocks([{ type: 'paragraph' }], currentBlock, 'after');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: currentBlock could be undefined here if getTextCursorPosition().block returns undefined - needs null check

Copy link
Member

@FelixMalfait FelixMalfait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work again!

@samyakpiya
Copy link
Contributor Author

@FelixMalfait I've made all the necessary changes. Thanks for reviewing!

Copy link
Member

@FelixMalfait FelixMalfait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. You're amongst the best contributions we've ever received (clean code, thoughtful approach)

@FelixMalfait FelixMalfait merged commit ba2f55a into twentyhq:main Dec 30, 2024
20 of 21 checks passed
Copy link
Contributor

Fails
🚫

node failed.

Log

�[31mError: �[39m SyntaxError: Unexpected token C in JSON at position 0
    at JSON.parse (<anonymous>)
�[90m    at parseJSONFromBytes (node:internal/deps/undici/undici:5584:19)�[39m
�[90m    at successSteps (node:internal/deps/undici/undici:5555:27)�[39m
�[90m    at fullyReadBody (node:internal/deps/undici/undici:1665:9)�[39m
�[90m    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)�[39m
�[90m    at async specConsumeBody (node:internal/deps/undici/undici:5564:7)�[39m
danger-results://tmp/danger-results-ae373cd3.json

Generated by 🚫 dangerJS against b712232

@samyakpiya
Copy link
Contributor Author

@FelixMalfait, thanks, that means a lot! 😁

@samyakpiya samyakpiya deleted the feat/8439-frontend-export-pdf-using-inheritance branch December 30, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export Notes to PDF/Word
2 participants