Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeViewItem: Throw exception when ItemTemplate is misconfigured #8867

Merged
merged 3 commits into from
May 3, 2024

Conversation

Taylan2020
Copy link
Contributor

Description

I'm creating this PR in reference to my previously deleted PR #8168.

@henon fix is now ready to merge for v7. Thanks.

This TreeView-bug only occurs when TreeView.ServeData is used with a custom ItemTemplate.

The parent node reference passed to the MudTreeView.ServerData delegate function is ALWAYS null when the parameter > 'Value' is NOT set in the customized MudTreeViewItems-Template. To fix this issue an exception is thrown when the parameter

MudTreeView.ServerData is set with MudTreeViewItem.Value & > MudTreeViewItem.Text unset.

MudTreeView.Text needs to be null to make sure the TreeViewItem is not only supplied with a display text - in which case the parentNode would be null anyways.

See Ticket #7156 for bug reproduction - still present in latest release v6.0.15.

How Has This Been Tested?

Unit test is included in the comit covering the same scenario from Ticket #7156.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added breaking change bug Something does not work as intended/expected PR: needs review labels May 3, 2024
Copy link

codecov bot commented May 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.13%. Comparing base (28bc599) to head (5819059).
Report is 135 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8867      +/-   ##
==========================================
+ Coverage   89.82%   90.13%   +0.30%     
==========================================
  Files         412      421       +9     
  Lines       11878    12304     +426     
  Branches     2364     2431      +67     
==========================================
+ Hits        10670    11090     +420     
+ Misses        681      665      -16     
- Partials      527      549      +22     

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

Comment on lines +334 to +341
protected override void OnParametersSet()
{
base.OnParametersSet();

if (Text == null && (Value == null && MudTreeRoot?.ServerData != null))
throw new InvalidOperationException(
$"'{nameof(MudTreeView<T>)}.{nameof(MudTreeRoot.ServerData)}' requires '{nameof(MudTreeRoot.ItemTemplate)}.{nameof(MudTreeViewItem<T>)}.{nameof(Value)}' to be supplied.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Taylan2020 for a && b && c you don't need brackets.

@ScarletKuro is this OK or should we use the state framework for this?

Copy link
Member

Choose a reason for hiding this comment

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

I guess it's fine for this case.

Copy link
Collaborator

@henon henon left a comment

Choose a reason for hiding this comment

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

In principle this is mergable. I just want to get a second opinion from @ScarletKuro

@henon henon merged commit 1ef6a7e into MudBlazor:dev May 3, 2024
4 checks passed
@henon
Copy link
Collaborator

henon commented May 3, 2024

lol, while searching for the the thing to fix I stumbled accross this:

        protected override async Task OnInitializedAsync()
        {
            if (Parent != null)
            {
                Parent.AddChild(this);
            }
            else
            {
                if (MudTreeRoot is not null)
                {
                    await MudTreeRoot.AddChildAsync(this);
                }
            }
            base.OnInitialized();
        }

OnInitializedAsync() calls base.OnInitialized()

Guess that was an oversight by me in an earlier PR

henon added a commit that referenced this pull request May 3, 2024
@henon
Copy link
Collaborator

henon commented May 3, 2024

Thanks @Taylan2020 !

henon added a commit that referenced this pull request May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change bug Something does not work as intended/expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants