Skip to content

Conversation

@rafalmaksymiuk
Copy link
Contributor

@rafalmaksymiuk rafalmaksymiuk commented Jun 20, 2025

…ebar

Added router disabling switch to VersionsSidebar components and created router-less branch of code inside.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added support for disabling routing in the Versions Sidebar, enabling internal sidebar navigation handling when routing is turned off.
    • Introduced new optional navigation props for custom sidebar navigation and back button behavior.
    • Refined sidebar navigation typing and default view settings for improved consistency.
  • Bug Fixes

    • Improved handling of sidebar navigation state when routing is disabled.
  • Tests

    • Enhanced test coverage to verify new navigation handling and ensure correct behavior with and without routing enabled.

@rafalmaksymiuk rafalmaksymiuk requested review from a team as code owners June 20, 2025 14:56
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 20, 2025

Walkthrough

This change refactors the version sidebar components to support an optional routerDisabled mode, allowing navigation to be handled internally via a callback instead of React Router. Type definitions are updated to make the open property optional. Corresponding tests are added and updated to verify both routing and internal navigation scenarios.

Changes

File(s) Change Summary
src/elements/common/types/SidebarNavigation.js.flow, src/elements/common/types/SidebarNavigation.ts Changed InternalSidebarNavigation.open from required to optional boolean.
src/elements/content-sidebar/versions/StaticVersionSidebar.js, src/elements/content-sidebar/versions/VersionsSidebar.js Refactored components to support routerDisabled, internal navigation handler, and updated prop types.
src/elements/content-sidebar/versions/VersionsSidebarContainer.js Updated parentName prop type from string to ViewTypeValues and default from '' to ViewType.DETAILS.
src/elements/content-sidebar/versions/tests/StaticVersionSidebar.test.js, src/elements/content-sidebar/versions/tests/VersionsSidebar.test.js Enhanced tests to cover both router-enabled and routerDisabled navigation scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SidebarComponent
    participant Router
    participant InternalNavHandler

    User->>SidebarComponent: Clicks Back Button
    alt routerDisabled is true
        SidebarComponent->>InternalNavHandler: handleNavigation(sidebarName)
    else routerDisabled is false
        SidebarComponent->>Router: history.push(parentSidebarRoute)
    end
Loading

Possibly related PRs

  • box/box-ui-elements#4144: Extends sidebar version components for optional routing and internal navigation, directly related to this PR's navigation logic changes.
  • box/box-ui-elements#4141: Refactors BackButton to remove routing logic, enabling navigation control to be managed by sidebar components as implemented here.
  • box/box-ui-elements#4136: Adds optional router disabling and internal sidebar navigation handling in annotator context components, related in enabling router-optional behavior.

Suggested labels

ready-to-merge

Suggested reviewers

  • greg-in-a-box
  • kajarosz

Poem

A sidebar hops with nimble grace,
Now routing’s not its only place!
With options new and tests so bright,
It turns and leaps both left and right.
Whether router’s on or gone away,
The menu’s sure to find its way—
A rabbit’s cheer for code today! 🐇

✨ 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
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 (1)
src/elements/content-sidebar/versions/VersionsSidebar.js (1)

1-127: Verify StaticVersionSidebar.js component was updated similarly.

The tests suggest that StaticVersionSidebar.js was updated with similar routerDisabled functionality, but the component file isn't included in this review. Please ensure that component received similar refactoring to maintain consistency.

#!/bin/bash
# Description: Verify StaticVersionSidebar.js has similar routerDisabled implementation
# Expected: Should find routerDisabled prop and similar conditional logic

echo "=== Checking StaticVersionSidebar.js for routerDisabled implementation ==="
cat src/elements/content-sidebar/versions/StaticVersionSidebar.js | grep -A 10 -B 5 "routerDisabled\|internalSidebarNavigation"

