Skip to content

fix(DockView): wrong position when switch visible#480

Merged
ArgoZhang merged 4 commits intomasterfrom
feat-dockview
Jun 30, 2025
Merged

fix(DockView): wrong position when switch visible#480
ArgoZhang merged 4 commits intomasterfrom
feat-dockview

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Jun 30, 2025

Link issues

fixes #479

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Fix incorrect panel positioning when toggling visibility by preserving visibility state throughout configuration, tree construction, and initialization, and by filtering out empty content.

Bug Fixes:

  • Preserve and apply panel visibility when renewing configuration to avoid wrong positions after visibility toggles.
  • Respect existing panel visible state when initializing and removing panels during dockview setup.
  • Include visible flag in panel parameters when adding panels to groups to ensure consistent visibility handling.

Enhancements:

  • Filter out empty content nodes before generating layout tree to prevent invalid branches.
  • Always register panels in getLeafNode regardless of visibility to maintain panel registry consistency.

@bb-auto bb-auto Bot added the bug Something isn't working label Jun 30, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 30, 2025

Reviewer's Guide

This PR fixes panel repositioning issues when toggling visibility by propagating visibility flags through configuration, pruning empty layout nodes, and ensuring panels are consistently registered and removed according to their visibility state.

Class diagram for updated DockView panel configuration and visibility handling

classDiagram
    class Panel {
        +id
        +title
        +renderer
        +tabComponent
        +contentComponent
        +params
    }
    class Config {
        +panels
    }
    class DockView {
        +_panelVisibleChanged
        +removePanel(panel)
    }
    Config "1" -- "*" Panel : contains
    DockView --> Panel : manages
    Panel : +visible
    Panel : +parentId
    Panel : +rect
    Panel : +packup
    DockView : +_panelVisibleChanged.fire({title, status})
    DockView : +removePanel(panel)
Loading

Flow diagram for panel visibility propagation and handling

flowchart TD
    A[User toggles panel visibility] --> B[renewConfigFromOptions propagates visible flag]
    B --> C[getConfigFromContent filters empty content]
    C --> D[getLeafNode sets panel.visible and registers panel]
    D --> E[initDockview checks panel.params.visible]
    E -- visible: false --> F[DockView removes panel]
    E -- visible: true --> G[DockView fires _panelVisibleChanged with status true]
Loading

File-Level Changes

Change Details Files
Preserve and propagate panel visibility in configuration
  • Merged original panel.params.visible into optionPanel.params.
  • Adjusted spread order to override optionPanel.params with actual visibility.
  • Stored updated optionPanel back into config.panels.
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-config.js
Filter out empty content nodes before layout generation
  • Introduced filterEmptyContent to recursively drop nodes with empty content arrays.
  • Applied filterEmptyContent at start of getConfigFromContent.
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-config.js
Always register leaf panels and normalize visibility
  • Set every leaf node’s visible flag to true.
  • Ensured views array always includes contentItem.id.
  • Removed conditional guard so panels[...] is always populated.
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-config.js
Respect panel.params.visible when initializing and removing panels
  • Checked panel.params.visible before calling removePanel.
  • Fired _panelVisibleChanged with actual visibility status.
  • Omitted firing show events for hidden panels.
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js
Default newly added panels to visible
  • Injected visible:true into params when adding panels by group.
  • Ensured panelVisibleChanged is fired as visible on addition.
src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-group.js

Assessment against linked issues

Issue Objective Addressed Explanation
#479 Fix the wrong position of DockView panels when their visibility is toggled.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added this to the v9.2.0 milestone Jun 30, 2025
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @ArgoZhang - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js:95` </location>
<code_context>
             panels.forEach(panel => {
-                dockview._panelVisibleChanged?.fire({ title: panel.title, status: true });
+                const visible = panel.params.visible
+                if(!visible){
+                    dockview.removePanel(panel)
+                }
+                dockview._panelVisibleChanged?.fire({ title: panel.title, status: visible });
</code_context>

<issue_to_address>
Removing panels with falsy 'visible' property may not distinguish between undefined and false.

Currently, panels with 'visible' undefined are also removed. To only remove panels explicitly set to not visible, use 'visible === false' instead of a falsy check.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                if(!visible){
                    dockview.removePanel(panel)
                }
=======
                if (visible === false) {
                    dockview.removePanel(panel)
                }
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js Outdated
@ArgoZhang ArgoZhang merged commit 14f2061 into master Jun 30, 2025
1 check passed
@ArgoZhang ArgoZhang deleted the feat-dockview branch June 30, 2025 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(DockView): wrong position when switch visible

2 participants