-
Notifications
You must be signed in to change notification settings - Fork 62
chore(signature-collection): Refactor report pdf creation #16278
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
Conversation
WalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx (1)
Line range hint
1-118
: Overall assessment: Significant improvements in PDF handlingThe refactoring of the
DownloadReports
component has resulted in several notable improvements:
- Introduction of
pdfState
for better management of PDF generation and caching.- Optimized PDF generation logic to prevent unnecessary operations.
- Implementation of
handleDownloadClick
for efficient report handling and prevention of redundant API calls.- Improved
useEffect
hooks for more precise control over PDF updates and opening.These changes have enhanced the component's efficiency, reduced unnecessary operations, and improved the overall user experience. The code is now more maintainable and follows React best practices.
A few minor suggestions have been provided to further optimize the component, particularly around handling loading states and fine-tuning some operators. Implementing these suggestions will further improve the robustness of the component.
Consider extracting the PDF generation and download logic into a custom hook (e.g.,
usePdfDownload
) to further improve the component's modularity and reusability across the application if similar functionality is needed elsewhere.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx (1)
Pattern
libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
🔇 Additional comments (4)
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx (4)
25-25
: LGTM: New state variable improves PDF managementThe introduction of
pdfState
is a good addition. It helps manage the PDF generation and caching process more effectively, potentially reducing unnecessary API calls and improving user experience.
Line range hint
32-38
: LGTM: Improved PDF generation logicThe modification to only generate the PDF document when
data
is available is a good optimization. It prevents unnecessary PDF generation, potentially improving performance and reducing resource usage.
59-64
: LGTM: Improved PDF update logicThe modification to the
useEffect
hook is a good improvement. By checking if the fetched report's ID matches theareaId
inpdfState
, we ensure that the PDF document is only updated when the correct data is available. This prevents unnecessary updates and potential race conditions.
109-109
: LGTM: Simplified onClick handlerThe refactoring of the
onClick
handler to use the newhandleDownloadClick
function is a good improvement. It simplifies the JSX, improves code readability, and centralizes the download logic in one place. This change is consistent with the overall refactoring of the component and follows good React practices.
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx
Show resolved
Hide resolved
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx
Show resolved
Hide resolved
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #16278 +/- ##
=======================================
Coverage 36.92% 36.92%
=======================================
Files 6781 6781
Lines 140030 140011 -19
Branches 39815 39807 -8
=======================================
- Hits 51705 51704 -1
+ Misses 88325 88307 -18
Flags with carried forward coverage won't be shown. Click here to find out more. see 6 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (2)
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx (2)
32-32
: Renamedocument
variable to avoid confusion with the globaldocument
objectUsing the name
document
may cause confusion with the browser's globaldocument
object. Renaming it improves clarity.Apply this diff to rename the variable:
- const [document, updateDocument] = usePDF({ + const [pdfDocument, updatePdfDocument] = usePDF({ document: data && ( <MyPdfDocument report={ data?.signatureCollectionAreaSummaryReport as SignatureCollectionAreaSummaryReport } /> ), })And update all usages of
document
accordingly.
59-64
: Optimize dependencies inuseEffect
to prevent unnecessary re-rendersIncluding the entire
pdfState
object in the dependencies can cause extra renders. Specify only the necessary properties.Update the dependency array:
- }, [data, pdfState, updateDocument]) + }, [data, pdfState.areaId, updateDocument])
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx (1)
Pattern
libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
🔇 Additional comments (1)
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx (1)
109-109
: Verify thatarea.id
correctly matchespdfState.areaId
Ensure that the
area.id
used inhandleDownloadClick(area.id)
corresponds accurately topdfState.areaId
, avoiding potential mismatches.Double-check that
area.id
andpdfState.areaId
are consistent throughout the component.
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx
Show resolved
Hide resolved
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx
Show resolved
Hide resolved
libs/portals/admin/signature-collection/src/screens-parliamentary/DownloadReports/index.tsx
Show resolved
Hide resolved
Datadog ReportBranch report: ✅ 0 Failed, 84 Passed, 0 Skipped, 30.84s Total Time |
...
Attach a link to issue if relevant
What
Specify what you're trying to achieve
Why
Specify why you need to achieve this
Screenshots / Gifs
Attach Screenshots / Gifs to help reviewers understand the scope of the pull request
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes