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

Fixes AppRoutes type #9890

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

Conversation

rithviknishad
Copy link
Member

@rithviknishad rithviknishad commented Jan 10, 2025

Proposed Changes

  • Fixes AppRoutes type

before:

image

after:
image

@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

  • Routing Improvements

    • Refactored routing type definitions
    • Moved AppRoutes type to a centralized location
    • Simplified routing type management
  • Type Changes

    • Updated facilityId type from number to string in multiple components
    • Introduced new helper types for route parameter extraction
  • Code Organization

    • Updated import paths to use absolute imports
    • Removed some unused imports and components
  • Routing Updates

    • Removed home facility redirect functionality in schedule routes

@rithviknishad rithviknishad requested a review from a team as a code owner January 10, 2025 18:00
Copy link

netlify bot commented Jan 10, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit aeaa074
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6781603b5f3bc20008381fc6
😎 Deploy Preview https://deploy-preview-9890--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 bot commented Jan 10, 2025

Walkthrough

This pull request introduces significant changes to the routing system and type definitions across multiple files. The primary modifications include moving AppRoutes type definitions to a new types.ts file, removing type definitions from AppRouter.tsx, and updating import statements in various route files. Additionally, some components have been updated to change facilityId type from number to string. The changes aim to improve type management and consistency in the routing structure while maintaining the existing routing logic.

Changes

