Extract InfiniteScrollList business logic into InfiniteScrollListViewModel#7240
Draft
Extract InfiniteScrollList business logic into InfiniteScrollListViewModel#7240
Conversation
…Model, establishing MVVM pattern with XAML bindings and unit tests
Contributor
|
This PR contains changes to XAML files. Verify that you've completed the following tasks:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Fixes: https://github.com/NuGet/Client.Engineering/issues/3700
Description
Extract InfiniteScrollList business logic into InfiniteScrollListViewModel
Summary
Extracts all business logic from
InfiniteScrollList.xaml.cs(860 lines) into a newInfiniteScrollListViewModel(714 lines), reducing the codebehind to ~200 lines of WPF-specific plumbing. The ViewModel has no WPF type references and is fully unit-testable.This is the first step in addressing https://github.com/NuGet/Client.Engineering/issues/2539 (business logic in codebehind). Further improvements are tracked in https://github.com/NuGet/Client.Engineering/issues/3702
Design decisions
HasUpdatablePackages(notIsUpdateContainerVisible),HasSelectedPackages(notIsUpdateEnabled),SelectionState(notSelectAllChecked),IsUpdateMode(notCheckBoxesEnabled)LoadingStatusBar.Reset()/SetError()/SetCancelled()replace their ownDataContextwith new objects — fundamentally imperative, can't be XAML bindings. Delegates are wired in the constructor (notLoaded) becausePackageManagerControlcallsLoadItemsAsyncduring initializationTopLevelPackageCount/TransitivePackageCountstay on the codebehind: They useCollectionViewGroup.ItemCountwhich reflects filtered counts. LINQ-based counts on the ViewModel would show unfiltered totals — wrong when vulnerability filter is activePackageManagerControlaccesses_packageList.ViewModeldirectly: Eliminates passthrough properties on the control. Both types are internal to the same assemblyBooleanToVisibilityConverterandBooleanToHiddenVisibilityConverterfromResources.xamlinstead of defining new onesTesting
New unit tests in
InfiniteScrollListViewModelTests.cscovering:LoadItemsAsyncparameter validation and cancellationHasTransitiveItemsdetectionResolveSelectedItem: by ID, not found, nullShouldShowStatusBarfor cancelled/error/ready/null statesPre-existing issue found
Group header package counts (
TopLevelPackageCount/TransitivePackageCount) intermittently show 0 when the vulnerability filter is active. This is a pre-existing bug ondev— the plain CLR getters have no change notification mechanism, andCollectionViewGroupmay not be fully rebuilt when the binding re-evaluates. Tracked separately.PR Checklist
Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.