echo -e "\n=== Checking for handleBackClick or similar navigation logic ==="
cat src/elements/content-sidebar/versions/StaticVersionSidebar.js | grep -A 5 -B 5 "handleBackClick\|BackButton.*onClick"

echo -e "\n=== Checking component props structure ==="
ast-grep --pattern 'type Props = {
  $$$
}'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 15c5d8d and f17f676.

📒 Files selected for processing (6)
  • src/elements/common/types/SidebarNavigation.js.flow (1 hunks)
  • src/elements/common/types/SidebarNavigation.ts (1 hunks)
  • src/elements/content-sidebar/versions/StaticVersionSidebar.js (2 hunks)
  • src/elements/content-sidebar/versions/VersionsSidebar.js (1 hunks)
  • src/elements/content-sidebar/versions/__tests__/StaticVersionSidebar.test.js (4 hunks)
  • src/elements/content-sidebar/versions/__tests__/VersionsSidebar.test.js (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/elements/common/types/SidebarNavigation.js.flow (1)
Learnt from: rafalmaksymiuk
PR: box/box-ui-elements#4144
File: src/elements/content-sidebar/versions/VersionsList.js:24-33
Timestamp: 2025-06-17T13:30:02.172Z
Learning: In the box-ui-elements codebase, Flow components use .flow.js type definition files, not TypeScript .ts files. The InternalSidebarNavigation type is a union type where different variants may have different properties like versionId, and proper type safety is ensured through conditional checks in methods like getSelectedVersionId.
🪛 Biome (1.9.4)
src/elements/content-sidebar/versions/VersionsSidebar.js

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 54-54: optional parameters are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 62-62: optional parameters are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)

src/elements/content-sidebar/versions/StaticVersionSidebar.js

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 41-41: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 61-61: optional parameters are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 69-69: optional parameters are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 69-69: 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 (17)
src/elements/common/types/SidebarNavigation.ts (1)

42-42: LGTM! Type change supports optional router functionality.

Making the open property optional in InternalSidebarNavigation aligns well with the new routerDisabled mode where sidebar state management becomes more flexible.

src/elements/common/types/SidebarNavigation.js.flow (1)

33-33: LGTM! Maintains type consistency with TypeScript definition.

The optional open property change matches the corresponding TypeScript type definition, ensuring consistent behavior across both type systems.

src/elements/content-sidebar/versions/__tests__/StaticVersionSidebar.test.js (2)

105-141: LGTM! Comprehensive test coverage for router vs internal navigation.

The test properly verifies that when React Router is enabled, the internal navigation handler is not called and routing uses the standard router mechanism.


180-222: LGTM! Thorough test coverage for routerDisabled mode.

The new test suite comprehensively covers the routerDisabled functionality:

  • Renders correctly without React Router context
  • Internal navigation handler is called with correct parameters
  • Props are passed correctly to child components
src/elements/content-sidebar/versions/__tests__/VersionsSidebar.test.js (2)

137-170: LGTM! Consistent test approach with router navigation verification.

The updated test properly verifies that router navigation takes precedence over internal navigation when router is enabled, maintaining consistency with the StaticVersionSidebar test pattern.


172-213: LGTM! Complete test coverage for routerDisabled functionality.

The test suite provides thorough coverage of the routerDisabled mode, ensuring:

  • Component renders without React Router
  • Internal navigation handler is invoked correctly
  • Props are passed to child components appropriately
src/elements/content-sidebar/versions/VersionsSidebar.js (4)

19-19: LGTM! Well-defined props for optional router functionality.

The new props are properly typed and optional, ensuring backward compatibility while enabling the new internal navigation mode.

Also applies to: 29-31, 33-33


54-60: LGTM! Robust conditional navigation logic.

The handleBackClick callback correctly handles both routing modes:

  • Uses internal navigation when routerDisabled is true
  • Falls back to React Router when available
  • Proper parameter validation and conditional execution

62-113: LGTM! Clean separation of rendering logic.

The renderContent function properly extracts the rendering logic and maintains all existing functionality while supporting the new optional history parameter for conditional router usage.


115-123: LGTM! Clean conditional rendering implementation.

The conditional rendering based on routerDisabled is clean and maintains the same UI structure in both modes while properly handling router dependency.

src/elements/content-sidebar/versions/StaticVersionSidebar.js (7)

17-17: LGTM: Appropriate type imports added.

The import of InternalSidebarNavigation and InternalSidebarNavigationHandler types is correctly added to support the new optional navigation functionality.


23-23: LGTM: useCallback import added for performance optimization.

The useCallback import is appropriate for the new navigation handler to prevent unnecessary re-renders.


25-32: LGTM: Props type extended with optional navigation properties.

The new optional props maintain backward compatibility while enabling the new router-disabled functionality:

  • internalSidebarNavigation?: For internal navigation state
  • internalSidebarNavigationHandler?: Callback for internal navigation
  • routerDisabled?: Flag to control navigation mode

34-41: LGTM: Component signature updated correctly.

The function signature properly destructures the new optional props while maintaining the existing parameter structure.


61-67: LGTM: Well-implemented conditional navigation logic.

The handleBackClick callback correctly implements the conditional navigation:

  • When routerDisabled=true: uses internal navigation handler
  • When routerDisabled=false/undefined: uses React Router history

The useCallback dependencies are correctly specified to prevent unnecessary re-renders.


69-125: LGTM: Clean refactoring of rendering logic.

The renderContent function effectively abstracts the rendering logic to support both navigation modes. The optional history parameter allows the same component structure to work with or without React Router.

The props passed to VersionsMenu correctly include the new navigation-related props.


127-131: LGTM: Conditional rendering implements the router-disabled feature correctly.

The conditional rendering logic cleanly separates the two modes:

  • When routerDisabled=true: renders content directly without Route wrapper
  • Otherwise: renders within Route component with history access

This maintains backward compatibility while enabling the new functionality.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f17f676 and c3fde86.

📒 Files selected for processing (3)
  • src/elements/content-sidebar/versions/StaticVersionSidebar.js (2 hunks)
  • src/elements/content-sidebar/versions/VersionsSidebar.js (1 hunks)
  • src/elements/content-sidebar/versions/VersionsSidebarContainer.js (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/elements/content-sidebar/versions/VersionsSidebarContainer.js (1)
Learnt from: rafalmaksymiuk
PR: box/box-ui-elements#4144
File: src/elements/content-sidebar/versions/VersionsList.js:24-33
Timestamp: 2025-06-17T13:30:02.172Z
Learning: In the box-ui-elements codebase, Flow components use .flow.js type definition files, not TypeScript .ts files. The InternalSidebarNavigation type is a union type where different variants may have different properties like versionId, and proper type safety is ensured through conditional checks in methods like getSelectedVersionId.
🪛 Biome (1.9.4)
src/elements/content-sidebar/versions/VersionsSidebarContainer.js

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

TypeScript only syntax

(parse)

src/elements/content-sidebar/versions/StaticVersionSidebar.js

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 45-45: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 65-65: optional parameters are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 73-73: optional parameters are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)

src/elements/content-sidebar/versions/VersionsSidebar.js

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 54-54: optional parameters are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 62-62: optional parameters are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 62-62: 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 (25)
src/elements/content-sidebar/versions/VersionsSidebarContainer.js (3)

27-27: Good type refinement for parentName prop.

The change from generic string to specific ViewTypeValues type improves type safety and aligns with the other version sidebar components.

Also applies to: 44-44


27-27: Good type improvement for better type safety.

The change from generic string to specific ViewTypeValues type for the parentName prop improves type safety and aligns with similar changes across related components.

Also applies to: 44-44


27-27: Type refinement looks good.

The change from generic string to specific ViewTypeValues type improves type safety for the parentName prop.

Also applies to: 44-44

src/elements/content-sidebar/versions/VersionsSidebar.js (11)

19-19: Well-structured imports for new navigation features.

The addition of the new navigation types and React hooks is properly organized and supports the router-disabled functionality.

Also applies to: 22-22


29-33: Good prop additions for optional routing.

The new props are properly typed and optional, allowing backward compatibility while enabling the new internal navigation mode.


54-60: Robust conditional navigation logic.

The handleBackClick callback correctly handles both router and internal navigation modes with proper guard conditions. The dependency array in useCallback is complete and accurate.


115-123: Clean conditional rendering pattern.

The pattern of conditional rendering based on routerDisabled is clean and maintainable. When routing is disabled, it renders content directly; otherwise it wraps with Route to access history.


93-99: Proper prop forwarding to VersionsMenu.

The routerDisabled and internalSidebarNavigation props are correctly passed to the VersionsMenu component to maintain consistent navigation behavior throughout the component tree.


19-19: LGTM: Well-structured prop additions for router flexibility.

The new props internalSidebarNavigation, internalSidebarNavigationHandler, and routerDisabled are properly typed and provide the necessary flexibility for both router-based and internal navigation modes.

Also applies to: 29-33


54-60: Excellent conditional navigation logic.

The handleBackClick callback properly handles both routing modes:

  • Internal navigation when routerDisabled is true
  • React Router navigation otherwise

The useCallback optimization and dependency array are correctly implemented.


62-123: Clean refactoring enables flexible rendering modes.

The extraction of rendering logic into renderContent() and conditional wrapper logic allows the component to work both with and without React Router while maintaining the same UI structure and functionality.


54-60: Well-designed conditional navigation logic.

The handleBackClick callback properly handles both routing scenarios with clear conditional logic. The use of useCallback with appropriate dependencies is correct.


115-123: Clean separation of routing modes.

The conditional rendering based on routerDisabled cleanly separates the two navigation modes while reusing the same content rendering logic.


62-113: Good refactoring with renderContent function.

Moving the rendering logic into a reusable renderContent function that accepts an optional history parameter is a clean solution that avoids code duplication between routing modes.

src/elements/content-sidebar/versions/StaticVersionSidebar.js (11)

17-21: Consistent imports and setup with VersionsSidebar.

The import structure and React hook usage align perfectly with the pattern established in VersionsSidebar, promoting consistency across the codebase.

Also applies to: 27-27


30-35: Proper prop typing for navigation features.

The new props follow the same pattern as VersionsSidebar with appropriate optional typing, ensuring backward compatibility and type safety.


65-71: Consistent navigation logic implementation.

The handleBackClick implementation matches the pattern in VersionsSidebar exactly, ensuring consistent behavior across both static and dynamic version sidebar components.


131-135: Identical conditional rendering pattern.

The conditional rendering logic perfectly mirrors VersionsSidebar, maintaining consistency in how router-disabled mode is handled across all version sidebar components.


98-105: Correct prop passing to VersionsMenu.

The props are properly forwarded to VersionsMenu, ensuring the navigation behavior is consistent throughout the component hierarchy.


17-21: Consistent prop additions align with VersionsSidebar.

The new props and types match those added to VersionsSidebar, ensuring consistent API across both sidebar components.

Also applies to: 30-36


65-71: Consistent navigation logic across sidebar components.

The handleBackClick implementation matches the pattern used in VersionsSidebar, ensuring consistent behavior between static and dynamic sidebar components.


73-135: Consistent refactoring pattern maintains component identity.

The refactoring follows the same pattern as VersionsSidebar while preserving the component's unique static content and upsell functionality. This ensures consistent navigation behavior across both sidebar variants.


65-71: Consistent implementation with VersionsSidebar.

The handleBackClick implementation matches the pattern used in VersionsSidebar.js, providing consistent behavior across components.


131-135: Proper conditional rendering implementation.

The routing mode separation follows the same clean pattern as the main VersionsSidebar component, ensuring consistent behavior.


