Skip to content

Conversation

@JayashTripathy
Copy link
Member

@JayashTripathy JayashTripathy commented Oct 31, 2025

Description

This pull request improves the handling of collapsed group state in both the Kanban and List base layouts by allowing external control of group collapse state and toggle behavior. The changes make it possible for parent components to manage collapsed groups and toggle actions, or to let the layouts manage them internally if not provided. Additionally, it updates the LayoutSwitcher prop type for consistency.

State management improvements for base layouts:

  • Updated BaseKanbanLayout and BaseListLayout to accept optional collapsedGroups and onToggleGroup props, enabling external or internal state management for collapsed groups depending on whether these props are provided.

Type consistency:

  • Changed the selectedLayout prop in LayoutSwitcher to be required instead of optional, ensuring that a selected layout is always specified.

Type of Change

  • Code refactoring

Summary by CodeRabbit

  • Refactor
    • Enhanced layout state management for Kanban and List components with optional external mode support for collapsed groups control
    • Improved type safety in LayoutSwitcher by requiring selectedLayout parameter

- Introduced BASE_LAYOUTS constant for layout configuration.
- Implemented LayoutSwitcher component for selecting layouts.
- Added hooks for group drop targets and layout state management.
- Created kanban and list components with group and item rendering.
- Integrated drag-and-drop functionality for items within groups.
- Updated translations for empty states and drag-and-drop messages.
…d improve drag-and-drop validation

- Modified GroupHeader to accept itemCount and onToggleGroup props.
- Updated useGroupDropTarget to enhance drop validation logic for items.
- Refactored group components to align with new IGroupHeaderProps interface.
…gleGroup usage in BaseKanbanGroup

- Streamlined the onDrop prop definition in useGroupDropTarget for clarity.
- Replaced local handleToggle function with direct onToggleGroup prop usage in BaseKanbanGroup.
… modes

- Changed UseLayoutStateProps to a union type for better clarity on external and internal modes.
- Simplified the useLayoutState hook to conditionally use external state and handlers based on the mode.
- Ensured auto-scroll functionality respects the new props structure.
- Eliminated unnecessary comment regarding the use of external state/handlers in the useLayoutState hook for improved code clarity.
…apsedGroups and onToggleGroup

- Updated BaseKanbanLayout and BaseListLayout to provide default values for collapsedGroups and onToggleGroup props.
- Set mode to "external" in useLayoutState for both components to improve state management.
…apsedGroups and onToggleGroup

- Modified BaseKanbanLayout and BaseListLayout to remove default values for collapsedGroups and onToggleGroup, making them required props.
- Enhanced useLayoutState to conditionally set the mode based on the presence of external props, improving flexibility in layout management.
Copilot AI review requested due to automatic review settings October 31, 2025 12:00
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 31, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

The changes introduce conditional external/internal mode selection for layout state management in Kanban and List layout components, where external mode activates when both control props are provided, and refine type safety by requiring selectedLayout in LayoutSwitcher to be non-optional.

Changes

Cohort / File(s) Summary
External/Internal Mode Selection
apps/web/core/components/base-layouts/kanban/layout.tsx, apps/web/core/components/base-layouts/list/layout.tsx
Introduces conditional mode selection: if both external state-control props are provided, the component uses "external" mode and passes them to useLayoutState; otherwise it uses "internal" mode with default behavior. Removes default values from collapsedGroups and onToggleGroup destructuring, deferring mode determination to runtime checks.
Type Tightening
apps/web/core/components/base-layouts/layout-switcher.tsx
Changes selectedLayout prop type from TBaseLayoutType | undefined to TBaseLayoutType, eliminating the possibility of undefined and ensuring a layout is always selected.

Sequence Diagram

sequenceDiagram
    actor Parent
    participant Layout as Kanban/List Layout
    participant useLayoutState
    
    Parent->>Layout: Render with props
    
    alt External Mode (both props provided)
        Layout->>Layout: useExternalMode = true
        Layout->>useLayoutState: Pass externalCollapsedGroups<br/>& externalOnToggleGroup<br/>with mode: "external"
        useLayoutState-->>Layout: Return external state
    else Internal Mode (props missing)
        Layout->>Layout: useExternalMode = false
        Layout->>useLayoutState: No external props<br/>with mode: "internal"
        useLayoutState-->>Layout: Return internal state
    end
    
    Layout-->>Parent: Render with selected mode
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Kanban and List layouts: Review the mode-selection logic and verify that external/internal branching is consistent and correctly gates prop usage across both components
  • LayoutSwitcher type change: Confirm that all callers now always provide a non-undefined selectedLayout value to avoid runtime errors
  • Prop destructuring changes: Ensure removal of defaults doesn't break fallback behavior for optional props in internal mode

Poem

🐰 Two paths unfold before the layout's gaze,
External or internal—let the props ablaze!
When both controls arrive, the outer way we take,
Else inward we retreat for safety's sake. 🎪✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description includes a well-detailed "Description" section explaining the state management improvements and type consistency changes, and properly marks the type of change as "Code refactoring." However, the description is missing two required sections from the template: "Test Scenarios" (which should describe the tests run to verify the changes) and "References" (which should link related issues if applicable). While the core information is present, these required template sections are entirely absent, making the description incomplete against the specified template requirements. Please add the missing sections to the PR description. Include a "Test Scenarios" section that describes how these refactoring changes were tested and verified (e.g., which components were tested to ensure external and internal state management work correctly). Also add a "References" section if there are any related issues or pull requests that should be linked to this change.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "[WEB-5306] refactor: base layouts" directly addresses the changeset, which involves refactoring the Kanban layout, List layout, and LayoutSwitcher components to support external vs internal control of collapsed group state. The title is clear, concise, and accurately describes the nature of the changes as a refactoring of base layout components. While the title is somewhat broad and doesn't specify the particular improvement (external control of collapsed groups), it still conveys the primary change that a teammate scanning PR history would understand at a glance.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/base-layouts

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the layout components to support both internal and external state management for collapsed groups. The changes make the collapsedGroups and onToggleGroup props optional, allowing components to manage their own internal state when these props are not provided.

  • Removed default values for collapsedGroups and onToggleGroup props, making them truly optional
  • Added runtime checks to conditionally use external or internal mode based on whether props are provided
  • Updated selectedLayout type in LayoutSwitcher to be non-nullable

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
apps/web/core/components/base-layouts/list/layout.tsx Implements conditional mode selection for useLayoutState based on presence of external props
apps/web/core/components/base-layouts/layout-switcher.tsx Removes undefined union from selectedLayout prop type
apps/web/core/components/base-layouts/kanban/layout.tsx Implements conditional mode selection for useLayoutState based on presence of external props

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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)
apps/web/core/components/base-layouts/kanban/layout.tsx (1)

27-38: Extract shared mode-switching logic to reduce duplication.

This exact mode-switching pattern (lines 27-38) is duplicated in apps/web/core/components/base-layouts/list/layout.tsx (lines 26-37). Consider extracting it into a shared utility function or custom hook to improve maintainability.

Example:

const useExternalModeConfig = (
  externalCollapsedGroups?: string[],
  externalOnToggleGroup?: (groupId: string) => void
) => {
  const useExternalMode = externalCollapsedGroups !== undefined && externalOnToggleGroup !== undefined;
  return useExternalMode
    ? { mode: "external" as const, externalCollapsedGroups, externalOnToggleGroup }
    : { mode: "internal" as const };
};
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 961cdf6 and 77ce05f.

📒 Files selected for processing (3)
  • apps/web/core/components/base-layouts/kanban/layout.tsx (1 hunks)
  • apps/web/core/components/base-layouts/layout-switcher.tsx (1 hunks)
  • apps/web/core/components/base-layouts/list/layout.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
apps/web/core/components/base-layouts/layout-switcher.tsx (1)
packages/types/src/base-layouts/base.ts (1)
  • TBaseLayoutType (55-55)
apps/web/core/components/base-layouts/kanban/layout.tsx (1)
apps/web/core/components/base-layouts/hooks/use-layout-state.ts (1)
  • useLayoutState (22-58)
apps/web/core/components/base-layouts/list/layout.tsx (1)
apps/web/core/components/base-layouts/hooks/use-layout-state.ts (1)
  • useLayoutState (22-58)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: CodeQL analysis (javascript-typescript)
  • GitHub Check: Build and lint web apps
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
apps/web/core/components/base-layouts/layout-switcher.tsx (1)

12-12: LGTM! Improved type safety.

Making selectedLayout required prevents potential runtime errors and aligns with the component's actual usage, which never checks for undefined values.

apps/web/core/components/base-layouts/kanban/layout.tsx (2)

23-24: LGTM! Clear prop naming for external control.

The external prefix clearly indicates these props enable external control of collapse state, distinguishing them from internal state management.


27-38: Mode switching logic is correct, but consider edge case documentation.

The logic correctly requires both externalCollapsedGroups and externalOnToggleGroup to enable external mode. However, if a developer provides only one prop, it silently falls back to internal mode, which could be unexpected.

Consider adding a development-mode warning or documenting this "all-or-nothing" requirement.

apps/web/core/components/base-layouts/list/layout.tsx (2)

20-21: LGTM! Consistent with kanban layout.

The prop renaming and removal of defaults matches the pattern in kanban/layout.tsx, providing a consistent API across layout types.


26-37: Mode switching logic is correct and consistent.

The implementation mirrors the kanban layout's approach and correctly requires both external props for external mode. The same considerations about partial prop provision and code duplication noted in kanban/layout.tsx apply here as well.

@JayashTripathy JayashTripathy changed the title refactor: base layouts [WEB-5306] refactor: base layouts Oct 31, 2025
@makeplane
Copy link

makeplane bot commented Oct 31, 2025

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

@pushya22 pushya22 merged commit 0a738d4 into preview Nov 6, 2025
6 of 7 checks passed
@pushya22 pushya22 deleted the refactor/base-layouts branch November 6, 2025 14:15
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