File Change Summary
src/Routers/AppRouter.tsx Removed type definitions for RouteParams, RouteFunction, and AppRoutes; added import for AppRoutes from @/Routers/types
src/Routers/routes/*Routes.tsx Updated import of AppRoutes from @/Routers/AppRouter to @/Routers/types
src/Routers/routes/ScheduleRoutes.tsx Removed HomeFacilityRedirect component and related route
src/Routers/types.ts Added new helper types ExtractRouteParams, RouteFunction, and AppRoutes; removed DetailRoute interface
src/components/Facility/FacilityUsers.tsx Changed facilityId prop type from number to string
src/components/Resource/ResourceCreate.tsx Changed facilityId prop type from number to string
src/pluginTypes.ts Updated multiple import statements to use absolute paths

Suggested labels

needs review, changes required

Suggested reviewers

  • bodhish
  • Jacobjeevan

Possibly related PRs

Poem

🐰 Routing rabbits hop and dance,
Types migrate with a swift glance,
From numbers to strings we leap,
Refactoring code in one big sweep,
A coding ballet, precise and neat! 🚀

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

cypress bot commented Jan 10, 2025

CARE    Run #4246

Run Properties:  status check failed Failed #4246  •  git commit aeaa0747f3: Fixes `AppRoutes` type
Project CARE
Branch Review rithviknishad/fix/app-route-type
Run status status check failed Failed #4246
Run duration 02m 19s
Commit git commit aeaa0747f3: Fixes `AppRoutes` type
Committer Rithvik Nishad
View all properties for this run ↗︎

Test results
Tests that failed  Failures 1
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 5
View all changes introduced in this branch ↗︎

Tests for review

Failed  cypress/e2e/facility_spec/facility_creation.cy.ts • 1 failed test

View Output

Test Artifacts
Facility Management > Create a new facility using the admin role Test Replay Screenshots

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 (5)
src/components/Resource/ResourceCreate.tsx (2)

Line range hint 108-108: Remove redundant string conversion.

Since facilityId is now typed as string, the String() conversion is unnecessary.

-        pathParams: { id: String(facilityId) },
+        pathParams: { id: facilityId },

Line range hint 170-170: Remove redundant string conversion.

Similar to above, the String() conversion is unnecessary as facilityId is already a string.

-        origin_facility: String(props.facilityId),
+        origin_facility: props.facilityId,
src/Routers/types.ts (1)

10-17: Well-structured route function and app routes types.

The RouteFunction type correctly leverages the ExtractRouteParams helper to ensure type safety between route patterns and their handler parameters. The AppRoutes type provides a flexible yet type-safe mapping of routes to their handlers.

Consider adding JSDoc comments to document:

  • Examples of valid route patterns
  • The relationship between route patterns and extracted parameters
  • Usage examples for the AppRoutes type
src/Routers/routes/FacilityRoutes.tsx (1)

Line range hint 13-35: Consider organizing routes by feature.

The routes are functionally correct but could benefit from better organization.

Consider grouping related routes using objects:

 const FacilityRoutes: AppRoutes = {
+  // Core facility routes
   "/facility": () => <Redirect to="/" />,
   "/facility/create": () => <FacilityCreate />,
   "/facility/:facilityId/update": ({ facilityId }) => (
     <FacilityCreate facilityId={facilityId} />
   ),
   "/facility/:facilityId": ({ facilityId }) => (
     <FacilityHome facilityId={facilityId} />
   ),
   "/facility/:facilityId/users": ({ facilityId }) => (
     <FacilityUsers facilityId={facilityId} />
   ),
+  // Resource management
   "/facility/:facilityId/resource/new": ({ facilityId }) => (
     <ResourceCreate facilityId={facilityId} />
   ),
+  // Organization management
   "/facility/:facilityId/organization": ({ facilityId }) => (
     <FacilityOrganizationIndex facilityId={facilityId} />
   ),
   "/facility/:facilityId/organization/:id": ({ facilityId, id }) => (
     <FacilityOrganizationView facilityId={facilityId} id={id} />
   ),
   "/facility/:facilityId/organization/:id/users": ({ facilityId, id }) => (
     <FacilityOrganizationUsers facilityId={facilityId} id={id} />
   ),
 };
src/Routers/routes/PatientRoutes.tsx (1)

Line range hint 24-29: Consider improving readability of dynamic route generation.

While the dynamic route generation using reduce is clever, it could be more readable.

Consider using a more explicit approach:

-  ...patientTabs.reduce((acc: AppRoutes, tab) => {
-    acc["/facility/:facilityId/patient/:id/" + tab.route] = ({
-      facilityId,
-      id,
-    }) => <PatientHome facilityId={facilityId} id={id} page={tab.route} />;
-    return acc;
-  }, {}),
+  // Generate routes for each patient tab
+  ...Object.fromEntries(
+    patientTabs.map((tab) => [
+      `/facility/:facilityId/patient/:id/${tab.route}`,
+      ({ facilityId, id }: { facilityId: string; id: string }) => (
+        <PatientHome facilityId={facilityId} id={id} page={tab.route} />
+      ),
+    ])
+  ),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 86eba9b and aeaa074.

📒 Files selected for processing (13)
  • src/Routers/AppRouter.tsx (1 hunks)
  • src/Routers/routes/ConsultationRoutes.tsx (1 hunks)
  • src/Routers/routes/FacilityRoutes.tsx (1 hunks)
  • src/Routers/routes/OrganizationRoutes.tsx (1 hunks)
  • src/Routers/routes/PatientRoutes.tsx (1 hunks)
  • src/Routers/routes/ResourceRoutes.tsx (1 hunks)
  • src/Routers/routes/ScheduleRoutes.tsx (1 hunks)
  • src/Routers/routes/UserRoutes.tsx (1 hunks)
  • src/Routers/routes/questionnaireRoutes.tsx (1 hunks)
  • src/Routers/types.ts (1 hunks)
  • src/components/Facility/FacilityUsers.tsx (1 hunks)
  • src/components/Resource/ResourceCreate.tsx (1 hunks)
  • src/pluginTypes.ts (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • src/Routers/routes/UserRoutes.tsx
  • src/Routers/routes/ResourceRoutes.tsx
  • src/Routers/routes/questionnaireRoutes.tsx
  • src/Routers/routes/OrganizationRoutes.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (9)
src/components/Facility/FacilityUsers.tsx (1)

18-18: LGTM! Type change aligns with REST API best practices.

The change from number to string for facilityId is appropriate as REST API resource identifiers are typically strings.

Let's verify the API endpoint's expected type:

✅ Verification successful

Type change verified - API expects string parameters

The API route /api/v1/facility/{facility_id}/get_users/ uses string-based path parameters, confirming that the type change from number to string is correct and matches the API's expectations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for facility API route definitions and their parameter types
rg -g '*.ts' -g '*.tsx' 'facility_id.*:.*string|facility_id.*:.*number' --no-heading

Length of output: 86


Script:

#!/bin/bash
# Search for API routes and type definitions related to facilities
rg -g '*.ts' -g '*.tsx' -A 2 'getFacility|facility.*api|facilities.*api' --no-heading

# Search for actual API calls with facilityId
ast-grep --pattern 'facilityId: $_'

Length of output: 1197

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

36-36: LGTM! Type change is consistent.

The change from number to string for facilityId maintains consistency with other components.

src/Routers/types.ts (1)

1-8: Excellent implementation of type-safe route parameter extraction!

The ExtractRouteParams type elegantly handles route parameter extraction using conditional types. The implementation correctly handles both middle parameters (:param/) and end parameters (:param), providing precise typing for route parameters.

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

1-1: Routes are properly typed and well-structured.

The schedule routes correctly implement the new AppRoutes type. Each route handler properly uses the extracted parameters with correct typing.

Let's verify that all components accept the correct prop types:

Also applies to: 6-24

✅ Verification successful

Routes are properly typed and implemented correctly

The verification confirms that:

  • AppRoutes type is correctly imported and used
  • Route parameters are properly typed and passed to components
  • Component prop types match the route parameters exactly
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify component prop types match route parameters
ast-grep --pattern 'interface $Props {
  facilityId: string;
  $$$
}

export default function $Component({ facilityId, $$$ }: $Props)' src/pages/Appointments/*.tsx

Length of output: 268


Script:

#!/bin/bash
# First find relevant component files
fd -e tsx -e ts "Appointment" src/

# Then check imports and route usage
rg -l "AppRoutes" src/

# Finally check component props structure
ast-grep --pattern 'function $Component($props) {
  $$$
}'

Length of output: 857


Script:

#!/bin/bash
# Check component props with various syntax patterns
ast-grep --pattern 'type $Props = {
  $$$
}' src/pages/Appointments/*.tsx

# Also check interface syntax
ast-grep --pattern 'interface $Props {
  $$$
}' src/pages/Appointments/*.tsx

# Check route definitions
rg -A 5 "path:" src/Routers/routes/ScheduleRoutes.tsx

Length of output: 414


Script:

#!/bin/bash
# Check actual component implementation
cat src/pages/Appointments/AppointmentsPage.tsx

# Look for route patterns
rg "AppRoutes\." src/Routers/routes/ScheduleRoutes.tsx

Length of output: 35768


Script:

#!/bin/bash
# Check actual routes implementation
cat src/Routers/routes/ScheduleRoutes.tsx

Length of output: 867

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

8-8: Import updated correctly to use new types module.

The AppRoutes import has been properly updated to use the new types file.

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

7-7: Import updated correctly to use new types module.

The AppRoutes import has been properly updated to use the new types file.

src/pluginTypes.ts (1)

4-6: LGTM! Import paths standardization.

The changes standardize import paths using absolute imports and align with the centralization of type definitions.

Also applies to: 9-9, 11-12

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

6-6: LGTM! Updated import path for centralized type definition.

The change aligns with moving AppRoutes type to a dedicated types file.

src/Routers/AppRouter.tsx (1)

22-22: LGTM! Centralized routing types.

The change improves code organization by moving type definitions to a dedicated types file.

Let's verify that all files importing the routing types have been updated:

✅ Verification successful

All routing type imports have been successfully updated

All files previously importing AppRoutes now consistently use the new path @/Routers/types. No remaining references to the old import location were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining imports of AppRoutes from the old location
rg "import.*AppRoutes.*from.*['\"]@/Routers/AppRouter['\"]" --type ts --type tsx

# Search for files using the new import path to ensure consistent adoption
rg "import.*AppRoutes.*from.*['\"]@/Routers/types['\"]" --type ts --type tsx

Length of output: 225


Script:

#!/bin/bash
# Find TypeScript/React files first
echo "TypeScript/React files in the project:"
fd "\.(ts|tsx)$"

# Search for old and new import patterns
echo -e "\nSearching for old import pattern:"
rg "import.*AppRoutes.*from.*['\"]@/Routers/AppRouter['\"]"

echo -e "\nSearching for new import pattern:"
rg "import.*AppRoutes.*from.*['\"]@/Routers/types['\"]" -A 2

Length of output: 20899

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

Successfully merging this pull request may close these issues.

1 participant