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

Add Facility Map Link #10755

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

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Feb 21, 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
    • Facility views now display a clickable map link when valid location coordinates are available.
    • The map link intelligently adapts its behavior based on the user's device.
    • Localization is enhanced with a new “Show on Maps” label for improved language support.
    • A new environment variable for mapping functionality has been introduced.

@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner February 21, 2025 18:33
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Walkthrough

This pull request introduces a new localization entry and a facility map link feature. A new key "show_on_maps": "Show on Maps" is added to the localization file. A utility constant isAndroidDevice is created to detect Android devices. In addition, a new component FacilityMapsLink is implemented to generate hyperlinks based on valid latitude and longitude coordinates. This component is integrated into various parts of the application including facility home, details, and card views, with conditional rendering based on geographical data availability.

Changes

File(s) Change Summary
public/locale/en.json Added new "show_on_maps" key for map display text.
src/Utils/utils.ts Added constant isAndroidDevice to detect Android devices using a regex test on navigator.userAgent.
src/components/Facility/FacilityHome.tsx
src/pages/Facility/FacilityDetailsPage.tsx
src/pages/Facility/components/FacilityCard.tsx
Integrated FacilityMapsLink into facility components for conditional display of map links when coordinates are provided.
src/components/Facility/FacilityMapLink.tsx Introduced new FacilityMapsLink component that validates latitude and longitude and generates map links.
.example.env Added new environment variable REACT_MAP_URL= for mapping functionality.
care.config.ts Added mapUrl property to careConfig to retrieve mapping URL from the environment variable.
src/vite-env.d.ts Added optional property REACT_MAP_URL to ImportMetaEnv interface.

Possibly related PRs

Suggested labels

needs review, needs testing

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a happy rabbit, hopped to the code,
Bringing map links where coordinates are showed.
With new keys and checks, I bound with delight,
Turning data to routes that shine so bright.
A code leap of joy from morning till night! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 Feb 21, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 15495a7
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67ba1308321dd0000858e258
😎 Deploy Preview https://deploy-preview-10755.preview.ohc.network
📱 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: 1

🧹 Nitpick comments (3)
src/components/Facility/FacilityMapLink.tsx (2)

7-15: Consider extracting validation functions to a shared utility file.

The coordinate validation functions could be reused across the application. Consider moving them to a dedicated geolocation utility file.

-const isValidLatitude = (latitude: string) => {
-  const lat = parseFloat(latitude.trim());
-  return Number.isFinite(lat) && lat >= -90 && lat <= 90;
-};
-
-const isValidLongitude = (longitude: string) => {
-  const long = parseFloat(longitude.trim());
-  return Number.isFinite(long) && long >= -180 && long <= 180;
-};

Create a new file src/Utils/geolocation.ts:

export const isValidLatitude = (latitude: string) => {
  const lat = parseFloat(latitude.trim());
  return Number.isFinite(lat) && lat >= -90 && lat <= 90;
};

export const isValidLongitude = (longitude: string) => {
  const long = parseFloat(longitude.trim());
  return Number.isFinite(long) && long >= -180 && long <= 180;
};

17-44:

❓ Verification inconclusive

Consider accessibility improvements for the map link.

The link could benefit from additional accessibility attributes:

       <Link
         className="text-primary flex items-center gap-1 w-max"
         href={href}
         target={target}
         rel="noreferrer"
+        aria-label={`${t("show_on_maps")} for ${t("facility_location")}`}
       >

Also, verify that the link text is properly localized:


🌐 Web query:

What are the WCAG guidelines for opening links in new tabs?

💡 Result:

The Web Content Accessibility Guidelines (WCAG) address link behavior through multiple success criteria, particularly regarding predictability and user control when opening new tabs/windows:

Key WCAG Requirements

  1. Success Criterion 3.2 Predictable
    Requires web pages to operate predictably[1][4]. Unexpected new tabs/windows (without warning) violate this principle by creating unannounced context changes[1][3][9].

  2. Success Criterion 3.2.5 Change on Request (AAA)
    Explicitly prohibits automatic new tabs/windows unless:

    • Users request them via standard browser controls (e.g., right-click > "Open in new tab")
    • A mechanism exists to disable automatic context changes[1][4][9].

Implementation Guidelines

  • Avoid target="_blank" by default: Most links should open in the same tab[3][4][6]. Users can choose to open new tabs via browser controls[3].
  • Required warnings when using new tabs: If you must open a link in a new tab:
    • Add visible icons (e.g., Font Awesome's external link icon)[1][6]
    • Include screen-reader text like <span class="screen-reader-text"> opens new window</span>[1][6]
    • Use ARIA labels for image links:
      <a href="#" target="_blank" aria-label="Example (opens new tab)">
        <img src="image.jpg" alt="Example">
      </a>
      ```[7]

Exceptions Allowing New Tabs

Scenario Example
User progress loss risk Forms with external policy links[1][4]
Required reference material Checklists/instructions needing parallel viewing[4]

Best Practices

  1. Use descriptive link text avoiding "click here" or URLs[2][5][8]
  2. Maintain ≥3:1 contrast between link/non-link text[10]
  3. Implement hover/focus indicators for keyboard users[10]
  4. Automate warnings with plugins like Accessibility New Window Warnings[1]

Non-compliant implementations risk failing WCAG at AA/AAA levels and creating disorientation for screen reader users[1][3][4]. Government sites like accessibility.gov demonstrate compliant implementations with explicit warnings[9].

Citations:


Accessibility Improvement Required: Enhance ARIA Label & Localization

Please update the Link component in src/components/Facility/FacilityMapLink.tsx (lines 17-44) to better notify users—especially screen reader users—when a link will open in a new tab/window. According to WCAG guidelines, links that open automatically in a new context should clearly indicate this behavior to prevent unexpected context changes.

  • Add an ARIA label:
    Include an ARIA label that not only reinforces the localized link text but also provides additional context regarding the facility’s location. For example, consider updating your code as follows:

           <Link
             className="text-primary flex items-center gap-1 w-max"
             href={href}
             target={target}
             rel="noreferrer"
    +        aria-label={`${t("show_on_maps")} for ${t("facility_location")}`}
           >
  • Verify localization:
    Ensure that the translation keys (t("show_on_maps") and t("facility_location")) remain clear and meaningful in all supported languages. Additionally, for users on non-Android devices (where target="_blank" is used), verify that the implicit behavior of opening a new tab is either evident from the link text/icon or further clarified in the ARIA label.

  • WCAG Consideration:
    As the WCAG guidelines recommend warning users about links opening in new contexts, double-check if a visible indicator or additional screen-reader text (e.g., “opens in a new tab”) would further enhance usability.

src/pages/Facility/components/FacilityCard.tsx (1)

40-45: Consider improving the coordinate type handling.

The current implementation requires type conversion from number to string. Consider:

  1. Using string types in the facility model, or
  2. Moving the type conversion to the FacilityMapsLink component
-                  <FacilityMapsLink
-                    latitude={facility.latitude.toString()}
-                    longitude={facility.longitude.toString()}
-                  />
+                  <FacilityMapsLink
+                    latitude={facility.latitude}
+                    longitude={facility.longitude}
+                  />

And update the FacilityMapsLink component to handle number types:

interface Props {
  latitude: string | number;
  longitude: string | number;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 57ad12d and acee643.

📒 Files selected for processing (6)
  • public/locale/en.json (1 hunks)
  • src/Utils/utils.ts (1 hunks)
  • src/components/Facility/FacilityHome.tsx (2 hunks)
  • src/components/Facility/FacilityMapLink.tsx (1 hunks)
  • src/pages/Facility/FacilityDetailsPage.tsx (2 hunks)
  • src/pages/Facility/components/FacilityCard.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (3)
src/pages/Facility/FacilityDetailsPage.tsx (1)

119-124: Apply consistent coordinate type handling.

Similar to the FacilityCard component, consider improving the coordinate type handling here as well.

src/components/Facility/FacilityHome.tsx (1)

38-38: LGTM! Clean implementation of the map link feature.

The changes properly integrate the FacilityMapsLink component with appropriate conditional rendering based on coordinate availability.

Also applies to: 318-325

public/locale/en.json (1)

2012-2012: LGTM! Proper localization key addition.

The new localization entry follows naming conventions and is properly placed in alphabetical order.

Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

LGTM,. minor thing

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)
care.config.ts (1)

58-59: Consider making the default map URL more configurable.

While the implementation is correct, consider the following improvements:

  1. Move the default URL to a constant or configuration file to make it easier to update.
  2. Consider regional variations where Google Maps might not be the preferred or accessible mapping service.

Apply this diff to improve configurability:

+const DEFAULT_MAP_URL = "https://maps.google.com/?q=";
+
 const careConfig = {
   // ... other config
-  mapUrl: env.REACT_MAP_URL || "https://maps.google.com/?q=",
+  mapUrl: env.REACT_MAP_URL || DEFAULT_MAP_URL,
   // ... other config
 } as const;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f0b5c71 and 15495a7.

📒 Files selected for processing (4)
  • .example.env (1 hunks)
  • care.config.ts (1 hunks)
  • src/components/Facility/FacilityMapLink.tsx (1 hunks)
  • src/vite-env.d.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .example.env
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Facility/FacilityMapLink.tsx
🔇 Additional comments (1)
src/vite-env.d.ts (1)

36-37: LGTM!

The new environment variable REACT_MAP_URL follows the established naming convention, has the correct type annotation, and is appropriately marked as optional.

Comment on lines +36 to +37

readonly REACT_MAP_URL?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
readonly REACT_MAP_URL?: string;
readonly REACT_MAPS_FALLBACK_URL_TEMPLATE?: string;

Comment on lines +66 to +67
# Map URL
REACT_MAP_URL=
Copy link
Member

Choose a reason for hiding this comment

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

the purpose of example.env is to provide an example, where's the example value? 🤔

@@ -55,6 +55,8 @@ const careConfig = {
defaultEncounterType: (env.REACT_DEFAULT_ENCOUNTER_TYPE ||
"hh") as EncounterClass,

mapUrl: env.REACT_MAP_URL || "https://maps.google.com/?q=",
Copy link
Member

Choose a reason for hiding this comment

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

let's keep the default in .env instead.

also let's use {lat}, {lng} in the env string which would be replaced by

Suggested change
mapUrl: env.REACT_MAP_URL || "https://maps.google.com/?q=",
mapUrl: (lat, lng) => env.REACT_MAP_URL.replace(...replace lat and lng with args...),

Copy link
Member

@rithviknishad rithviknishad Feb 23, 2025

Choose a reason for hiding this comment

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

or better, just export the map url template in care config and have a common utility function to have this function, let's not keep functions in care config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Add Google Maps link for a facility in its page.
2 participants