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: Resource Letter printing issue #10230

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Jan 28, 2025

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Introduced a new route for printing resource request letters.
    • Added a new component for generating printable resource request letters.
  • Bug Fixes

    • Removed outdated request letter functionality and print mode management.
  • Refactor

    • Updated data fetching logic for resource details to improve performance and consistency.
    • Changed utility function for combining class names in the print preview component.
    • Enhanced print layout by modifying CSS for printed pages.

@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner January 28, 2025 09:09
Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

Walkthrough

The pull request introduces significant changes to the ResourceDetails component by removing the RequestLetter function and its associated rendering logic. It updates the data fetching mechanism to use the useQuery hook from @tanstack/react-query and eliminates the state management for print mode, replacing it with a navigation action to a new print-specific route. Additionally, a new component, PrintResourceLetter, is added to handle the rendering of the printable resource letter.

Changes

File Change Summary
src/components/Resource/ResourceDetails.tsx Removed RequestLetter function and its rendering logic; updated data fetching to useQuery and renamed loading state to isLoading.
src/Routers/routes/ResourceRoutes.tsx Added new route "/resource/:id/print" for PrintResourceLetter component.
src/components/Resource/PrintResourceLetter.tsx Introduced new component for generating printable resource request letters, utilizing useQuery for data fetching.
src/CAREUI/misc/PrintPreview.tsx Updated import from classNames to cn utility for class name management.
src/style/index.css Added new CSS rule @page { margin-top: 0; } for print layout.

Assessment against linked issues

Objective Addressed Explanation
Fix page crash when printing Resource letter [#10191]

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 In the land of code, where rabbits play,
A print route hops in, brightening the day!
The old request is gone, but fear not,
A new letter blooms, with all it’s got!
With queries fetching, and prints in sight,
We celebrate changes, all feels just right! 🌟


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

netlify bot commented Jan 28, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 1479600
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/679a76edf910e600085444b3
😎 Deploy Preview https://deploy-preview-10230--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Nitpick comments (2)
src/components/Resource/ResourceDetails.tsx (2)

106-106: Improve type safety for translation function parameter.

The type annotation (arg0: string) => string for the translation function is oversimplified and doesn't account for i18next's interpolation capabilities.

Consider using the proper i18next types:

-const RequestLetter = (data: ResourceRequest, t: (arg0: string) => string) => {
+import { TFunction } from 'i18next';
+const RequestLetter = (data: ResourceRequest, t: TFunction) => {

384-384: Consider using object destructuring for better maintainability.

Using positional parameters can be error-prone when adding or reordering parameters in the future.

Consider using object destructuring:

-{RequestLetter(data, t)}
+{RequestLetter({ data, t })}

And update the function signature accordingly:

const RequestLetter = ({ data, t }: { data: ResourceRequest; t: TFunction }) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 230b483 and ba863cf.

📒 Files selected for processing (1)
  • src/components/Resource/ResourceDetails.tsx (2 hunks)
🔇 Additional comments (1)
src/components/Resource/ResourceDetails.tsx (1)

Line range hint 106-384: LGTM! The changes effectively address the resource letter printing issue.

The implementation properly integrates translation capabilities into the letter component, ensuring that all static text can be properly translated when printing. The changes maintain consistency with the application's internationalization approach.

@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Jan 28, 2025
Copy link
Contributor

@Jacobjeevan Jacobjeevan left a comment

Choose a reason for hiding this comment

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

This solves the immediate problem, however print doesn't work as intended for request letter (with print preview displaying RequestLetter multiple times).

  • You would need to convert RequestLetter (prob rename to PrintRequestLetter) into its own component and have its content wrapped in PrintPreview
  • add a new /print route that calls this component
  • update Resourcedetails (buttons, state etc)
    • replace useTanStackQueryInstead while you are at it.

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

🧹 Nitpick comments (3)
src/components/Resource/ResourceDetails.tsx (2)

1-1: Great adoption of useQuery!
Switching to the official @tanstack/react-query hook improves maintainability and consistency. However, consider handling potential error states (e.g., network failures) to offer a more robust user experience.

Also applies to: 20-20


107-115: Add error handling logic.
Currently, isLoading is checked, but there is no fallback or notification for errors. Consider passing onError or checking for error from useQuery to gracefully handle failed requests and provide user feedback.

src/components/Resource/PrintResourceLetter.tsx (1)

14-26: Consider handling query errors.
While isLoading || !data is checked, handling potential error would improve resiliency. You can display an error message or route the user back.

+ const { data, isLoading, error } = useQuery(...);
+ if (error) {
+   return <p className="text-red-600">{t("failed_to_load_resource")}</p>;
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e15333b and d011d26.

📒 Files selected for processing (3)
  • src/Routers/routes/ResourceRoutes.tsx (2 hunks)
  • src/components/Resource/PrintResourceLetter.tsx (1 hunks)
  • src/components/Resource/ResourceDetails.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (4)
src/components/Resource/ResourceDetails.tsx (1)

130-130: Navigation approach looks good.
Switching from print mode state to a dedicated print route increases clarity and separation of concerns. Ensure that any downstream users are aware of the new path.

src/Routers/routes/ResourceRoutes.tsx (1)

2-2: Route addition is consistent.
Importing PrintResourceLetter and adding "/resource/:id/print" is a clean design choice. It aligns with best practices for route-based print handling.

Also applies to: 14-14

src/components/Resource/PrintResourceLetter.tsx (2)

1-13: Imports are well-organized.
These imports adequately cover the new component’s requirements, including querying, translation, and utility usage.


27-129: Rendering logic is well-structured.
The content is neatly organized, and i18n usage looks comprehensive. The separated print layout offers clarity and maintainability.

@AdityaJ2305 AdityaJ2305 marked this pull request as draft January 29, 2025 18:46
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

🧹 Nitpick comments (1)
src/style/index.css (1)

434-436: LGTM! Consider standardizing all page margins.

The margin-top: 0 rule will remove unwanted spacing at the top of printed pages. However, for consistency, consider explicitly setting all margin properties.

 @page {
-    margin-top: 0;
+    margin: 0;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f508df5 and 1479600.

📒 Files selected for processing (1)
  • src/style/index.css (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (1)
src/style/index.css (1)

434-436: Verify print layout across browsers.

Different browsers may handle @page margins differently. Please test the print layout in major browsers (Chrome, Firefox, Safari) to ensure consistent results.

@AdityaJ2305 AdityaJ2305 marked this pull request as ready for review January 29, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required Deploy-Failed Deplyment is not showing preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Printing Resource letter crashes the page
2 participants