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: add lunalink and enjoy route inference #561

Merged
merged 1 commit into from
Mar 4, 2025

Conversation

yoannfleurydev
Copy link
Member

@yoannfleurydev yoannfleurydev commented Mar 2, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced the app’s navigation by introducing an updated link-generation mechanism. Users will now enjoy uniform and predictable links across account, admin, repository, and user interfaces.
  • Refactor

    • Streamlined routing configurations to improve reliability and clarity of the navigation experience.
  • Chores

    • Integrated an external utility to support advanced link construction and lay the groundwork for future improvements.

Copy link

vercel bot commented Mar 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
start-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 2, 2025 3:20pm

Copy link
Contributor

coderabbitai bot commented Mar 2, 2025

Warning

Rate limit exceeded

@yoannfleurydev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 52 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7b10ba5 and d795c18.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • package.json (1 hunks)
  • src/features/account/routes.ts (1 hunks)
  • src/features/admin/routes.ts (1 hunks)
  • src/features/app/routes.ts (1 hunks)
  • src/features/management/routes.ts (1 hunks)
  • src/features/repositories/AdminRepositoryActions.tsx (2 hunks)
  • src/features/repositories/PageAdminRepositories.tsx (2 hunks)
  • src/features/repositories/PageAdminRepository.tsx (2 hunks)
  • src/features/repositories/routes.ts (1 hunks)
  • src/features/users/AdminUserActions.tsx (2 hunks)
  • src/features/users/PageAdminUsers.tsx (2 hunks)
  • src/features/users/routes.ts (1 hunks)

Walkthrough

The pull request adds the dependency @bearstudio/lunalink (v0.1.2) and modifies several route definition files to enforce stricter type safety through explicit as const assertions. Additionally, multiple UI components across repository and user features have been updated to generate URLs using the new lunalink function instead of calling route functions directly. TypeScript error suppression comments were also added in some cases to accommodate the new type comparisons.

Changes

Files Change Summary
package.json Added dependency @bearstudio/lunalink version 0.1.2.
src/features/*/routes.ts (account, admin, app, management, repositories, users) Updated route definitions with explicit as const assertions; modified method signatures, parameter handling, and comparisons with added TS error suppression comments where needed.
src/features/(repositories: AdminRepositoryActions.tsx, PageAdminRepositories.tsx, PageAdminRepository.tsx; users: AdminUserActions.tsx, PageAdminUsers.tsx) Replaced direct route function calls with the lunalink function for URL generation and updated corresponding import statements.

Sequence Diagram(s)

sequenceDiagram
    participant UI as UI Component
    participant LL as lunalink
    participant RT as Routes Definition

    UI->>LL: Invoke lunalink(route(), params)
    LL->>RT: Retrieve URL from route definition (using const assertion)
    RT-->>LL: Return constant URL
    LL-->>UI: Return processed URL
Loading

Suggested reviewers

  • ivan-dalmet
  • DecampsRenan

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.
  • @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
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 df83be7 and d10fc4a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • package.json (1 hunks)
  • src/features/account/routes.ts (1 hunks)
  • src/features/admin/routes.ts (1 hunks)
  • src/features/app/routes.ts (1 hunks)
  • src/features/management/routes.ts (1 hunks)
  • src/features/repositories/AdminRepositoryActions.tsx (2 hunks)
  • src/features/repositories/PageAdminRepositories.tsx (2 hunks)
  • src/features/repositories/PageAdminRepository.tsx (2 hunks)
  • src/features/repositories/routes.ts (1 hunks)
  • src/features/users/AdminUserActions.tsx (2 hunks)
  • src/features/users/PageAdminUsers.tsx (2 hunks)
  • src/features/users/routes.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/features/management/routes.ts
🔇 Additional comments (22)
package.json (1)

45-45: Adding lunalink for type-safe route generation.

The addition of @bearstudio/lunalink will help enforce type safety in route generation across the application, ensuring parameters needed for routes are properly provided.

src/features/users/PageAdminUsers.tsx (2)

3-3: Good addition of the lunalink import.

This aligns with the PR objectives to enhance route inference capabilities.


131-133: Enhanced route typing with lunalink.

The change from direct route function calls to the lunalink pattern improves type safety. Now the route definition and parameters are clearly separated, allowing better static analysis and preventing parameter-related errors.

src/features/repositories/PageAdminRepositories.tsx (2)

3-3: Consistent use of lunalink import.

Good job maintaining consistency in the import pattern across different files.


109-111: Better type safety for repository route generation.

Converting to the lunalink function follows the same pattern as in the users module, creating a consistent approach to route parameter handling throughout the application.

src/features/users/AdminUserActions.tsx (2)

3-3: Proper lunalink import.

Consistent with other files in the PR.


104-104: Improved route parameter safety.

The conversion to lunalink provides better type checking for route parameters. This ensures that required parameters (like user ID) aren't accidentally omitted, making the codebase more robust.

src/features/repositories/PageAdminRepository.tsx (2)

3-3: Added import for lunalink package

The import of lunalink from @bearstudio/lunalink aligns with the PR objective to add lunalink support for route handling.


69-71: URL generation using lunalink

The code now uses lunalink to generate the URL instead of directly calling the route function with parameters. This provides better type safety and route management.

src/features/users/routes.ts (2)

5-6: Improved type safety with as const assertions

Adding as const to route function return values ensures they're treated as literal types rather than general strings, improving type safety throughout the application.


7-7:

✅ Verification successful

Route parameter handling changed

The user method signature has been changed from accepting a parameter object to using a parameterized route format (:id). This is consistent with the lunalink approach but constitutes a breaking change for any code that directly calls this method without using lunalink.

Please ensure all callsites that use this route method have been updated to use the new signature with lunalink.


🏁 Script executed:

#!/bin/bash
# Search for all instances where ROUTES_USERS.admin.user is called directly without lunalink
rg "ROUTES_USERS\.admin\.user\(" --type ts

Length of output: 262


Route parameter update verified – all callsites now use lunalink

I reviewed the callsite usages, and both occurrences in src/features/users/PageAdminUsers.tsx and src/features/users/AdminUserActions.tsx call ROUTES_USERS.admin.user() via lunalink, confirming that the new parameterized route (:id) is consistently applied. No further changes are required.

src/features/repositories/AdminRepositoryActions.tsx (3)

3-3: Added import for lunalink package

The import of lunalink from @bearstudio/lunalink is consistent with the PR objective.


58-60: URL generation using lunalink

Converting direct route function calls to use the lunalink function provides better type safety and consistency with the rest of the application.


67-69: URL generation using lunalink for edit action

Similar to the previous change, this properly implements the lunalink pattern for the edit action URL.

src/features/admin/routes.ts (1)

2-2: Enhanced type safety with as const assertion

Adding as const to the route function return value improves type safety by treating it as a literal type.

src/features/app/routes.ts (2)

2-2: Enhanced type safety with const assertion.

Adding as const to the return value of the root function ensures that TypeScript treats it as a literal string type '/app' rather than a general string type. This provides more precise type information that can be used for route inference.


6-8: Improved type handling in conditional return.

The changes to the baseUrl function improve type safety by:

  1. Adding as const to ensure the empty string is treated as a literal type
  2. Including a @ts-expect-error comment to suppress expected TypeScript errors from the conditional return types

This maintains the guard against double slashes in URLs while enhancing type checking.

src/features/account/routes.ts (2)

6-6: Enhanced type safety with const assertion.

Using as const assertion for the app root path ensures that TypeScript treats it as a literal string type rather than a general string type, which enables more precise type checking and better route inference.


9-11: Enhanced type safety across admin route definitions.

The addition of as const assertions to all admin route paths (root, profile, and email) creates consistent literal type treatment throughout the routing system. This is a good practice that enables stronger type checking and better IDE support.

src/features/repositories/routes.ts (3)

6-6: Enhanced type safety with const assertion.

Using as const for the app root path ensures that TypeScript treats it as a literal string type, which enables more precise type checking for route definitions.


9-10: Enhanced type safety for root and create routes.

Adding as const assertions to the root and create route paths improves type safety and enables better route inference with the lunalink dependency mentioned in the PR description.


11-12: Improved parameterized route handling with const assertions.

The repository and update route definitions now:

  1. Use a parameterized format with :id placeholder
  2. Include as const assertions for literal type treatment

This approach provides better type safety while maintaining the dynamic nature of these routes when used with the lunalink library.

Comment on lines 6 to 8
baseUrl: () =>
// @ts-expect-error see comment above
ROUTES_ADMIN.root === ('/' as const) ? '' : ROUTES_ADMIN.root,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Logic error in baseUrl implementation

There's a critical issue in this change. The code now compares the function reference (ROUTES_ADMIN.root) directly to a string literal ('/'), which will always fail. The original comparison likely called the function (ROUTES_ADMIN.root()) to compare its return value.

This change will break the baseUrl functionality. Apply this fix:

-  baseUrl: () =>
-    // @ts-expect-error see comment above
-    ROUTES_ADMIN.root === ('/' as const) ? '' : ROUTES_ADMIN.root,
+  baseUrl: () =>
+    ROUTES_ADMIN.root() === ('/' as const) ? '' : ROUTES_ADMIN.root(),

Alternatively, if you want to maintain the as const type safety:

-  baseUrl: () =>
-    // @ts-expect-error see comment above
-    ROUTES_ADMIN.root === ('/' as const) ? '' : ROUTES_ADMIN.root,
+  baseUrl: () =>
+    (ROUTES_ADMIN.root() === '/' ? '' : ROUTES_ADMIN.root()) as const,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
baseUrl: () =>
// @ts-expect-error see comment above
ROUTES_ADMIN.root === ('/' as const) ? '' : ROUTES_ADMIN.root,
baseUrl: () =>
ROUTES_ADMIN.root() === ('/' as const) ? '' : ROUTES_ADMIN.root(),

@yoannfleurydev yoannfleurydev force-pushed the feat/add-lunalink-and-enjoy-route-types branch from 7b10ba5 to d795c18 Compare March 2, 2025 15:18
Copy link

sonarqubecloud bot commented Mar 2, 2025

Comment on lines -9 to +12
root: () => `${ROUTES_ADMIN.baseUrl()}/repositories`,
create: () => `${ROUTES_REPOSITORIES.admin.root()}/create`,
repository: (params: { id: string }) =>
`${ROUTES_REPOSITORIES.admin.root()}/${params.id}`,
update: (params: { id: string }) =>
`${ROUTES_REPOSITORIES.admin.root()}/${params.id}/update`,
root: () => `${ROUTES_ADMIN.baseUrl()}/repositories` as const,
create: () => `${ROUTES_REPOSITORIES.admin.root()}/create` as const,
repository: () => `${ROUTES_REPOSITORIES.admin.root()}/:id` as const,
update: () => `${ROUTES_REPOSITORIES.admin.root()}/:id/update` as const,
Copy link
Member

Choose a reason for hiding this comment

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

Why are we still defining routes as functions? I think that with Lunalink, we will no longer provide params, so this should simplify both the declaration and usage.
For example

repository: `${ROUTES_REPOSITORIES.admin.root}/:id` as const,

@yoannfleurydev yoannfleurydev enabled auto-merge (squash) March 4, 2025 18:58
@yoannfleurydev yoannfleurydev merged commit 9b2296d into master Mar 4, 2025
9 checks passed
@yoannfleurydev yoannfleurydev deleted the feat/add-lunalink-and-enjoy-route-types branch March 4, 2025 19:01
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.

3 participants