Skip to content

Conversation

mithun50
Copy link
Contributor

@mithun50 mithun50 commented Aug 14, 2025

Closes #127

📝 Description

This pull request refactors the frontend routing to use react-router-dom idiomatically, replacing a manual, state-based routing system with a modern, declarative approach.

🔧 Changes Made

Replaced the old, manual routing logic in App.tsx with a modern, declarative system using the react-router-dom library. Instead of relying on component state to switch pages, the application now uses standard URL-based routes (e.g., /dashboard, /settings).

Improved the Sidebar Navigation:
Updated the navigation links in the Sidebar from simple buttons to proper NavLink components. This allows the active page to be highlighted correctly based on the current URL.

Added a Logout Feature:
Added a new logout button to the bottom of the sidebar, which was previously missing.

✅ Checklist

  • I have read the contributing guidelines.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if applicable).
  • Any dependent changes have been merged and published in downstream modules.

Summary by CodeRabbit

  • New Features

    • Added protected routing with a new layout that gates authenticated pages and redirects unauthenticated users to login.
    • Introduced nested routes with animated transitions between pages.
    • Sidebar now integrates with router links and includes a Logout control.
  • Refactor

    • Replaced imperative page switching with a declarative nested route structure.
    • Updated page components to receive shared data via routed layout.
    • Simplified Sidebar API by removing active page props and adding an onLogout handler.

Copy link
Contributor

coderabbitai bot commented Aug 14, 2025

Walkthrough

Refactors frontend routing to use react-router-dom nested routes with a ProtectedLayout. Replaces activePage/renderPage with declarative routes. Sidebar now uses NavLink-based navigation and exposes onLogout. Adds Outlet and AnimatePresence for nested route rendering and transitions. Auth gating redirects unauthenticated users to /login.

Changes

Cohort / File(s) Summary
Routing refactor and auth gating
frontend/src/App.tsx
Replaces state-driven routing with nested react-router-dom routes, introduces ProtectedLayout with Sidebar and Outlet, adds route-based auth gating (root protected, /login public), updates page props (setRepoData, repoData), integrates AnimatePresence for route transitions.
Sidebar navigation migration
frontend/src/components/layout/Sidebar.tsx
Replaces button-based navigation and activePage prop with NavLink-driven router navigation via a navItems array; updates SidebarProps (remove activePage/setActivePage, add onLogout); adds Logout control; updates icons/imports.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant Router as React Router
  participant Protected as ProtectedLayout
  participant Sidebar
  participant Outlet
  participant Pages as Page Components

  User->>Router: Navigate to /
  Router->>Protected: Check auth
  alt Authenticated
    Protected->>Sidebar: Render (isOpen, onLogout)
    Protected->>Outlet: Render nested route
    Outlet->>Pages: Render Dashboard/Analytics/... based on path
    User->>Sidebar: Click NavLink
    Sidebar->>Router: Change URL
    Router->>Outlet: Render new nested route
  else Not authenticated
    Router->>User: Redirect to /login
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Assessment against linked issues

Objective Addressed Explanation
Replace activePage/renderPage with declarative Route components; remove prop-drilled navigation [#127]
Implement nested protected routes with auth gating; root protected, /login public [#127]
Sidebar uses NavLink for navigation with URL syncing [#127]
Ensure URL reflects current page and supports direct linking [#127]

Possibly related PRs

Suggested reviewers

  • chandansgowda

Poem

I hopped through routes, a tidy warren,
No more switches, no more sorrow’n.
Links that glow, a sidebar bright,
Protected paths guard day and night.
With one swift leap, I’m logged right out—
Animate hops, I dance about! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@mithun50
Copy link
Contributor Author

@smokeyScraper request for review this pr

@smokeyScraper
Copy link
Contributor

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Aug 16, 2025

✅ Actions performed

Full review triggered.

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 (7)
frontend/src/components/layout/Sidebar.tsx (3)

36-41: Use functional state update and add a11y attributes to the toggle

Prevents potential stale state issues and improves accessibility.

-        <button onClick={() => setIsOpen(!isOpen)} className="p-2 hover:bg-gray-800 rounded-lg">
+        <button
+          onClick={() => setIsOpen((prev) => !prev)}
+          aria-label={isOpen ? 'Collapse sidebar' : 'Expand sidebar'}
+          aria-expanded={isOpen}
+          className="p-2 hover:bg-gray-800 rounded-lg"
+        >

45-57: Improve collapsed-mode accessibility and discoverability for links

When collapsed, the label is visually hidden. Provide an accessible name and tooltip.

           <NavLink
             key={item.path}
             to={item.path}
+            title={item.label}
+            aria-label={!isOpen ? item.label : undefined}
             className={({ isActive }) =>

60-67: Add a11y attributes to the Logout button

Explicitly set button type and label for accessibility.

-        <button
+        <button
+          type="button"
+          aria-label="Logout"
           onClick={onLogout}
           className={`w-full flex items-center px-4 py-3 text-gray-300 hover:bg-gray-800 hover:text-red-500 transition-colors`}
         >
frontend/src/App.tsx (4)

20-29: Avoid auth flicker on initial load by reading localStorage synchronously

Initialize from localStorage in state initializer and drop the effect. Prevents a brief redirect to /login before hydration.

-  const [isAuthenticated, setIsAuthenticated] = useState(false);
-
-  // Check for existing authentication on app load
-  useEffect(() => {
-    const savedAuth = localStorage.getItem('isAuthenticated');
-    if (savedAuth === 'true') {
-      setIsAuthenticated(true);
-    }
-  }, []);
+  const [isAuthenticated, setIsAuthenticated] = useState<boolean>(() => {
+    return localStorage.getItem('isAuthenticated') === 'true';
+  });

2-2: Ensure route transition exit animations run by keying content with location

AnimatePresence won’t play exit animations reliably without a stable key per route. Use useLocation and key the Outlet container.

-import { BrowserRouter as Router, Routes, Route, Navigate, Outlet } from 'react-router-dom';
+import { BrowserRouter as Router, Routes, Route, Navigate, Outlet, useLocation } from 'react-router-dom';
-  const ProtectedLayout = () => (
-    <div className="flex">
-      <Sidebar
-        isOpen={isSidebarOpen}
-        setIsOpen={setIsSidebarOpen}
-        onLogout={handleLogout}
-      />
-      <main
-        className={`transition-all duration-300 flex-1 ${
-          isSidebarOpen ? 'ml-64' : 'ml-20'
-        }`}
-      >
-        <div className="p-8">
-          <AnimatePresence mode="wait">
-            <Outlet />
-          </AnimatePresence>
-        </div>
-      </main>
-    </div>
-  );
+  const ProtectedLayout = () => {
+    const location = useLocation();
+    return (
+      <div className="flex">
+        <Sidebar
+          isOpen={isSidebarOpen}
+          setIsOpen={setIsSidebarOpen}
+          onLogout={handleLogout}
+        />
+        <main
+          className={`transition-all duration-300 flex-1 ${
+            isSidebarOpen ? 'ml-64' : 'ml-20'
+          }`}
+        >
+          <div className="p-8">
+            <AnimatePresence mode="wait">
+              <div key={location.pathname}>
+                <Outlet />
+              </div>
+            </AnimatePresence>
+          </div>
+        </main>
+      </div>
+    );
+  };

Also applies to: 41-60


66-96: Add a catch-all route to handle unknown URLs

Redirects unknown paths to a sensible destination depending on auth.

         <Routes>
           <Route
             path="/login"
             element={
               isAuthenticated ? (
                 <Navigate to="/" replace />
               ) : (
                 <LoginPage onLogin={handleLogin} />
               )
             }
           />
           <Route
             path="/"
             element={
               isAuthenticated ? <ProtectedLayout /> : <Navigate to="/login" replace />
             }
           >
             <Route index element={<LandingPage setRepoData={setRepoData} />} />
             <Route path="dashboard" element={<Dashboard repoData={repoData} />} />
             <Route path="integration" element={<BotIntegrationPage />} />
             <Route path="contributors" element={<ContributorsPage repoData={repoData} />} />
             <Route path="analytics" element={<AnalyticsPage repoData={repoData} />} />
             <Route path="prs" element={<PullRequestsPage repoData={repoData} />} />
             <Route path="support" element={<SupportPage />} />
             <Route path="settings" element={<SettingsPage />} />
             <Route path="profile" element={<ProfilePage />} />
           </Route>
+          <Route
+            path="*"
+            element={<Navigate to={isAuthenticated ? '/dashboard' : '/login'} replace />}
+          />
         </Routes>

19-19: Optional: replace any with a typed shape for repoData

Define a RepoData interface to improve type-safety across Dashboard/Analytics/Contributors/PRs.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a4ff6eb and 9111674.

📒 Files selected for processing (2)
  • frontend/src/App.tsx (4 hunks)
  • frontend/src/components/layout/Sidebar.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
frontend/src/App.tsx (2)
frontend/src/components/integration/BotIntegrationPage.tsx (1)
  • BotIntegrationPage (11-140)
frontend/src/components/pages/SettingsPage.tsx (1)
  • SettingsPage (12-257)
🔇 Additional comments (2)
frontend/src/components/layout/Sidebar.tsx (1)

22-31: Good move: NavLink-based navigation with defined route paths

Switching to a centralized navItems + NavLink removes prop-drilling and keeps URL as the source of truth. Clean and idiomatic.

frontend/src/App.tsx (1)

78-92: Router refactor is idiomatic and clear

Nested routes under a ProtectedLayout with URL-driven navigation is a strong improvement over manual state switching. Props wiring to pages looks consistent.

Copy link
Contributor

@smokeyScraper smokeyScraper left a comment

Choose a reason for hiding this comment

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

Thanks a lot @mithun50! for the PR.
This helps a lot in protecting routes and decoupling logic.

@smokeyScraper smokeyScraper merged commit f31ba33 into AOSSIE-Org:main Sep 7, 2025
1 check was pending
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.

BUG:Refactor Frontend Routing for Better Maintainability and Readability

2 participants