73-129: Good code reuse with renderContent function.

The extracted renderContent function maintains the same structure as the corresponding component, enabling clean separation between routing and non-routing modes.

jankowiakdawid
jankowiakdawid previously approved these changes Jun 23, 2025
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

♻️ Duplicate comments (2)
src/elements/content-sidebar/versions/VersionsSidebar.js (1)

53-63: Component extraction follows established patterns but consider the noted anti-pattern concern.

Based on past review comments, defining components inside other components was flagged as an anti-pattern. However, this implementation appears to be a transitional approach during migration.

The component signature and prop destructuring are well-organized and type-safe.

src/elements/content-sidebar/versions/StaticVersionSidebar.js (1)

48-56: Component extraction maintains consistency with VersionsSidebar pattern.

The StaticVersionsContent component follows the same extraction pattern as VersionsContent, which addresses the migration needs despite the noted anti-pattern concern from past reviews.

🧹 Nitpick comments (1)
src/elements/content-sidebar/versions/StaticVersionSidebar.js (1)

143-155: Address the variable redeclaration issue flagged by static analysis.

The static analysis tool correctly identifies that routerDisabled is being redeclared. While the logic is correct, the destructuring creates an unnecessary redeclaration.

Apply this diff to avoid the redeclaration:

 const StaticVersionsSidebar = (props: Props): React.Node => {
-    const { routerDisabled } = props;
-
-    if (routerDisabled) {
+    if (props.routerDisabled) {
         return <StaticVersionsContent {...props} />;
     }
 
     return (
         <Route>
             {({ history }) => <StaticVersionsContent {...props} history={history} />}
         </Route>
     );
 };

Alternatively, if you prefer to keep the destructuring for readability, you could rename the destructured variable to avoid the warning.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e38028f and 050f336.

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

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 56-56: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 143-143: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 144-144: Shouldn't redeclare 'routerDisabled'. Consider to delete it or rename it.

'routerDisabled' is defined here:

(lint/suspicious/noRedeclare)

src/elements/content-sidebar/versions/VersionsSidebar.js

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 131-131: 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 (1)
  • GitHub Check: Summary
🔇 Additional comments (13)
src/elements/content-sidebar/versions/VersionsSidebar.js (7)

19-19: Import statement is correct despite static analysis warning.

The static analysis tool flags this as TypeScript syntax, but this is a Flow-typed JavaScript file (indicated by @flow comment), where import type is valid syntax.


22-22: Good practice: destructuring useCallback at module level.

Extracting useCallback from React improves readability and follows React hooks best practices.


26-37: Type definitions are well-structured and comprehensive.

The Props type correctly includes all the new optional navigation-related properties with appropriate typing.


39-51: VersionsContentProps type definition is appropriate.

The type includes history?: any for optional router history and all necessary navigation props. The any type for history is acceptable here as it matches React Router's typing patterns.


69-75: Navigation logic is correctly implemented with proper conditional handling.

The handleBackClick callback properly handles both routing scenarios:

  • When routerDisabled is true: uses internal navigation handler
  • When routing is enabled: uses React Router's history.push
  • Includes proper null checks and dependency array for useCallback

The logic correctly prioritizes the routing mode and handles the navigation appropriately.


108-113: Props forwarding to VersionsMenu is correctly implemented.

The component properly passes the new routerDisabled and internalSidebarNavigation props to VersionsMenu, ensuring consistent navigation behavior throughout the component tree.


131-143: Conditional rendering logic is clean and follows the intended pattern.

The main component correctly:

  • Extracts routerDisabled from props
  • Returns VersionsContent directly when routing is disabled
  • Wraps VersionsContent in Route when routing is enabled, providing history via render prop

This approach maintains backward compatibility while supporting the new router-less mode.

src/elements/content-sidebar/versions/StaticVersionSidebar.js (6)

17-21: Import types are correctly defined despite static analysis warning.

Similar to the other file, this is Flow-typed JavaScript where import type syntax is valid. The imported types are necessary for the new navigation functionality.


27-27: Consistent React hooks usage.

Good practice to destructure useCallback from React at module level, maintaining consistency with the VersionsSidebar implementation.


29-36: Props type definition is comprehensive and well-structured.

The type includes all necessary navigation-related properties with appropriate optional typing, consistent with the VersionsSidebar implementation.


38-46: StaticVersionsContentProps type is appropriately defined.

The type structure mirrors the VersionsContentProps from the other file, maintaining consistency across the refactoring.


76-82: Navigation logic is identical and correctly implemented.

The handleBackClick implementation is consistent with VersionsSidebar, properly handling both routing modes with appropriate conditional logic and dependency management.


109-116: Props forwarding to VersionsMenu maintains consistency.

The component correctly passes the new navigation-related props to VersionsMenu, ensuring consistent behavior across both sidebar implementations.

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 (1)
src/elements/content-sidebar/versions/VersionsSidebar.js (1)

69-75: Consider extracting shared navigation logic.

Both VersionsSidebar and StaticVersionSidebar implement identical handleBackClick logic. Consider creating a shared custom hook or utility function to reduce code duplication:

// utils/useBackNavigation.js
const useBackNavigation = (parentName, routerDisabled, internalSidebarNavigationHandler, history) => {
    return useCallback(() => {
        if (routerDisabled && internalSidebarNavigationHandler) {
            internalSidebarNavigationHandler({ sidebar: parentName });
        } else if (!routerDisabled && history) {
            history.push(`/${parentName}`);
        }
    }, [parentName, routerDisabled, internalSidebarNavigationHandler, history]);
};

This would eliminate duplication and centralize the navigation logic maintenance.

Also applies to: 76-82

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e38028f and 050f336.

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

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)

src/elements/content-sidebar/versions/StaticVersionSidebar.js

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 56-56: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 143-143: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 144-144: Shouldn't redeclare 'routerDisabled'. Consider to delete it or rename it.

'routerDisabled' is defined here:

(lint/suspicious/noRedeclare)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (18)
src/elements/content-sidebar/versions/StaticVersionSidebar.js (9)

17-21: LGTM: Type imports are correctly structured.

The type imports are properly organized and align with the new navigation functionality being introduced.


27-27: LGTM: useCallback import follows React best practices.

Proper destructuring of useCallback from React for the navigation handler.


29-36: LGTM: Props type definition is well-structured.

The new props for internal navigation support are properly typed and optional where appropriate. The parentName type change from string to ViewTypeValues adds better type safety.


38-46: LGTM: StaticVersionsContentProps type definition is comprehensive.

The props type includes all necessary properties for both router and router-disabled modes, with appropriate optional flags.


48-56: LGTM: Component extraction follows good separation of concerns.

The StaticVersionsContent component properly accepts all required props and maintains clear boundaries between routing and content logic.


76-82: LGTM: Navigation logic correctly handles both routing modes.

The handleBackClick callback properly:

  • Uses useCallback for performance optimization
  • Implements conditional navigation based on routerDisabled flag
  • Includes proper dependency array
  • Handles both internal navigation and router navigation paths

94-97: LGTM: BackButton integration is clean.

The BackButton properly uses the handleBackClick callback and maintains the data-resin-target attribute for analytics.


109-116: LGTM: VersionsMenu receives appropriate props for navigation support.

The VersionsMenu component correctly receives the routerDisabled and internalSidebarNavigation props to support the new navigation mode.


143-155: LGTM: Conditional rendering pattern is well-implemented.

The main component correctly:

  • Conditionally renders StaticVersionsContent directly when routing is disabled
  • Wraps with Route component to provide history when routing is enabled
  • Maintains clean separation between routing and non-routing modes
src/elements/content-sidebar/versions/VersionsSidebar.js (9)

19-19: LGTM: Type imports are consistent with StaticVersionSidebar.

