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/google maps link #10003

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

Conversation

rahulharpal1603
Copy link

@rahulharpal1603 rahulharpal1603 commented Jan 15, 2025

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Demo Video:

2025-01-16.02-17-42.mp4

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

    • Added a Google Maps link for facilities with latitude and longitude.
    • Enhanced localization support with a new "Show On Maps" label.
    • Introduced a new component for displaying facility location links based on device type.
  • Style

    • Adjusted margin class for geographical organization information.
  • Bug Fixes

    • Improved device detection for Android devices.

@rahulharpal1603 rahulharpal1603 requested a review from a team as a code owner January 15, 2025 20:49
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Walkthrough

The pull request introduces enhancements to the facility pages by adding a Google Maps link feature. It includes a new localization entry for "Show On Maps" and modifies the FacilityHome.tsx component to generate a clickable link using the facility's latitude and longitude. Additionally, a utility function is added to detect Android devices, supporting the link generation logic.

Changes

File Change Summary
public/locale/en.json Added new localization entry "show_on_maps": "Show On Maps"
src/components/Facility/FacilityHome.tsx - Imported FacilityMapsLink
- Conditioned rendering of FacilityMapsLink based on latitude and longitude
- Adjusted margin class from mt-2 to mt-1
- Added console.log for debugging
src/Utils/utils.ts - Added _isAndroidDevice function for Android detection
- Created isAndroidDevice constant
src/components/Facility/FacilityMapsLink.tsx Introduced new component FacilityMapsLink for generating map links based on device type
src/pages/Facility/FacilityDetailsPage.tsx Added import for FacilityMapsLink and conditional rendering based on facility coordinates

Assessment against linked issues

