Skip to content

Conversation

@sealday
Copy link
Contributor

@sealday sealday commented Jun 30, 2025

Summary by CodeRabbit

  • New Features

    • Updated all admin-related routes and navigation to use a dynamic, configurable URL prefix instead of a hardcoded path.
  • Refactor

    • Centralized the admin URL prefix logic for easier management and consistency across the application.
    • Replaced all hardcoded /admin references with the new dynamic prefix throughout the user interface.
    • Added a loading state flag to improve application load management.
    • Enhanced route handling by simplifying dynamic page and plugin routing paths.
    • Improved application startup by conditionally triggering load operations.
  • Chores

    • Removed a custom router context provider and related context logic that is no longer needed.
    • Enabled React Strict Mode at the app root for better development checks.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 30, 2025

Walkthrough

The changes refactor the application's routing logic to replace hardcoded /admin paths with a dynamic prefix sourced from a new prefix property in the Application class, now set to 'dashboard'. This affects route matching, navigation, and URL construction throughout the codebase. Additionally, a custom router context provider file was removed, and references to it were eliminated. Minor improvements include adding React StrictMode in the root app, simplifying constructors in Plugin and PluginManager, guarding against redundant app loading, and adding a symbol key check in the API client proxy.

Changes

File(s) Change Summary
packages/client/src/application/Application.tsx Added prefix getter returning 'dashboard'; added loaded property; updated adminUrl to use prefix; added indexSchema getter; set loaded = true after load.
packages/client/src/application/CustomRouterContextProvider.tsx Deleted file; removed all custom routing contexts, providers, and hooks.
packages/client/src/application/RouterManager.tsx Removed import and usage of CustomRouterContextProvider.
packages/client/src/built-in/admin-layout/MenuEditor.tsx Replaced hardcoded /admin with dynamic /${app.prefix} in route matching and navigation.
packages/client/src/built-in/admin-layout/components/AddNewButton.tsx Changed navigation after insert to use dynamic app.prefix instead of /admin.
packages/client/src/built-in/dynamic-page/index.tsx Updated route path to use this.app.prefix instead of /:entry.
packages/client/src/built-in/index.tsx Updated route paths and redirects to use this.app.prefix instead of /admin or /:entry.
packages/client/src/built-in/setting-layout/SettingLayout.tsx Changed home button navigation to use dynamic app.prefix instead of /admin.
packages/client/src/built-in/user-settings/UserSettingsLayout.tsx Changed fallback path in getFirstDeepChildPath to use dynamic app.prefix instead of /admin.
packages/client/src/collection-manager/CollectionHistoryProvider.tsx Changed admin page detection to use app.prefix instead of /admin.
apps/web/src/index.tsx Added explicit React import and wrapped <App /> in <React.StrictMode>.
packages/client/src/application/Plugin.ts Simplified constructor by using parameter properties instead of explicit assignments.
packages/client/src/application/PluginManager.ts Removed redundant explicit assignment of app in constructor.
packages/client/src/application/components/AppComponent.tsx Added conditional to call app.load() only if not already loaded or loading.
packages/client/src/hooks/useAdminSchemaUid.ts Changed to return dynamic app.indexSchema instead of hardcoded string.
packages/sdk/src/APIClient.ts Added guard in proxy to ignore symbol keys by logging and returning undefined.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Router
    participant App
    participant Components

    User->>Router: Navigate to /dashboard/...
    Router->>App: Request prefix via app.prefix
    App-->>Router: Return 'dashboard'
    Router->>Components: Render routes using dynamic prefix
    Components->>Router: Use app.prefix for navigation and matching
Loading

Poem

🐇
Paths once fixed, now dance and shift,
"Dashboard" leads where "admin" did drift.
Contexts pruned, the code runs light,
Dynamic routes guide us right.
With every hop, the app feels new—
Prefix in paw, we bound on through!

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in a Comment
  • Commit Unit Tests in branch feat/new-router-system

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests 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

🧹 Nitpick comments (1)
packages/client/src/application/Application.tsx (1)

118-120: Consider making the prefix configurable.

The new prefix getter provides centralized prefix management, which is good. However, the hardcoded 'dashboard' value might need to be configurable for different deployment scenarios.

Consider making the prefix configurable through application options:

+export interface ApplicationOptions {
+  prefix?: string;
   // ... other options
+}

 get prefix() {
-  return 'dashboard';
+  return this.options.prefix || 'dashboard';
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 482f32f and f5a54f0.

📒 Files selected for processing (10)
  • packages/client/src/application/Application.tsx (1 hunks)
  • packages/client/src/application/CustomRouterContextProvider.tsx (0 hunks)
  • packages/client/src/application/RouterManager.tsx (1 hunks)
  • packages/client/src/built-in/admin-layout/MenuEditor.tsx (4 hunks)
  • packages/client/src/built-in/admin-layout/components/AddNewButton.tsx (3 hunks)
  • packages/client/src/built-in/dynamic-page/index.tsx (1 hunks)
  • packages/client/src/built-in/index.tsx (3 hunks)
  • packages/client/src/built-in/setting-layout/SettingLayout.tsx (1 hunks)
  • packages/client/src/built-in/user-settings/UserSettingsLayout.tsx (1 hunks)
  • packages/client/src/collection-manager/CollectionHistoryProvider.tsx (3 hunks)
💤 Files with no reviewable changes (1)
  • packages/client/src/application/CustomRouterContextProvider.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: CI
🔇 Additional comments (14)
packages/client/src/built-in/user-settings/UserSettingsLayout.tsx (1)

72-72: LGTM! Fallback path correctly uses dynamic prefix.

The change from hardcoded '/admin' to /${app.prefix} ensures the fallback navigation aligns with the application's configured prefix.

packages/client/src/built-in/setting-layout/SettingLayout.tsx (1)

96-96: LGTM! Home button navigation correctly uses dynamic prefix.

The navigation path now uses /${app.prefix} instead of the hardcoded /admin, making the routing configurable.

packages/client/src/application/RouterManager.tsx (1)

148-154: LGTM! Simplified routing context management.

The removal of CustomRouterContextProvider wrapper streamlines the JSX structure and reduces unnecessary routing context complexity.

packages/client/src/built-in/admin-layout/components/AddNewButton.tsx (3)

8-8: LGTM! Added useApp import for dynamic prefix.

The import correctly adds useApp hook to access the application's dynamic prefix.


26-26: LGTM! Initialized app instance for prefix access.

Getting the app instance enables access to the dynamic prefix property.


38-38: LGTM! Navigation path uses dynamic prefix.

The navigation URL construction now uses /${app.prefix}/ instead of hardcoded /admin/, making the routing configurable.

packages/client/src/collection-manager/CollectionHistoryProvider.tsx (3)

6-6: LGTM! Added useApp import for dynamic prefix.

The import correctly adds useApp hook to access the application's dynamic prefix.


21-21: LGTM! Initialized app instance for prefix access.

Getting the app instance enables access to the dynamic prefix property for admin page detection.


44-44: LGTM! Admin page detection uses dynamic prefix.

The pathname check now uses /${app.prefix} instead of hardcoded /admin, ensuring admin page detection works with the configurable prefix.

packages/client/src/built-in/dynamic-page/index.tsx (1)

22-22: LGTM! Route path correctly updated to use dynamic prefix.

The change from /:entry/:name/* to /${this.app.prefix}/:name/* properly implements the dynamic prefix pattern, removing the parameterized entry segment in favor of the app's configured prefix.

packages/client/src/built-in/admin-layout/MenuEditor.tsx (2)

6-6: LGTM! Added necessary import for dynamic prefix usage.

The useApp import is correctly added to support the dynamic prefix functionality throughout the component.


25-87: Excellent refactoring! All hardcoded admin paths replaced consistently.

All route matching, navigation, and URL construction have been properly updated to use /${app.prefix} instead of hardcoded /admin paths. The changes maintain the existing logic while making the routing dynamic and configurable.

packages/client/src/application/Application.tsx (1)

110-116: LGTM! AdminUrl properly refactored to use dynamic prefix.

The adminUrl getter correctly uses this.prefix instead of hardcoded 'admin' strings, providing consistency with the broader refactoring effort.

packages/client/src/built-in/index.tsx (1)

349-372: LGTM! Route definitions properly updated to use dynamic prefix.

All route paths have been correctly updated to use ${this.app.prefix} instead of hardcoded paths, maintaining consistency with the refactoring effort.

subApp ? (
<Button key="back" onClick={() => (window.location.href = '/admin')}>
// TODO 提供默认跳转的页面,即到对应页面后,会触发前端跳转
<Button key="back" onClick={() => (window.location.href = `/admin`)}>
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

Fix remaining hardcoded admin reference.

There's still a hardcoded /admin reference in the error handling code that should be updated for consistency with the prefix refactoring.

Apply this fix to use the dynamic prefix:

-<Button key="back" onClick={() => (window.location.href = `/admin`)}>
+<Button key="back" onClick={() => (window.location.href = `/${app.prefix}`)}>

Note: You'll need to access the app instance in this context. Consider using the useApp() hook similar to other components.

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

🤖 Prompt for AI Agents
In packages/client/src/built-in/index.tsx at line 110, replace the hardcoded
'/admin' URL with a dynamic prefix by using the useApp() hook to get the current
app instance and its prefix. Update the onClick handler to set
window.location.href to the prefix plus '/admin' instead of the fixed string.
This ensures consistency with the prefix refactoring across the codebase.

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 f5a54f0 and e08d97b.

📒 Files selected for processing (7)
  • apps/web/src/index.tsx (1 hunks)
  • packages/client/src/application/Application.tsx (3 hunks)
  • packages/client/src/application/Plugin.ts (1 hunks)
  • packages/client/src/application/PluginManager.ts (0 hunks)
  • packages/client/src/application/components/AppComponent.tsx (1 hunks)
  • packages/client/src/hooks/useAdminSchemaUid.ts (1 hunks)
  • packages/sdk/src/APIClient.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/client/src/application/PluginManager.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/client/src/application/Application.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: CI
🔇 Additional comments (5)
apps/web/src/index.tsx (2)

1-1: LGTM: React import is necessary for StrictMode usage.

The explicit React import is required for using React.StrictMode component, which aligns with the changes made in the render method.


10-14: Excellent addition of React StrictMode!

Wrapping the App component in React.StrictMode is a great improvement that will:

  • Help identify potential problems during development
  • Warn about deprecated React features and unsafe lifecycle methods
  • Enable additional development-time checks and warnings

This change aligns with React best practices and will improve the development experience without affecting production performance.

packages/client/src/application/components/AppComponent.tsx (1)

24-26: LGTM! Excellent improvement to prevent redundant loading.

The conditional guard ensures app.load() is only called when necessary, preventing redundant operations and potential race conditions. This is a good defensive programming practice.

packages/client/src/hooks/useAdminSchemaUid.ts (1)

1-6: LGTM! Good refactoring to use dynamic configuration.

Replacing the hardcoded string with app.indexSchema aligns perfectly with the PR objective to use dynamic prefixes instead of hardcoded values. The implementation correctly uses the useApp() hook to access the application context.

packages/client/src/application/Plugin.ts (1)

6-9: LGTM! Clean constructor simplification using TypeScript parameter properties.

The refactoring leverages TypeScript's parameter property syntax to automatically create class properties, eliminating boilerplate code while maintaining the same functionality. The protected access modifiers ensure proper encapsulation.

Comment on lines +314 to +317
if (typeof actionName === 'symbol') {
console.log('-----', _, actionName);
return;
}
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

Remove debug logging and improve symbol handling.

The symbol check is a good defensive practice, but the console.log appears to be debug code that should be removed before production.

 if (typeof actionName === 'symbol') {
-  console.log('-----', _, actionName);
-  return;
+  // Symbols are not valid action names, return undefined to prevent processing
+  return undefined;
 }

Consider adding a comment explaining why symbols are filtered out, as this helps future maintainers understand the defensive behavior against framework-internal symbol property accesses.

📝 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
if (typeof actionName === 'symbol') {
console.log('-----', _, actionName);
return;
}
if (typeof actionName === 'symbol') {
// Symbols are not valid action names, return undefined to prevent processing
return undefined;
}
🤖 Prompt for AI Agents
In packages/sdk/src/APIClient.ts around lines 314 to 317, remove the console.log
debug statement inside the symbol type check to clean up production code. Retain
the symbol check to defensively filter out framework-internal symbol property
accesses, and add a clear comment explaining this purpose for future
maintainers.

@sealday sealday marked this pull request as draft July 3, 2025 03:53
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.

2 participants