Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Oct 23, 2025

Link issues

fixes #6986

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

Enable configurable tooltip display for Display components in EditorForm and refactor CreateDisplayByFieldType with helper methods for better maintainability

New Features:

  • Add IsShowDisplayTooltip parameter to EditorForm to control tooltip display on Display components
  • Add showTooltip flag to CreateDisplayByFieldType method to pass tooltip setting to Display rendering

Bug Fixes:

Enhancements:

  • Extract rendering logic into private helper methods (RenderSwitch, RenderTextarea, RenderDisplay) for cleaner code
  • Use generic nameof expressions for component attribute declarations to improve type safety

Copilot AI review requested due to automatic review settings October 23, 2025 02:52
@bb-auto bb-auto bot added the enhancement New feature or request label Oct 23, 2025
@bb-auto bb-auto bot added this to the 9.11.0 milestone Oct 23, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 23, 2025

Reviewer's Guide

This PR introduces a new IsShowDisplayTooltip flag in EditorForm and propagates it through the display-rendering pipeline. It extends CreateDisplayByFieldType to accept a showTooltip parameter, refactors the rendering branches into reusable helper methods (RenderSwitch, RenderTextarea, RenderDisplay), and generalizes many AddAttribute calls to use open generic component types.

Sequence diagram for propagating IsShowDisplayTooltip in EditorForm rendering

sequenceDiagram
    participant EditorForm
    participant Utility
    participant RenderTreeBuilder
    EditorForm->>Utility: CreateDisplayByFieldType(item, Model, IsShowDisplayTooltip)
    Utility->>RenderTreeBuilder: RenderDisplay(item, fieldType, fieldValue, displayName, showTooltip)
    RenderTreeBuilder-->>Utility: Display component rendered with ShowTooltip = IsShowDisplayTooltip
Loading

Class diagram for EditorForm and Utility changes

classDiagram
    class EditorForm_TModel {
        +bool IsDisplay
        +bool IsShowDisplayTooltip
        +RenderFragment AutoGenerateTemplate(IEditorItem item)
    }
    class Utility {
        +void CreateDisplayByFieldType(RenderTreeBuilder builder, IEditorItem item, object model, bool showTooltip = false)
        -void RenderSwitch(RenderTreeBuilder builder, IEditorItem item, object? fieldValue, string? displayName)
        -void RenderTextarea(RenderTreeBuilder builder, IEditorItem item, object? fieldValue, string? displayName)
        -void RenderDisplay(RenderTreeBuilder builder, IEditorItem item, Type fieldType, object? fieldValue, string? displayName, bool showTooltip)
    }
    EditorForm_TModel --> Utility: uses CreateDisplayByFieldType
    Utility o-- RenderSwitch
    Utility o-- RenderTextarea
    Utility o-- RenderDisplay
Loading

File-Level Changes

Change Details Files
Add IsShowDisplayTooltip parameter on EditorForm
  • Define new [Parameter] IsShowDisplayTooltip property
  • Pass IsShowDisplayTooltip to CreateDisplayByFieldType call
Components/EditorForm/EditorForm.razor.cs
Extend CreateDisplayByFieldType to accept a showTooltip flag
  • Update method signature and XML docs to include showTooltip defaulting to false
  • Forward showTooltip argument when invoking RenderDisplay
Utils/Utility.cs
Refactor display logic into private RenderX helper methods
  • Extract Switch branch into RenderSwitch
  • Extract Textarea branch into RenderTextarea
  • Extract Display branch into RenderDisplay
Utils/Utility.cs
Generalize AddAttribute invocations to open-generic components
  • Replace concrete ValidateBase and Select/Select references with ValidateBase<> and Select<>
  • Update nameof() calls accordingly throughout Utility.cs
Utils/Utility.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6986 Add an IsShowDisplayTooltip parameter to the EditorForm component.
#6986 Ensure the IsShowDisplayTooltip parameter controls whether the Display component's tooltip is shown.

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
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

This PR adds a new IsShowDisplayTooltip parameter to the EditorForm component to control whether tooltips are displayed on Display components in display mode. The implementation refactors the CreateDisplayByFieldType method by extracting rendering logic into separate helper methods and updates XML documentation comments.

Key Changes:

  • Added IsShowDisplayTooltip parameter to EditorForm component with default value of false
  • Refactored CreateDisplayByFieldType to use extracted helper methods (RenderSwitch, RenderTextarea, RenderDisplay)
  • Updated XML documentation with detailed parameter descriptions

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs Adds IsShowDisplayTooltip parameter and passes it to CreateDisplayByFieldType
src/BootstrapBlazor/Utils/Utility.cs Refactors display component creation logic and adds showTooltip parameter support
src/BootstrapBlazor/BootstrapBlazor.csproj Updates version numbers for beta releases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Oct 23, 2025
Copy link
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 there - 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/BootstrapBlazor/Utils/Utility.cs:461` </location>
<code_context>
+        builder.AddAttribute(10, nameof(Display<>.DisplayText), displayName);
+        builder.AddAttribute(20, nameof(Display<>.Value), fieldValue);
+        builder.AddAttribute(30, nameof(Display<>.Lookup), item.Lookup);
+        builder.AddAttribute(30, nameof(Display<>.LookupService), item.LookupService);
+        builder.AddAttribute(40, nameof(Display<>.LookupServiceKey), item.LookupServiceKey);
+        builder.AddAttribute(50, nameof(Display<>.LookupServiceData), item.LookupServiceData);
</code_context>

<issue_to_address>
**nitpick:** Duplicate attribute index (30) used for both Lookup and LookupService.

Assign unique indices to each attribute to prevent confusion and improve maintainability.
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Utils/Utility.cs:419` </location>
<code_context>
+        }
+    }
+
+    private static void RenderTextarea(this RenderTreeBuilder builder, IEditorItem item, object? fieldValue, string? displayName)
+    {
+        builder.OpenComponent(0, typeof(Textarea));
</code_context>

<issue_to_address>
**issue (complexity):** Consider refactoring the three rendering methods into a single generic renderer with attribute lists to eliminate repetitive code and manual sequence numbers.

You’ve already split the big switch into three methods, but they’re still almost line-for-line duplicates of each other.  You can collapse all of them into a single “generic” renderer + a tiny helper that drives `AddAttribute` from a simple list or dictionary.  That way you:

- eliminate all of your hard-coded sequence numbers  
- stop repeating the same `OpenComponent`/`CloseComponent`/`AddMultipleAttributes` logic  
- can inline conditional attributes (e.g. the `class` on `ITableColumn`) in a single loop  

For example, add a helper like this:

```csharp
private static void RenderComponent(
    this RenderTreeBuilder builder,
    Type componentType,
    IEditorItem item,
    IEnumerable<(string Name, object? Value)> attributes)
{
    builder.OpenComponent(0, componentType);

    var seq = 1;
    foreach (var (name, value) in attributes)
    {
        if (value != null)
            builder.AddAttribute(seq++, name, value);
    }

    builder.AddMultipleAttributes(seq, item.ComponentParameters);
    builder.CloseComponent();
}
```

Then rewrite each of your three methods into just building an attribute list:

```csharp
private static void RenderSwitch(this RenderTreeBuilder builder, IEditorItem item, object? fieldValue, string? displayName)
{
    var attrs = new[]
    {
        (nameof(Switch.Value)           , (object?) fieldValue),
        (nameof(Switch.IsDisabled)      , true),
        (nameof(Switch.DisplayText)     , displayName),
        (nameof(Switch.ShowLabelTooltip), (object?) item.ShowLabelTooltip),
        ( "class"                       , item is ITableColumn col ? col.CssClass : null )
    };
    builder.RenderComponent(typeof(Switch), item, attrs);
}
```

And similarly for `Textarea` and `Display<>`:

```csharp
private static void RenderTextarea(...){
    var attrs = new List<(string, object?)>{
        (nameof(Textarea.DisplayText), displayName),
        (nameof(Textarea.Value), fieldValue),
        /* etc */
    };
    if (item.Rows > 0) attrs.Add(("rows", item.Rows));
    attrs.Add(("class", item is ITableColumn col ? col.CssClass : null));
    builder.RenderComponent(typeof(Textarea), item, attrs);
}

private static void RenderDisplay(...){
    var displayType = typeof(Display<>).MakeGenericType(fieldType);
    var attrs = new List<(string, object?)>{
        (nameof(Display<object>.DisplayText), displayName),
        (nameof(Display<object>.Value), fieldValue),
        /* all the lookup/formatter/tooltip attrs */
    };
    if (item is ITableColumn col) { /* add format/FormatterAsync/class */ }
    builder.RenderComponent(displayType, item, attrs);
}
```

This preserves exactly the same behavior but removes hundreds of lines of boilerplate, collapses all your `AddAttribute(…)` calls into simple loops, and you never have to hand-maintain sequence numbers again.
</issue_to_address>

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.

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6987   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          741       741           
  Lines        32352     32365   +13     
  Branches      4481      4481           
=========================================
+ Hits         32352     32365   +13     
Flag Coverage Δ
BB 100.00% <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.

@ArgoZhang ArgoZhang merged commit 58180ef into main Oct 23, 2025
4 of 5 checks passed
@ArgoZhang ArgoZhang deleted the refactor-editor branch October 23, 2025 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(EditorForm): add IsShowDisplayTooltip parameter

2 participants