feat(EditorForm): merge Items and FieldItems parameter#7646
Conversation
Reviewer's GuideEditorForm now merges the configured Items collection with dynamically built FieldItems, giving FieldItems higher precedence, centralizing filter logic, and extending tests to cover mixed usage. Class diagram for updated EditorForm item handlingclassDiagram
class EditorForm_TModel {
+RenderFragment_TModel FieldItems
+IEnumerable~IEditorItem~ Items
+List~string~ IgnoreItems
+List~IEditorItem~ GetRenderItems()
+bool FilterEditorItem(IEditorItem i)
+bool FilterIgnoreItem(IEditorItem item)
}
class IEditorItem {
+bool GetIgnore()
+string GetFieldName()
}
EditorForm_TModel --> IEditorItem : uses
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
GetRenderItems, theItems.Where(i => _editorItems.Find(...) == null && FilterEditorItem(i))pattern performs an O(n²) scan over_editorItems; consider precomputing aHashSetof_editorItemsfield names to make the duplicate filtering logic more efficient and easier to read. - The new helper name
FilterEditorItemis slightly misleading since it also callsFilterIgnoreItem; consider renaming it to something likeIsValidItemor similar to better reflect its purpose and reduce confusion when maintaining this logic.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `GetRenderItems`, the `Items.Where(i => _editorItems.Find(...) == null && FilterEditorItem(i))` pattern performs an O(n²) scan over `_editorItems`; consider precomputing a `HashSet` of `_editorItems` field names to make the duplicate filtering logic more efficient and easier to read.
- The new helper name `FilterEditorItem` is slightly misleading since it also calls `FilterIgnoreItem`; consider renaming it to something like `IsValidItem` or similar to better reflect its purpose and reduce confusion when maintaining this logic.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7646 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 750 750
Lines 33182 33185 +3
Branches 4602 4605 +3
=========================================
+ Hits 33182 33185 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Updates EditorForm<TModel> so Items and FieldItems can be used together (instead of one disabling the other), with FieldItems taking precedence.
Changes:
- Update
EditorForm<TModel>item selection/merge logic soFieldItemsandItemsare combined. - Adjust XML docs to reflect the new parameter precedence.
- Extend the
Items_Okunit test to render with bothItemsandFieldItemsset.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs |
Merge Items and _editorItems (from FieldItems) and introduce shared filtering helper. |
test/UnitTest/Components/EditorFormTest.cs |
Update Items_Ok to include a FieldItems fragment alongside Items. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
GetRenderItems, the deduplicationHashSet<string?>for field names uses the default case-sensitive comparer whileFilterIgnoreItemuses case-insensitive comparison; consider usingStringComparer.OrdinalIgnoreCasefor theHashSetto keep behavior consistent for fields likeNamevsname. - When both
ItemsandFieldItemsare provided, the current merge logic always takes all_editorItemsafter filtering and only removesItemsentries that match existing_editorItems; if a different precedence or ordering is desired (e.g., preservingItemsorder or allowingItemsto override), it may be worth making that precedence explicit in code comments or adjusting the logic accordingly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `GetRenderItems`, the deduplication `HashSet<string?>` for field names uses the default case-sensitive comparer while `FilterIgnoreItem` uses case-insensitive comparison; consider using `StringComparer.OrdinalIgnoreCase` for the `HashSet` to keep behavior consistent for fields like `Name` vs `name`.
- When both `Items` and `FieldItems` are provided, the current merge logic always takes all `_editorItems` after filtering and only removes `Items` entries that match existing `_editorItems`; if a different precedence or ordering is desired (e.g., preserving `Items` order or allowing `Items` to override), it may be worth making that precedence explicit in code comments or adjusting the logic accordingly.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Link issues
fixes #7645
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Unify EditorForm field template and items collection so they can be used together with consistent precedence and filtering.
Enhancements:
Tests: