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

feat(native-app): add locale to vaccinations query #16813

Merged
merged 6 commits into from
Nov 12, 2024

Conversation

thoreyjona
Copy link
Contributor

@thoreyjona thoreyjona commented Nov 12, 2024

What

  • Add locale to vaccinations query.
  • Make sure to show vaccine name even if there is no url
  • Move some thing into variables in health-overview to make code cleaner

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

Release Notes

  • New Features

    • Added new GraphQL queries for health insurance overview, medicine data, health center registration, and payment overview.
    • Enhanced vaccination data retrieval by supporting localization.
  • Improvements

    • Refactored data access in the Health Overview component for better readability.
    • Improved rendering logic in the Vaccinations Card to ensure names are displayed regardless of URL presence.
    • Integrated locale-based querying in the Vaccinations Screen for tailored data retrieval.

These updates enhance the overall user experience by providing more relevant and accessible health-related information.

@thoreyjona thoreyjona requested a review from a team as a code owner November 12, 2024 10:26
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

This pull request introduces several new GraphQL queries related to health data, including GetHealthInsuranceOverview, GetMedicineData, GetHealthCenter, and GetPaymentOverview. It also updates the existing GetVaccinations query to accept a new locale argument for localization. In the frontend, the HealthOverviewScreen component is refactored to improve data access, while the VaccinationsCard component is adjusted for layout and rendering logic. The VaccinationsScreen component is modified to utilize the new locale-based querying for vaccinations.

Changes

File Path Change Summary
apps/native/app/src/graphql/queries/health.graphql Added queries: GetHealthInsuranceOverview, GetMedicineData, GetHealthCenter, GetPaymentOverview. Updated GetVaccinations to accept $locale: String.
apps/native/app/src/screens/health/health-overview.tsx Refactored data access in HealthOverviewScreen to improve readability with new variables.
apps/native/app/src/screens/vaccinations/components/vaccination-card.tsx Increased max width of Cell components and modified rendering logic for vaccination names.
apps/native/app/src/screens/vaccinations/vaccinations.tsx Added useLocale hook and updated useGetVaccinationsQuery to include locale as a parameter.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • thorkellmani

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: 1

🧹 Outside diff range and nitpick comments (4)
apps/native/app/src/screens/vaccinations/vaccinations.tsx (1)

57-59: Consider adding locale-specific error handling

The locale integration looks good and aligns with the PR objectives. However, consider these improvements:

  1. Add error handling for cases where locale is undefined
  2. Consider handling loading states during locale changes
  const locale = useLocale()
+ // Ensure we have a valid locale, fallback to default if needed
+ const safeLocale = locale || 'is'
 
- const vaccinationsRes = useGetVaccinationsQuery({ variables: { locale } })
+ const vaccinationsRes = useGetVaccinationsQuery({ 
+   variables: { locale: safeLocale },
+   // Optionally add loading state handling for locale changes
+   notifyOnNetworkStatusChange: true 
+ })
apps/native/app/src/screens/health/health-overview.tsx (3)

Line range hint 292-321: Consider simplifying the date formatting logic

While the code is functionally correct, the nested ternary operation for date formatting could be more readable.

Consider extracting the date formatting logic:

-value={
-  healthInsuranceData?.from
-    ? intl.formatDate(healthInsuranceData.from)
-    : null
-}
+value={formatInsuranceDate(healthInsuranceData?.from, intl)}

+// Add this helper function
+const formatInsuranceDate = (date: string | null | undefined, intl: IntlShape) => {
+  return date ? intl.formatDate(date) : null
+}

Line range hint 342-365: Extract repeated currency formatting logic

The currency formatting pattern is repeated across multiple inputs. Consider extracting this logic to reduce duplication.

Consider creating a helper function:

+const formatCurrency = (amount: number | null | undefined, intl: IntlShape) => {
+  return amount ? `${intl.formatNumber(amount)} kr.` : '0 kr.'
+}

-value={
-  paymentStatusData?.maximumMonthlyPayment
-    ? `${intl.formatNumber(
-        paymentStatusData?.maximumMonthlyPayment,
-      )} kr.`
-    : '0 kr.'
-}
+value={formatCurrency(paymentStatusData?.maximumMonthlyPayment, intl)}

Line range hint 1-456: Consider breaking down this component for better maintainability

The component currently handles multiple concerns (health insurance, payments, medicine purchases). Consider splitting it into smaller, focused components:

  • HealthInsuranceSection
  • PaymentStatusSection
  • MedicinePurchaseSection

This would improve:

  • Code organization
  • Reusability
  • Testing
  • Maintenance
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between df859d4 and d27d85b.

📒 Files selected for processing (4)
  • apps/native/app/src/graphql/queries/health.graphql (1 hunks)
  • apps/native/app/src/screens/health/health-overview.tsx (8 hunks)
  • apps/native/app/src/screens/vaccinations/components/vaccination-card.tsx (3 hunks)
  • apps/native/app/src/screens/vaccinations/vaccinations.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
apps/native/app/src/graphql/queries/health.graphql (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."
apps/native/app/src/screens/health/health-overview.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."
apps/native/app/src/screens/vaccinations/components/vaccination-card.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."
apps/native/app/src/screens/vaccinations/vaccinations.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."
🔇 Additional comments (7)
apps/native/app/src/graphql/queries/health.graphql (2)

Line range hint 1-52: Well-structured and properly typed GraphQL queries!

The new queries are well-organized, properly typed, and follow GraphQL best practices. Each query serves a specific purpose and includes all necessary fields for comprehensive health data retrieval.


53-54: Locale parameter implementation looks good!

The addition of the locale parameter is clean and properly typed. This change aligns with the PR objective to support localized vaccination names.

Let's verify the locale handling in the schema:

✅ Verification successful

Locale parameter implementation is consistent with the codebase patterns

The verification shows that:

  • The locale parameter is widely used across multiple GraphQL queries in the codebase
  • Other health-related queries like healthDirectorateOrganDonation also use the same locale pattern
  • The implementation follows the established pattern of accepting locale: $locale as a parameter
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the GraphQL schema properly defines the locale parameter
# and that the healthDirectorateVaccinations field accepts it

# Search for the type definition of healthDirectorateVaccinations
ast-grep --pattern 'type Query {
  $$$
  healthDirectorateVaccinations($$$): $$$
  $$$
}'

# Search for any existing locale-aware queries for consistency
rg 'locale: \$locale' -A 2

Length of output: 8933

apps/native/app/src/screens/vaccinations/vaccinations.tsx (2)

17-17: LGTM: Clean import addition

The useLocale hook import follows the established import pattern and is correctly placed with other hook imports.


59-59: Verify vaccine name display implementation

The PR objectives mention ensuring vaccine names display without URLs, but this implementation isn't visible in the current changes. Let's verify the handling in related components.

✅ Verification successful

Vaccine name display implementation is correct

The implementation correctly handles vaccine names both with and without URLs:

  • When a URL is present, it's displayed as a clickable link with an external link icon
  • When no URL is present, it's displayed as plain text using Typography component
  • The name is always shown without the URL being visible to the user

This matches the PR objective of ensuring proper vaccine name display.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for vaccine name rendering logic in related components
echo "Searching for VaccinationsCard component implementation..."
rg -t tsx "VaccinationsCard" ./apps/native/app/src/screens/vaccinations/

Length of output: 227


Script:

#!/bin/bash
# Search for vaccine name rendering logic in related components with correct file extension
echo "Searching for VaccinationsCard component and name rendering..."
rg "VaccinationsCard" ./apps/native/app/src/screens/vaccinations/
rg "vaccine.*name|name.*vaccine" ./apps/native/app/src/screens/vaccinations/

Length of output: 612


Script:

#!/bin/bash
# Let's examine the vaccination-card component implementation
echo "Checking vaccination-card component implementation..."
cat ./apps/native/app/src/screens/vaccinations/components/vaccination-card.tsx

# Also check the query structure to see how vaccine names are handled
echo -e "\nChecking vaccination query structure..."
rg -A 5 "useGetVaccinationsQuery|query GetVaccinations" ./apps/native/app/src/

Length of output: 11457

apps/native/app/src/screens/vaccinations/components/vaccination-card.tsx (1)

173-173: Verify the layout changes and document the rationale.

The maxWidth increase from 20% to 21% for date columns seems arbitrary. Please verify that:

  1. This change doesn't cause text overflow or alignment issues with different date formats and screen sizes
  2. The specific value of 21% is necessary and optimal

Also applies to: 244-244

✅ Verification successful

The width adjustment is part of a consistent table layout design

The change from 20% to 21% for the date column is justified as it's part of a well-structured table layout where columns have specific width allocations:

  • Number column: 6% width
  • Date column: 21% width
  • Age column: 25% width

The remaining space (48%) appears to be allocated for the vaccine name column, creating a balanced table layout. The slight increase to 21% for dates ensures proper spacing for formatted dates while maintaining overall table proportions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other width-related changes or discussions
rg -A 2 "maxWidth.*21%" 
rg -A 2 "maxWidth.*20%"

Length of output: 814


Script:

#!/bin/bash
# Search for similar Cell components with width constraints to understand the layout pattern
rg -A 5 "<Cell.*style.*maxWidth"

# Search for the entire table structure to understand the column distribution
ast-grep --pattern 'const VaccinationCard = $_ => {
  $$$
  return (
    $$$
    <Table>
      $$$
    </Table>
    $$$
  )
}'

Length of output: 2246

apps/native/app/src/screens/health/health-overview.tsx (2)

122-127: Well-structured data access refactoring!

The introduction of these variables improves code readability and maintains proper TypeScript type inference from GraphQL queries. This refactoring aligns with React best practices for organizing data access patterns.


Line range hint 376-394: Apply the currency formatting helper here as well

This section would also benefit from the suggested currency formatting helper function to maintain consistency and reduce code duplication.

Copy link
Contributor

@snaerseljan snaerseljan left a comment

Choose a reason for hiding this comment

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

Nice work.

@thoreyjona thoreyjona added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 12, 2024
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 (1)
apps/native/app/src/ui/lib/card/expandable-card.tsx (1)

66-70: LGTM: Well-structured styled component

The new Message component effectively encapsulates layout properties and spacing, following React Native best practices for component composition.

Consider adding a type annotation for better TypeScript safety:

-const Message = styled(Typography)`
+const Message = styled(Typography)<{ variant: string }>`
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d27d85b and 9cafb0f.

📒 Files selected for processing (2)
  • apps/native/app/src/screens/vaccinations/vaccinations.tsx (4 hunks)
  • apps/native/app/src/ui/lib/card/expandable-card.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/native/app/src/screens/vaccinations/vaccinations.tsx
🧰 Additional context used
📓 Path-based instructions (1)
apps/native/app/src/ui/lib/card/expandable-card.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."
🔇 Additional comments (2)
apps/native/app/src/ui/lib/card/expandable-card.tsx (2)

57-57: LGTM: Improved layout flexibility

The addition of flex: 1 ensures the IconMessage container properly expands to fill available space, which is a good practice in flex layouts.


192-192: LGTM: Consistent component usage

The replacement of Typography with the new Message component maintains the heading5 variant while benefiting from the improved layout properties.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.44%. Comparing base (c4b4548) to head (139b2ba).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16813   +/-   ##
=======================================
  Coverage   36.44%   36.44%           
=======================================
  Files        6853     6853           
  Lines      143479   143479           
  Branches    40949    40949           
