-
Notifications
You must be signed in to change notification settings - Fork 61
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
fix(native-app): fix document pdf rendering #16449
Conversation
WalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Suggested labels
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: 0
🧹 Outside diff range and nitpick comments (5)
apps/native/app/src/screens/document-detail/document-detail.tsx (5)
318-321
: Improved clarity and logic for showing additional information.The renaming of
showAlert
toshowAdditionalInfo
enhances code readability. The updated condition for showing additional information is more comprehensive, considering multiple factors.Consider extracting the complex condition into a separate function for better readability and maintainability. For example:
const shouldShowAdditionalInfo = () => showConfirmedAlert || (hasAlert && !hasConfirmation) || (hasActions && !showConfirmedAlert && !hasConfirmation); const showAdditionalInfo = shouldShowAdditionalInfo();This approach would make the logic easier to understand and modify in the future.
Line range hint
441-457
: Improved conditional rendering of additional information.The changes align well with the updated
showAdditionalInfo
logic, making the rendering of alerts and action buttons more flexible and conditional.To improve TypeScript usage and prevent potential runtime errors, consider adding type guards or assertions for the
Document.alert
object. For example:{showConfirmedAlert && Document.alert && ( <Alert type="success" hasBorder message={Document.alert.title ?? Document.alert.data ?? undefined} /> )}This approach ensures that
Document.alert
is notundefined
before accessing its properties.
490-507
: Improved PdfViewer rendering and error handling.The changes enhance the rendering logic for the PdfViewer component and improve error handling. The new condition ensures all necessary props are available before rendering, and the
shouldIncludeDocument
check prevents premature loading state changes.Consider adding a timeout for loading the PDF to handle cases where the PDF might fail to load without triggering an error. For example:
useEffect(() => { if (visible && accessToken) { const timer = setTimeout(() => { if (!loaded) { setLoaded(true); setError(true); } }, 30000); // 30 seconds timeout return () => clearTimeout(timer); } }, [visible, accessToken, loaded]);This approach ensures that the user isn't left waiting indefinitely if the PDF fails to load for any reason.
492-493
: Enhanced security for PDF rendering.The use of a data URI for the PDF content and including the document ID and access token in the body improves security by not exposing the document URL and ensuring proper authentication.
To further enhance security, consider encrypting the access token before sending it in the request body. You could implement a simple encryption function:
const encryptToken = (token: string) => { // Implement a reversible encryption algorithm here return encryptedToken; }; // Usage body={`documentId=${Document.id}&__accessToken=${encryptToken(accessToken)}`}This approach adds an extra layer of security to protect the access token during transmission.
494-501
: Improved PDF loading logic and state management.The changes enhance the PDF loading process by setting the
pdfUrl
state for later use and preventing premature loading state changes with theshouldIncludeDocument
check.Consider adding error handling within the
onLoaded
callback to manage potential issues when setting thepdfUrl
. For example:onLoaded={(filePath: string) => { try { setPdfUrl(filePath); if (shouldIncludeDocument) { setLoaded(true); } } catch (error) { console.error('Error setting PDF URL:', error); setError(true); } }}This approach ensures that any unexpected errors during the loading process are caught and handled appropriately.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- apps/native/app/src/screens/document-detail/document-detail.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/native/app/src/screens/document-detail/document-detail.tsx (1)
Pattern
apps/**/*
: "Confirm that the code adheres to the following:
- NextJS best practices, including file structure, API routes, and static generation methods.
- Efficient state management and server-side rendering techniques.
- Optimal use of TypeScript for component and utility type safety."
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #16449 +/- ##
==========================================
- Coverage 36.75% 36.75% -0.01%
==========================================
Files 6835 6835
Lines 141332 141332
Branches 40240 40262 +22
==========================================
- Hits 51949 51947 -2
- Misses 89383 89385 +2 Flags with carried forward coverage won't be shown. Click here to find out more. see 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Datadog ReportAll test runs ✅ 66 Total Test Services: 0 Failed, 64 Passed Test ServicesThis report shows up to 10 services
🔻 Code Coverage Decreases vs Default Branch (3) |
What
I accidentally broke rendering of normal pdfs when implementing subpoena functionality. Fixing that and a few more tiny fixes.
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes
Refactor