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

fix(native-app): fix document pdf rendering #16449

Merged
merged 3 commits into from
Oct 18, 2024
Merged

Conversation

thoreyjona
Copy link
Contributor

@thoreyjona thoreyjona commented Oct 17, 2024

What

I accidentally broke rendering of normal pdfs when implementing subpoena functionality. Fixing that and a few more tiny fixes.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Enhanced logic for displaying alerts and action buttons in the Document Detail screen.
    • Improved rendering conditions for the PDF viewer, ensuring it displays only when all necessary criteria are met.
  • Bug Fixes

    • Updated error handling in the PDF viewer for better state management.
  • Refactor

    • Streamlined conditions for rendering UI elements related to document state management.

@thoreyjona thoreyjona requested a review from a team as a code owner October 17, 2024 12:53
Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The pull request introduces modifications to the DocumentDetailScreen component in the document-detail.tsx file. Key changes include renaming the showAlert variable to showAdditionalInfo, altering the conditions for rendering alerts and action buttons, and refining the PdfViewer component's rendering logic. The error handling for the PdfViewer has been updated, and the useEffect hooks have been adjusted to manage document states more effectively. Overall, these changes streamline the logic for UI elements and enhance document state management.

Changes

File Change Summary
apps/native/app/src/screens/document-detail/document-detail.tsx - Renamed showAlert to showAdditionalInfo.
- Adjusted rendering conditions for alerts and actions.
- Refined PdfViewer rendering logic.
- Updated error handling in PdfViewer.
- Modified useEffect hooks for document state management.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • snaerseljan
  • disaerna

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 to showAdditionalInfo 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 not undefined 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 the shouldIncludeDocument check.

Consider adding error handling within the onLoaded callback to manage potential issues when setting the pdfUrl. 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

📥 Commits

Files that changed from the base of the PR and between 17e1369 and bb1227c.

📒 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."

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.75%. Comparing base (de4f7a0) to head (5315d15).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
air-discount-scheme-backend 54.08% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.37% <ø> (ø)
api-domains-air-discount-scheme 36.93% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.90% <ø> (ø)
api-domains-criminal-record 48.00% <ø> (ø)
api-domains-driving-license 44.43% <ø> (ø)
api-domains-education 31.58% <ø> (ø)
api-domains-health-insurance 34.77% <ø> (ø)
api-domains-mortgage-certificate 34.95% <ø> (ø)
api-domains-payment-schedule 41.16% <ø> (ø)
application-api-files 56.86% <ø> (ø)
application-core 71.64% <ø> (+0.40%) ⬆️
application-system-api 41.37% <ø> (ø)
application-template-api-modules 27.83% <ø> (-0.02%) ⬇️
application-templates-accident-notification 29.27% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.34% <ø> (ø)
application-templates-driving-license 18.32% <ø> (ø)
application-templates-estate 12.32% <ø> (ø)
application-templates-example-payment 25.14% <ø> (ø)
application-templates-financial-aid 15.50% <ø> (ø)
application-templates-general-petition 23.44% <ø> (ø)
application-templates-inheritance-report 6.49% <ø> (ø)
application-templates-marriage-conditions 15.17% <ø> (ø)
application-templates-mortgage-certificate 43.82% <ø> (ø)
application-templates-parental-leave 29.96% <ø> (ø)
application-types 6.63% <ø> (ø)
application-ui-components 1.28% <ø> (ø)
application-ui-shell 21.37% <ø> (ø)
auth-react 22.77% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.67% <ø> (ø)
clients-driving-license-book 43.80% <ø> (ø)
clients-financial-statements-inao 49.32% <ø> (ø)
clients-license-client 1.83% <ø> (ø)
clients-middlewares 72.84% <ø> (ø)
clients-regulations 42.80% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-syslumenn 49.44% <ø> (ø)
cms 0.42% <ø> (ø)
cms-translations 39.03% <ø> (ø)
contentful-apps 5.44% <ø> (ø)
download-service 44.22% <ø> (ø)
financial-aid-backend 56.37% <ø> (ø)
financial-aid-shared 18.94% <ø> (ø)
island-ui-core 28.39% <ø> (ø)
judicial-system-api 18.36% <ø> (ø)
judicial-system-backend 55.15% <ø> (ø)
judicial-system-web 27.91% <ø> (ø)
license-api 42.75% <ø> (+0.05%) ⬆️
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 16.15% <ø> (ø)
services-auth-admin-api 51.93% <ø> (ø)
services-auth-delegation-api 57.30% <ø> (-0.07%) ⬇️
services-auth-ids-api 51.40% <ø> (-0.02%) ⬇️
services-auth-personal-representative 45.10% <ø> (-0.04%) ⬇️
services-auth-personal-representative-public 41.23% <ø> (-0.03%) ⬇️
services-auth-public-api 48.90% <ø> (ø)
services-endorsements-api 53.66% <ø> (ø)
services-university-gateway 48.28% <ø> (-0.09%) ⬇️
services-user-notification 47.02% <ø> (+0.02%) ⬆️
services-user-profile 62.12% <ø> (+0.09%) ⬆️
shared-components 27.65% <ø> (ø)
shared-form-fields 31.59% <ø> (ø)
shared-utils 27.69% <ø> (ø)
web 1.82% <ø> (ø)

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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de4f7a0...5315d15. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 17, 2024

Datadog Report

All test runs 867b811 🔗

66 Total Test Services: 0 Failed, 64 Passed
🔻 Test Sessions change in coverage: 3 decreased, 2 increased, 195 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-backend 0 0 0 81 0 30.37s N/A Link
air-discount-scheme-web 0 0 0 2 0 8.08s N/A Link
api 0 0 0 4 0 2.63s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 17.45s N/A Link
api-domains-assets 0 0 0 3 0 11.36s N/A Link
api-domains-auth-admin 0 0 0 18 0 13.2s N/A Link
api-domains-communications 0 0 0 5 0 30.54s N/A Link
api-domains-criminal-record 0 0 0 5 0 9.28s 1 no change Link
api-domains-driving-license 0 0 0 23 0 28.7s N/A Link
api-domains-education 0 0 0 8 0 19.66s N/A Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • services-auth-delegation-api - jest 51.22% (-0.19%) - Details
  • services-university-gateway - jest 44.84% (-0.02%) - Details
  • services-auth-ids-api - jest 45.01% (-0.01%) - Details

@thoreyjona thoreyjona added the automerge Merge this PR as soon as all checks pass label Oct 18, 2024
@kodiakhq kodiakhq bot merged commit 35f35e8 into main Oct 18, 2024
201 checks passed
@kodiakhq kodiakhq bot deleted the fix/document-pdf-rendering branch October 18, 2024 10:42
@coderabbitai coderabbitai bot mentioned this pull request Dec 5, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants