Skip to content

Conversation

rafalmaksymiuk
Copy link
Contributor

@rafalmaksymiuk rafalmaksymiuk commented Jun 25, 2025

SidebarToggle updated to use an alternative to react-router when switch is enabled.

Summary by CodeRabbit

  • New Features
    • Sidebar toggle now supports both internal navigation and router-based navigation, with a new option to disable router integration.
  • Bug Fixes
    • Improved sidebar toggle behavior to ensure consistent state updates across navigation methods.
  • Tests
    • Updated sidebar toggle tests for better coverage and reliability using modern testing tools.

@rafalmaksymiuk rafalmaksymiuk requested a review from a team as a code owner June 25, 2025 13:00
Copy link

coderabbitai bot commented Jun 25, 2025

Walkthrough

The SidebarToggle component was updated to support both React Router-based and internal navigation for toggling sidebar state, controlled by a new routerDisabled flag and associated handler props. Corresponding tests were refactored to use React Testing Library, expanding coverage to include both navigation modes and complex state scenarios.

Changes

File(s) Change Summary
src/elements/content-sidebar/SidebarToggle.js Extended SidebarToggle props for optional internal navigation and router disabling; refactored click handler logic.
src/elements/content-sidebar/tests/SidebarToggle.test.js Migrated tests from Enzyme to React Testing Library; added tests for both router and internal navigation modes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SidebarToggle
    participant RouterHistory
    participant InternalNavHandler

    User->>SidebarToggle: Click toggle button
    SidebarToggle->>SidebarToggle: handleToggleClick()
    alt routerDisabled = false and history present
        SidebarToggle->>RouterHistory: replace({ sidebarOpen: toggled })
    else routerDisabled = true and internal handler present
        SidebarToggle->>InternalNavHandler: handle({ sidebarOpen: toggled }, { replace: true })
    end
Loading

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • jankowiakdawid
  • tjiang-box

Poem

A toggle for the sidebar, now clever and spry,
Can dance with the router, or wave it goodbye.
With handlers internal, or history in tow,
It opens and closes, wherever you go.
🐇✨ Hooray for the code that makes sidebars flow!

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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

@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: 3

🧹 Nitpick comments (1)
src/elements/content-sidebar/__tests__/SidebarToggle.test.js (1)

33-87: Consider adding edge case tests for missing props.

While the current tests cover the happy path well, consider adding tests for when routerDisabled is true but required props are missing.

Add test cases for edge scenarios:

test('should handle missing internalSidebarNavigationHandler gracefully', async () => {
    const user = userEvent();
    render(<SidebarToggle routerDisabled={true} internalSidebarNavigation={{ sidebar: 'activity' }} />);
    
    const toggleButton = screen.getByTestId('sidebartoggle');
    await user.click(toggleButton);
    
    // Should not throw error and handler should not be called
    expect(mockInternalSidebarNavigationHandler).not.toHaveBeenCalled();
});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 269f585 and cd16f7d.

⛔ Files ignored due to path filters (1)
  • src/elements/content-sidebar/__tests__/__snapshots__/SidebarToggle.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/elements/content-sidebar/SidebarToggle.js (1 hunks)
  • src/elements/content-sidebar/__tests__/SidebarToggle.test.js (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/elements/content-sidebar/SidebarToggle.js

[error] 11-11: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 12-19: type alias are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 27-27: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint_test_build
  • GitHub Check: Summary
🔇 Additional comments (7)
src/elements/content-sidebar/SidebarToggle.js (2)

28-42: The toggle logic implementation looks correct.

The conditional navigation logic properly handles both router and internal navigation modes. The spread operator correctly preserves existing navigation state while toggling the open property.


33-38: Verify internal navigation handler is always available when routerDisabled is true.

The code checks for both internalSidebarNavigationHandler and internalSidebarNavigation before calling the handler, but there's no feedback when these are missing in router-disabled mode.

Consider adding error handling or warnings when routerDisabled is true but required props are missing:

 if (routerDisabled) {
     // Use internal navigation handler when router is disabled
     if (internalSidebarNavigationHandler && internalSidebarNavigation) {
         internalSidebarNavigationHandler({
             ...internalSidebarNavigation,
             open: !isOpen,
         }, true); // Always use replace for toggle
+    } else {
+        console.warn('SidebarToggle: routerDisabled is true but internalSidebarNavigationHandler or internalSidebarNavigation is missing');
     }
 }
src/elements/content-sidebar/__tests__/SidebarToggle.test.js (5)

2-2: LGTM! Good migration to React Testing Library.

The import update to use React Testing Library and userEvent is a solid improvement over Enzyme for more realistic user interactions.


8-14: Excellent test setup with proper cleanup.

The beforeEach hook for clearing mocks and the render helper function follow React Testing Library best practices and improve test reliability.


16-31: Well-structured parameterized tests for router mode.

The test correctly verifies that history.replace is called with the toggled state. The parameterized approach efficiently covers both open/closed scenarios.


33-62: Comprehensive coverage for router-disabled mode.

The tests properly verify the internal navigation handler is called with the correct parameters including the replace flag. Good separation of concerns with dedicated describe block.


64-86: Excellent test for complex navigation state scenarios.

This test ensures the spread operator behavior works correctly with complex navigation objects, which is crucial for maintaining existing state while toggling the sidebar.

Copy link
Contributor

mergify bot commented Jun 26, 2025

This pull request has been removed from the queue for the following reason: checks failed.

The merge conditions cannot be satisfied due to failing checks.

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

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.

4 participants