Objective Addressed Explanation
Add Google Maps link for facility page [#10000]

Possibly related PRs

Suggested labels

tested, reviewed

Suggested reviewers

  • rithviknishad

Poem

🐰 A rabbit hops with glee and cheer,
A link to maps is finally here!
With coordinates bright, we’ll find our way,
To every facility, come what may! 🌍
So let’s explore, with joy we’ll roam,
Google Maps, our guiding home! 🗺️


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 15, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 3378e84
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/679ca6457e190000086486c1
😎 Deploy Preview https://deploy-preview-10003--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.

@rahulharpal1603
Copy link
Author

@rithviknishad Kindly review this.

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 (1)
src/types/facility/facility.ts (1)

31-32: Consider using number type for geographical coordinates.

The latitude and longitude properties are currently typed as string, but they represent numerical values. Consider:

  1. Using number type instead of string for better type safety and to avoid unnecessary string-to-number conversions.
  2. Adding validation constraints using JSDoc or custom type guards to ensure valid coordinate ranges:
    • Latitude: -90 to 90
    • Longitude: -180 to 180
-  latitude: string;
-  longitude: string;
+  /** Latitude in decimal degrees, range: -90 to 90 */
+  latitude: number;
+  /** Longitude in decimal degrees, range: -180 to 180 */
+  longitude: 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 3e98ab7 and fa95cbc.

📒 Files selected for processing (8)
  • public/locale/en.json (1 hunks)
  • public/locale/hi.json (1 hunks)
  • public/locale/kn.json (1 hunks)
  • public/locale/ml.json (1 hunks)
  • public/locale/mr.json (1 hunks)
  • public/locale/ta.json (1 hunks)
  • src/components/Facility/FacilityHome.tsx (3 hunks)
  • src/types/facility/facility.ts (1 hunks)
🔇 Additional comments (8)
src/components/Facility/FacilityHome.tsx (2)

287-297: LGTM! Well-implemented Google Maps link.

The implementation:

  • Correctly checks for both latitude and longitude before rendering
  • Uses proper security attributes (target="_blank" with rel="noreferrer")
  • Follows accessibility best practices with proper text and icon

281-281: LGTM! Margin adjustment.

The margin adjustment from mt-2 to mt-1 improves the visual spacing.

public/locale/mr.json (1)

42-42: LGTM! Correct Marathi translation.

The translation "Google नकाशे" is appropriate and consistent with Marathi language conventions.

public/locale/hi.json (1)

395-395: LGTM! Correct Hindi translation.

The translation "Google मैप्स" is appropriate and consistent with Hindi language conventions.

public/locale/kn.json (1)

397-397: Translation looks good!

The Kannada translation "Google ನಕ್ಷೆಗಳು" is accurate and follows proper localization practices.

public/locale/ta.json (1)

396-396: Translation looks good!

The Tamil translation "Google வரைபடங்கள்" is accurate and follows proper localization practices.

public/locale/ml.json (1)

998-998: LGTM! Translation looks good.

The Malayalam translation for "Google Maps" is accurate and consistent with the translations added in other locale files.

public/locale/en.json (1)

1081-1081: LGTM! The translation key follows the established conventions.

The addition of the "google_maps" translation key with value "Google Maps" is consistent with the existing naming patterns and properly handles the capitalization of the proper noun.

src/components/Facility/FacilityHome.tsx Outdated Show resolved Hide resolved
@rajku-dev
Copy link
Contributor

rajku-dev commented Jan 16, 2025

@rahulharpal1603 Do not add translations for all languages except en.json
Refer https://github.com/ohcnetwork/care_fe?tab=readme-ov-file#translations

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 16, 2025
@rahulharpal1603
Copy link
Author

@rahulharpal1603 Do not add translations for all languages except en.json
Refer https://github.com/ohcnetwork/care_fe?tab=readme-ov-file#translations

Thanks, I will fix it

@rithviknishad rithviknishad added needs testing needs review and removed question Further information is requested needs-triage labels Jan 17, 2025
@nihal467
Copy link
Member

LGTM

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.

I could be wrong, but from product perspective, I don't see any use case for adding this here. Authenticated users would definitely be inside the facility itself right?
This would've added value if it was in the public page where patients get to see the facility details.

cc: @bodhish / @gigincg

@rahulharpal1603
Copy link
Author

I could be wrong, but from product perspective, I don't see any use case for adding this here. Authenticated users would definitely be inside the facility itself right? This would've added value if it was in the public page where patients get to see the facility details.

cc: @bodhish / @gigincg

I thought from the perspective of the district admin, where he/she can see details about various facilities. In the facilities page for the admin, many facilities were listed instead of only one.

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 17, 2025
@bodhish
Copy link
Member

bodhish commented Jan 20, 2025

I think it should be part of the public page where users can use the maps to navigate to the location, don't think its required in the internal facility side. (Since we have added it, I maynot mind keeping it)

Also Care is a DPG, lets not hardode https://www.google.com/maps/search/?api, we should show the link only if the url is set on the env. (by default we could keep it enabled)

@rahulharpal1603
Copy link
Author

@rithviknishad I have added the conditional link rendering, based on whether the device is android or not.

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 (1)
src/components/Facility/FacilityHome.tsx (1)

126-148: Consider environment-based configuration for maps URL.

The Google Maps URL should be configurable through environment variables to support different map providers or configurations.

Consider this approach:

+const MAPS_URL = process.env.MAPS_URL || 'https://www.google.com/maps/search/';
+
 const getMapsLink = (latitude: number, longitude: number) => {
   return isAndroidDevice ? (
     <a
       className="text-sm text-primary flex items-center gap-1 w-max"
       href={`geo:0,0?q=${latitude},${longitude}`}
       target="_blank"
       rel="noreferrer"
     >
       {t("show_on_maps")}
       <SquareArrowOutUpRight className="h-3 w-3" />
     </a>
   ) : (
     <a
       className="text-sm text-primary flex items-center gap-1 w-max"
-      href={`https://www.google.com/maps/search/?api=1&query=${latitude},${longitude}`}
+      href={`${MAPS_URL}?api=1&query=${latitude},${longitude}`}
       target="_blank"
       rel="noreferrer"
     >
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dfd83e9 and c0109a7.

📒 Files selected for processing (3)
  • public/locale/en.json (1 hunks)
  • src/Utils/utils.ts (1 hunks)
  • src/components/Facility/FacilityHome.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • public/locale/en.json
🔇 Additional comments (2)
src/components/Facility/FacilityHome.tsx (2)

98-98: Remove debug console.log statement.

Remove the console.log statement used for debugging.

-  console.log(navigator.platform);

336-341: LGTM! Proper null checks for coordinates.

The implementation correctly checks for both latitude and longitude before rendering the maps link.

src/Utils/utils.ts Show resolved Hide resolved
@rithviknishad
Copy link
Member

I think it should be part of the public page where users can use the maps to navigate to the location, don't think its required in the internal facility side. (Since we have added it, I maynot mind keeping it)

#10003 (comment)

Was this done?

@rithviknishad rithviknishad added question Further information is requested and removed needs testing needs review labels Jan 29, 2025
@rahulharpal1603
Copy link
Author

I think it should be part of the public page where users can use the maps to navigate to the location, don't think its required in the internal facility side. (Since we have added it, I maynot mind keeping it)

#10003 (comment)

Was this done?

I will add that today.

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 (1)
src/components/Facility/FacilityHome.tsx (1)

354-359: Add null check for coordinates.

While there's a conditional check for the existence of coordinates, it's good practice to validate that they are valid numbers.

- {facilityData.latitude &&
-  facilityData.longitude &&
+ {typeof facilityData.latitude === 'number' &&
+  typeof facilityData.longitude === 'number' &&
   getMapsLink(
     facilityData.latitude,
     facilityData.longitude,
   )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c0109a7 and 5671e1e.

📒 Files selected for processing (3)
  • public/locale/en.json (1 hunks)
  • src/Utils/utils.ts (1 hunks)
  • src/components/Facility/FacilityHome.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • public/locale/en.json
  • src/Utils/utils.ts
🔇 Additional comments (2)
src/components/Facility/FacilityHome.tsx (2)

9-15: LGTM! Clean import organization.

The imports are well-organized and the new SquareArrowOutUpRight icon is appropriately added to the existing lucide-react imports.


104-104: Remove debug console.log statement.

The console.log statement for navigator.platform appears to be used for debugging and should be removed before merging.

src/components/Facility/FacilityHome.tsx Outdated Show resolved Hide resolved
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5671e1e and c93b037.

📒 Files selected for processing (3)
  • src/components/Facility/FacilityHome.tsx (3 hunks)
  • src/components/Facility/FacilityMapsLink.tsx (1 hunks)
  • src/pages/Facility/FacilityDetailsPage.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Facility/FacilityHome.tsx
🔇 Additional comments (2)
src/components/Facility/FacilityMapsLink.tsx (1)

18-26: LGTM! Accessibility attributes are properly set.

The link implementation follows accessibility best practices with proper attributes for external links.

src/pages/Facility/FacilityDetailsPage.tsx (1)

118-123: LGTM! Proper null checks for coordinates.

The component is correctly rendered only when both latitude and longitude are present.

Comment on lines +14 to +16
const href = isAndroidDevice
? `geo:0,0?q=${latitude},${longitude}`
: `https://maps.google.com/?q=${latitude},${longitude}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider environment-based URL configuration.

Based on PR comments from bodhish, the maps URL should be configurable via environment variables rather than hardcoded.

+import { getConfig } from "@/config";
+
 export const FacilityMapsLink = ({
   latitude,
   longitude,
 }: {
   latitude: number;
   longitude: number;
 }) => {
   const { t } = useTranslation();
+  const mapsUrl = getConfig("MAPS_URL");
+  if (!mapsUrl) return null;
+
   const href = isAndroidDevice
-    ? `geo:0,0?q=${latitude},${longitude}`
-    : `https://maps.google.com/?q=${latitude},${longitude}`;
+    ? `geo:0,0?q=${latitude},${longitude}`
+    : `${mapsUrl}?q=${latitude},${longitude}`;

Committable suggestion skipped: line range outside the PR's diff.

src/components/Facility/FacilityMapsLink.tsx Outdated Show resolved Hide resolved
@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Jan 31, 2025
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c93b037 and 88e05ae.

📒 Files selected for processing (1)
  • src/components/Facility/FacilityMapsLink.tsx (1 hunks)
🔇 Additional comments (3)
src/components/Facility/FacilityMapsLink.tsx (3)

1-4: LGTM!

The imports are well-organized and follow project conventions.


20-22: Make maps URL configurable via environment.

The hardcoded Google Maps URL should be configurable via environment variables.

Based on the PR comments discussion about device compatibility:

  1. Consider adding a fallback mechanism for Android devices where the geo URI scheme isn't supported.
  2. Add error tracking to monitor if users encounter issues with the geo URI scheme.

23-33: LGTM!

The component follows accessibility best practices with:

  • Appropriate security attributes for external links (rel="noreferrer")
  • Clear visual indication of external link (icon)
  • Internationalization support

src/components/Facility/FacilityMapsLink.tsx Outdated Show resolved Hide resolved
@rahulharpal1603
Copy link
Author

@rithviknishad I have added the maps link to the public pages also. Please review.

@bodhish bodhish added needs testing needs review and removed question Further information is requested Deploy-Failed Deplyment is not showing preview labels Jan 31, 2025
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 (1)
src/components/Facility/FacilityMapsLink.tsx (1)

30-31: Enhance link accessibility and security.

The link's accessibility and security can be improved:

  1. Add an aria-label for screen readers
  2. Add descriptive text for external link behavior
  3. Simplify the target logic
 const target = isAndroidDevice ? "_self" : "_blank";
 return (
   <a
     className="text-sm text-primary flex items-center gap-1 w-max"
     href={href}
     target={target}
     rel="noreferrer"
+    aria-label={`Show location at coordinates ${latitude},${longitude} on map`}
+    {...(!isAndroidDevice && {
+      'aria-description': 'Opens in a new tab'
+    })}
   >

Also applies to: 32-37

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c019c1 and 3378e84.

📒 Files selected for processing (1)
  • src/components/Facility/FacilityMapsLink.tsx (1 hunks)
🔇 Additional comments (1)
src/components/Facility/FacilityMapsLink.tsx (1)

27-29: Configure maps URL via environment variables.

The hardcoded Google Maps URL should be configurable.

Comment on lines +7 to +16
const useValidateCoordinates = (latitude: number, longitude: number) => {
useEffect(() => {
if (latitude < -90 || latitude > 90) {
console.error("Invalid latitude. Must be between -90 and 90 degrees.");
}
if (longitude < -180 || longitude > 180) {
console.error("Invalid longitude. Must be between -180 and 180 degrees.");
}
}, [latitude, longitude]);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance coordinate validation.

The current validation approach using console.error in a hook has several limitations:

  1. Console messages aren't suitable for production environments
  2. Validation doesn't prevent invalid coordinates from being used
  3. Validation logic isn't reusable outside React components

Consider this alternative approach:

// utils/coordinates.ts
export class InvalidCoordinateError extends Error {
  constructor(message: string) {
    super(message);
    this.name = 'InvalidCoordinateError';
  }
}

export const validateCoordinates = (latitude: number, longitude: number) => {
  if (latitude < -90 || latitude > 90) {
    throw new InvalidCoordinateError("Invalid latitude. Must be between -90 and 90 degrees.");
  }
  if (longitude < -180 || longitude > 180) {
    throw new InvalidCoordinateError("Invalid longitude. Must be between -180 and 180 degrees.");
  }
  return { latitude, longitude };
};

// FacilityMapsLink.tsx
const useValidateCoordinates = (latitude: number, longitude: number) => {
  useEffect(() => {
    try {
      validateCoordinates(latitude, longitude);
    } catch (error) {
      // Log to error monitoring service
      console.error(error);
    }
  }, [latitude, longitude]);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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