The import statement correctly includes the necessary types for internal navigation support, maintaining consistency across both sidebar components.


22-22: LGTM: useCallback import follows established pattern.

Consistent with the StaticVersionSidebar implementation.


26-37: LGTM: Props type definition maintains consistency.

The Props type correctly mirrors the navigation-related props added to StaticVersionSidebar, ensuring a consistent API across both components.


39-51: LGTM: VersionsContentProps type is comprehensive.

The type definition includes all necessary props for both routing modes and maintains consistency with the StaticVersionSidebar pattern.


53-63: LGTM: Component extraction follows established pattern.

The VersionsContent component extraction is consistent with the StaticVersionSidebar approach and properly destructures the required props.


69-75: LGTM: Navigation logic is consistent and correct.

The handleBackClick implementation:

  • Matches the pattern established in StaticVersionSidebar
  • Properly handles both internal navigation and router navigation
  • Uses correct dependency array for useCallback
  • Maintains consistent conditional logic

84-84: LGTM: BackButton integration is consistent.

The BackButton usage matches the StaticVersionSidebar implementation with proper callback binding.


108-113: LGTM: VersionsMenu props are consistent with StaticVersionSidebar.

The VersionsMenu component receives the same navigation-related props as in StaticVersionSidebar, maintaining API consistency.


131-143: LGTM: Conditional rendering pattern matches StaticVersionSidebar.

The main component implementation is consistent with the StaticVersionSidebar approach:

  • Same conditional rendering logic based on routerDisabled
  • Proper Route wrapper when routing is enabled
  • Clean separation of concerns

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 (4)
src/elements/content-sidebar/versions/StaticVersionSidebar.js (2)

143-154: Clean conditional rendering approach, but consider simplifying variable destructuring.

The conditional rendering logic is well-structured. However, there's a minor issue with variable redeclaration.

Consider this cleaner approach to avoid the redeclaration warning:

-const StaticVersionsSidebar = (props: Props): React.Node => {
-    const { routerDisabled } = props;
-
-    if (routerDisabled) {
+const StaticVersionsSidebar = (props: Props): React.Node => {
+    if (props.routerDisabled) {
         return <StaticVersionsContent {...props} />;
     }

38-46: Consider improving type safety for the history prop.

The history prop is typed as any, which reduces type safety. Consider using a more specific type from react-router-dom if available.

type StaticVersionsContentProps = {
    error?: MessageDescriptor,
    fileId: string,
-   history?: any,
+   history?: { push: (path: string) => void },
    // ... rest of props
};
src/elements/content-sidebar/versions/VersionsSidebar.js (2)

131-142: Consider consolidating the duplicate conditional rendering pattern.

Both VersionsSidebar and StaticVersionsSidebar implement identical conditional rendering logic. Consider extracting this pattern into a higher-order component or custom hook to reduce duplication.

Example approach using a custom hook:

const useConditionalRouter = (routerDisabled, ContentComponent, props) => {
    if (routerDisabled) {
        return <ContentComponent {...props} />;
    }
    
    return (
        <Route>
            {({ history }) => <ContentComponent {...props} history={history} />}
        </Route>
    );
};

39-51: Consider consistent type safety improvement for history prop.

Similar to StaticVersionSidebar, the history prop is typed as any. For consistency and better type safety, consider using a more specific type.

type VersionsContentProps = {
    error?: MessageDescriptor,
    fileId: string,
-   history?: any,
+   history?: { push: (path: string) => void },
    // ... rest of props
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 050f336 and 3881cb7.

📒 Files selected for processing (4)
  • src/elements/content-sidebar/versions/StaticVersionSidebar.js (2 hunks)
  • src/elements/content-sidebar/versions/VersionsSidebar.js (1 hunks)
  • src/elements/content-sidebar/versions/__tests__/StaticVersionSidebar.test.js (4 hunks)
  • src/elements/content-sidebar/versions/__tests__/VersionsSidebar.test.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/elements/content-sidebar/versions/tests/StaticVersionSidebar.test.js
  • src/elements/content-sidebar/versions/tests/VersionsSidebar.test.js
🧰 Additional context used
🪛 Biome (1.9.4)
src/elements/content-sidebar/versions/StaticVersionSidebar.js

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 56-56: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 143-143: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 144-144: Shouldn't redeclare 'routerDisabled'. Consider to delete it or rename it.

'routerDisabled' is defined here:

(lint/suspicious/noRedeclare)

src/elements/content-sidebar/versions/VersionsSidebar.js

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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


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

TypeScript only syntax

(parse)


[error] 131-131: 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 (4)
  • GitHub Check: Rule: Automatic merge queue (queue)
  • GitHub Check: lint_test_build
  • GitHub Check: Summary
  • GitHub Check: Queue: Embarked in merge queue
🔇 Additional comments (16)
src/elements/content-sidebar/versions/StaticVersionSidebar.js (8)

17-21: LGTM: Type imports properly added for new navigation functionality.

The new type imports support the optional router functionality and maintain type safety with Flow.


29-36: LGTM: Props type definition correctly expanded for optional router support.

The new optional props properly support both router-enabled and router-disabled modes while maintaining backward compatibility.


48-56: Good separation of concerns with extracted content component.

Extracting the main content into StaticVersionsContent provides a clean separation between routing logic and UI rendering, making the code more maintainable.


76-82: Well-implemented conditional navigation logic.

The handleBackClick callback correctly handles both routing scenarios:

  • Uses internal navigation handler when router is disabled
  • Falls back to React Router when enabled

The useCallback optimization is appropriate here since the callback depends on multiple props.


17-21: Type imports look appropriate for the new functionality.

The imported types support the new internal navigation feature and provide proper typing for the refactored component structure.


76-82: Back button navigation logic is well-implemented.

The useCallback hook is properly used with correct dependencies, and the conditional logic appropriately handles both router-enabled and router-disabled navigation scenarios.


109-116: Props are correctly passed to VersionsMenu.

The new routerDisabled and internalSidebarNavigation props are properly forwarded to support the internal navigation functionality.


143-155: Conditional rendering pattern is clean and effective.

The wrapper component appropriately handles both router-enabled and router-disabled modes by conditionally rendering the content component directly or wrapped in a Route component.

src/elements/content-sidebar/versions/VersionsSidebar.js (8)

19-19: LGTM: Consistent type imports across sidebar components.

The type imports align with the StaticVersionSidebar implementation, maintaining consistency across the codebase.


53-63: Good architectural consistency with StaticVersionSidebar.

The extracted VersionsContent component follows the same pattern as StaticVersionsContent, providing consistent behavior across both sidebar components.


69-75: Consistent navigation logic implementation.

The handleBackClick implementation mirrors the StaticVersionSidebar approach, ensuring uniform behavior across both components. The conditional logic properly handles both routing modes.


108-113: Props correctly passed to VersionsMenu for router support.

The routerDisabled and internalSidebarNavigation props are properly forwarded to the VersionsMenu component, enabling it to handle the new navigation modes.


19-19: Type imports are consistent and appropriate.

The imported types align with the StaticVersionSidebar implementation and support the new internal navigation functionality effectively.


69-75: Navigation handling logic is consistent and correct.

The handleBackClick implementation mirrors the StaticVersionSidebar approach, ensuring consistent behavior across both sidebar components.


108-113: Props forwarding to VersionsMenu is properly implemented.

The new navigation-related props are correctly passed through to support the internal navigation functionality.


131-143: Wrapper component follows the established pattern.

The conditional rendering logic is consistent with StaticVersionSidebar, maintaining a unified approach to handling router-enabled and router-disabled modes across both sidebar components.

@mergify
Copy link
Contributor

mergify bot commented Jun 24, 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.

3 participants