=======================================
+ Hits        52285    52287    +2     
+ Misses      91194    91192    -2     
Flag Coverage Δ
air-discount-scheme-backend 54.06% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.34% <ø> (ø)
api-catalogue-services 77.85% <ø> (ø)
api-domains-air-discount-scheme 37.02% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.60% <ø> (ø)
api-domains-criminal-record 47.48% <ø> (ø)
api-domains-driving-license 44.47% <ø> (ø)
api-domains-education 30.55% <ø> (ø)
api-domains-health-insurance 34.33% <ø> (ø)
api-domains-mortgage-certificate 34.68% <ø> (ø)
api-domains-payment-schedule 41.25% <ø> (ø)
application-api-files 62.45% <ø> (ø)
application-core 70.11% <ø> (-0.64%) ⬇️
application-system-api 40.97% <ø> (ø)
application-template-api-modules 27.64% <ø> (ø)
application-templates-accident-notification 28.98% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.87% <ø> (ø)
application-templates-driving-license 18.26% <ø> (ø)
application-templates-estate 12.15% <ø> (ø)
application-templates-example-payment 24.80% <ø> (ø)
application-templates-financial-aid 15.48% <ø> (ø)
application-templates-general-petition 23.07% <ø> (ø)
application-templates-inheritance-report 6.52% <ø> (ø)
application-templates-marriage-conditions 15.04% <ø> (ø)
application-templates-mortgage-certificate 43.22% <ø> (ø)
application-templates-parental-leave 29.71% <ø> (ø)
application-types 6.60% <ø> (ø)
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.82% <ø> (ø)
auth-admin-web 2.43% <ø> (ø)
auth-nest-tools 30.20% <ø> (ø)
auth-react 21.84% <ø> (ø)
auth-shared 75.00% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.20% <ø> (ø)
clients-driving-license-book 43.44% <ø> (ø)
clients-financial-statements-inao 48.98% <ø> (ø)
clients-license-client 1.26% <ø> (ø)
clients-middlewares 73.14% <ø> (ø)
clients-regulations 42.27% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-rsk-personal-tax-return 38.00% <ø> (ø)
clients-smartsolutions 12.77% <ø> (ø)
clients-syslumenn 49.19% <ø> (ø)
clients-zendesk 50.37% <ø> (ø)
cms 0.42% <ø> (ø)
cms-translations 38.89% <ø> (ø)
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.14% <ø> (ø)
contentful-apps 4.69% <ø> (ø)
dokobit-signing 62.58% <ø> (ø)
download-service 44.24% <ø> (ø)
email-service 60.41% <ø> (ø)
feature-flags 90.47% <ø> (ø)
file-storage 45.86% <ø> (ø)
financial-aid-backend 51.26% <ø> (ø)
financial-aid-shared 17.81% <ø> (ø)
icelandic-names-registry-backend 54.34% <ø> (ø)
infra-nest-server 48.37% <ø> (ø)
infra-tracing 43.24% <ø> (ø)
island-ui-core 28.86% <ø> (ø)
judicial-system-api 19.62% <ø> (ø)
judicial-system-audit-trail 68.70% <ø> (ø)
judicial-system-backend 55.18% <ø> (ø)
judicial-system-formatters 79.13% <ø> (ø)
judicial-system-message 66.86% <ø> (ø)
judicial-system-message-handler 47.81% <ø> (ø)
judicial-system-scheduler 70.47% <ø> (ø)
judicial-system-types 43.99% <ø> (ø)
judicial-system-web 27.51% <ø> (ø)
license-api 42.50% <ø> (-0.08%) ⬇️
localization 10.15% <ø> (ø)
logging 48.43% <ø> (ø)
message-queue 67.80% <ø> (ø)
nest-audit 68.20% <ø> (ø)
nest-aws 54.03% <ø> (ø)
nest-core 43.54% <ø> (ø)
nest-feature-flags 50.96% <ø> (ø)
nest-problem 45.82% <ø> (ø)
nest-sequelize 94.44% <ø> (ø)
nest-swagger 51.71% <ø> (ø)
nova-sms 61.90% <ø> (ø)
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 15.89% <ø> (ø)
reference-backend 49.74% <ø> (ø)
regulations 16.78% <ø> (ø)
residence-history 85.00% <ø> (ø)
services-auth-admin-api 52.47% <ø> (ø)
services-auth-delegation-api 58.19% <ø> (ø)
services-auth-ids-api 52.08% <ø> (+0.01%) ⬆️
services-auth-personal-representative 45.59% <ø> (+0.02%) ⬆️
services-auth-personal-representative-public 41.72% <ø> (-0.04%) ⬇️
services-auth-public-api 49.56% <ø> (ø)
services-documents 60.81% <ø> (ø)
services-endorsements-api 53.34% <ø> (ø)
services-sessions 65.35% <ø> (-0.05%) ⬇️
services-university-gateway 49.34% <ø> (+0.02%) ⬆️
services-user-notification 46.85% <ø> (ø)
services-user-profile 61.84% <ø> (ø)
shared-components 26.88% <ø> (ø)
shared-form-fields 31.24% <ø> (ø)
shared-mocking 60.89% <ø> (ø)
shared-pii 92.85% <ø> (ø)
shared-problem 87.50% <ø> (ø)
shared-utils 27.69% <ø> (ø)
skilavottord-ws 24.14% <ø> (ø)
testing-e2e 66.66% <ø> (ø)
web 1.80% <ø> (ø)

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 c4b4548...139b2ba. Read the comment docs.

@kodiakhq kodiakhq bot merged commit fae12b4 into main Nov 12, 2024
261 checks passed
@kodiakhq kodiakhq bot deleted the feat/app-add-locale-vaccinations branch November 12, 2024 17:44
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* feat: add locale to vaccination query

* Fix: show vaccination name even if there is no url

* feat: move data into variables for health

* feat: wrap vaccination in two lines if no space

* fix: make sure loading is shown for vaccinations

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants