Skip to content

doc(TreeView): update sample code prevent page not avaliable#7828

Merged
ArgoZhang merged 1 commit intomainfrom
fix-tv
Apr 2, 2026
Merged

doc(TreeView): update sample code prevent page not avaliable#7828
ArgoZhang merged 1 commit intomainfrom
fix-tv

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Apr 2, 2026

Link issues

fixes #7827

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

Ensure TreeView draggable sample uses an instance-level data source instead of shared static state to avoid cross-page interference.

Bug Fixes:

  • Prevent TreeView draggable demo from sharing drag source data across pages by using an instance-local item collection as the data source.

Enhancements:

  • Simplify TreeView sample data initialization and make IconItems instance-scoped for consistency with other demo item collections.

Copilot AI review requested due to automatic review settings April 2, 2026 02:47
@bb-auto bb-auto bot added the documentation Improvements or additions to documentation label Apr 2, 2026
@bb-auto bb-auto bot added this to the v10.5.0 milestone Apr 2, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 2, 2026

Reviewer's Guide

Refactors the TreeView drag-and-drop demo to use an instance-scoped source list and non-static icon items, ensuring consistent state updates when dragging nodes while simplifying the draggable item factory method.

Sequence diagram for updated TreeView drag-and-drop handling

sequenceDiagram
    actor User
    participant TreeViewComponent
    participant TreeViews
    participant DraggableSourceItems

    User->>TreeViewComponent: drag node and drop on target
    TreeViewComponent->>TreeViews: OnDragItemEndAsync(context)
    activate TreeViews

    TreeViews->>DraggableSourceItems: find source by context.Source.Value.Id
    DraggableSourceItems-->>TreeViews: source TreeFoo

    TreeViews->>DraggableSourceItems: find target by context.Target.Value.Id
    DraggableSourceItems-->>TreeViews: target TreeFoo

    TreeViews->>TreeViews: update source.ParentId and ordering
    TreeViews->>TreeViews: DraggableItems = TreeFoo.CascadingTree(DraggableSourceItems, callback)

    TreeViews-->>TreeViewComponent: updated DraggableItems
    deactivate TreeViews

    TreeViewComponent-->>User: render updated TreeView
Loading

File-Level Changes

Change Details Files
Refactor draggable TreeView sample to use an instance-level source list instead of recreating or caching static data.
  • Introduce DraggableSourceItems as an instance property initialized from GetDraggableItems()
  • Update OnInitialized to build DraggableItems from DraggableSourceItems instead of a freshly created list
  • Update OnDragItemEndAsync to find and manipulate source/target nodes within DraggableSourceItems
  • Rebuild DraggableItems from DraggableSourceItems after drag operations while preserving expansion logic
src/BootstrapBlazor.Server/Components/Samples/TreeViews.razor.cs
Align TreeView sample properties and helpers with instance-based patterns and simplify the draggable item factory.
  • Change IconItems from static settable property to an instance get-only property initialized via TreeFoo.GetTreeItems()
  • Replace the previously cached static _dragItems pattern with a simple static GetDraggableItems() method that returns a new list literal of TreeFoo items
src/BootstrapBlazor.Server/Components/Samples/TreeViews.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7827 Update the TreeView sample component code so that the draggable TreeView no longer causes a 'page not available' or runtime error (by fixing how the draggable data source is managed).
#7827 Ensure the TreeView sample/demo code is valid and reflects the correct usage pattern for draggable items and icon items in the documentation/site.

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

Copy link
Copy Markdown
Contributor

@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 - I've reviewed your changes and they look great!


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.

@ArgoZhang ArgoZhang merged commit d49b19e into main Apr 2, 2026
6 checks passed
@ArgoZhang ArgoZhang deleted the fix-tv branch April 2, 2026 02:48
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b133314) to head (7b6082d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7828   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          764       764           
  Lines        34142     34142           
  Branches      4701      4701           
=========================================
  Hits         34142     34142           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
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

Updates the TreeView sample component to avoid shared/static state in the draggable TreeView demo, which can lead to invalid demo data and navigation failures (“page not available”) across sessions.

Changes:

  • Introduces a per-component DraggableSourceItems data source and reuses it during drag operations.
  • Removes the previously cached static draggable items list and makes IconItems instance-scoped.
Comments suppressed due to low confidence (2)

src/BootstrapBlazor.Server/Components/Samples/TreeViews.razor.cs:96

  • DraggableItems[0] is accessed unconditionally. If CascadingTree(DraggableSourceItems) ever returns an empty list (e.g., source data ends up with no root nodes), this will throw and break the sample page. Guard with if (DraggableItems.Count > 0) before indexing, and apply the same pattern to the subsequent [1]/[2] expansions.
        DraggableItems = TreeFoo.CascadingTree(DraggableSourceItems);
        DraggableItems[0].IsExpand = true;
        if (DraggableItems.Count > 1)
        {
            DraggableItems[1].IsExpand = true;
        }

src/BootstrapBlazor.Server/Components/Samples/TreeViews.razor.cs:140

  • After rebuilding DraggableItems, the code indexes DraggableItems[0] without checking Count. A drag operation can potentially result in a hierarchy with no root nodes, making CascadingTree return an empty list and causing an IndexOutOfRangeException. Add a Count > 0 guard (and keep the existing Count > 1/2 checks) before setting IsExpand.
        DraggableItems = TreeFoo.CascadingTree(DraggableSourceItems, cb);
        DraggableItems[0].IsExpand = true;
        if (DraggableItems.Count > 1)
        {
            DraggableItems[1].IsExpand = true;
        }

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc(TreeView): update sample code prevent page not avaliable

2 participants