Skip to content

feat(ISearchFormItemMetadata): add RenderContent method#7785

Merged
ArgoZhang merged 12 commits intomainfrom
refactor-search
Mar 23, 2026
Merged

feat(ISearchFormItemMetadata): add RenderContent method#7785
ArgoZhang merged 12 commits intomainfrom
refactor-search

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Mar 22, 2026

Link issues

fixes #7784

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

Add support for custom-rendered search form items via metadata and centralize search form localization options retrieval.

New Features:

  • Allow ISearchFormItemMetadata implementations to provide custom RenderContent for search form item UI.
  • Enable SearchForm to prefer metadata-provided content while falling back to the default search item component rendering.

Enhancements:

  • Rename and extend the search metadata base class to include a default RenderContent implementation and update derived metadata types accordingly.
  • Refactor search form localization options creation into a reusable IStringLocalizer extension used by SearchForm and Table search integration.

Tests:

  • Add a unit test verifying that custom metadata can render a search form item with a predefined value via RenderContent.

Copilot AI review requested due to automatic review settings March 22, 2026 11:41
@bb-auto bb-auto bot added the enhancement New feature or request label Mar 22, 2026
@bb-auto bb-auto bot added this to the v10.4.0 milestone Mar 22, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 22, 2026

Reviewer's Guide

Adds a customizable RenderContent hook to ISearchFormItemMetadata and its base class, updates SearchForm and Table search form generation to use it and a shared localizer helper, and introduces a unit test demonstrating custom metadata rendering.

Sequence diagram for custom search item rendering with RenderContent

sequenceDiagram
    actor User
    participant SearchForm
    participant ISearchItem
    participant Metadata as ISearchFormItemMetadata

    User->>SearchForm: OpenSearchForm()
    SearchForm->>ISearchItem: AutoGenerateTemplate(item)
    ISearchItem-->>SearchForm: item with Metadata
    SearchForm->>Metadata: RenderContent()
    alt custom content provided
        Metadata-->>SearchForm: RenderFragment customContent
        SearchForm-->>User: Render customContent
    else no custom content
        Metadata-->>SearchForm: null
        SearchForm->>ISearchItem: CreateSearchItemComponentByMetadata()
        ISearchItem-->>SearchForm: RenderFragment defaultContent
        SearchForm-->>User: Render defaultContent
    end

    User->>SearchForm: Change search value
    SearchForm->>SearchForm: Items.ToFilter()
    SearchForm->>SearchForm: OnChanged(filter)
Loading

Class diagram for updated search form item metadata hierarchy

classDiagram

class ISearchFormItemMetadata {
    +Reset()
    +RenderContent() RenderFragment?
}

class SearchFormItemMetadataBase {
    +Reset()
    +RenderContent() RenderFragment?
}

class DateTimeSearchMetadata
class DateTimeRangeSearchMetadata
class NumberSearchMetadata
class StringSearchMetadata
class SelectSearchMetadata
class MultipleSelectSearchMetadata {
    +GetFilter(fieldName string) FilterKeyValueAction?
}

ISearchFormItemMetadata <|.. SearchFormItemMetadataBase
SearchFormItemMetadataBase <|-- DateTimeSearchMetadata
SearchFormItemMetadataBase <|-- DateTimeRangeSearchMetadata
SearchFormItemMetadataBase <|-- NumberSearchMetadata
SearchFormItemMetadataBase <|-- StringSearchMetadata
SearchFormItemMetadataBase <|-- SelectSearchMetadata
SelectSearchMetadata <|-- MultipleSelectSearchMetadata
Loading

Flow diagram for shared SearchFormLocalizerOptions creation

flowchart TD
    subgraph Components
        SearchForm
        Table
    end

    IStringLocalizer_SearchFormLocalizerOptions
    SearchFormLocalizerOptions

    SearchForm -->|needs options| SearchFormLocalizerOptions
    Table -->|needs options| SearchFormLocalizerOptions

    SearchFormLocalizerOptions -->|if null| IStringLocalizer_SearchFormLocalizerOptions
    IStringLocalizer_SearchFormLocalizerOptions -->|GetSearchFormLocalizerOptions| SearchFormLocalizerOptions
Loading

File-Level Changes

Change Details Files
Introduce RenderContent extensibility point for search form item metadata and wire it into SearchForm rendering.
  • Extend ISearchFormItemMetadata with a RenderContent method returning an optional RenderFragment.
  • Add a virtual RenderContent implementation to the SearchFormItemMetadataBase abstract class that returns null by default.
  • Update SearchForm.AutoGenerateTemplate to prefer item.Metadata.RenderContent() when provided, falling back to CreateSearchItemComponentByMetadata().
  • Fix invocation style of the OnChanged callback in SearchForm to call the delegate directly.
src/BootstrapBlazor/Components/Searches/ISearchFormItemMetadata.cs
src/BootstrapBlazor/Components/Searches/SearchFormItemMetadataBase.cs
src/BootstrapBlazor/Components/SearchForm/SearchForm.razor.cs
Refactor search metadata base type naming and dependent metadata classes.
  • Rename SearchMetadataBase to SearchFormItemMetadataBase to better reflect its purpose while keeping the same responsibilities.
  • Update all concrete metadata classes to inherit from SearchFormItemMetadataBase instead of SearchMetadataBase.
  • Adjust documentation comments that referenced the old base class name.
src/BootstrapBlazor/Components/Searches/SearchFormItemMetadataBase.cs
src/BootstrapBlazor/Components/Searches/DateTimeRangeSearchMetadata.cs
src/BootstrapBlazor/Components/Searches/DateTimeSearchMetadata.cs
src/BootstrapBlazor/Components/Searches/NumberSearchMetadata.cs
src/BootstrapBlazor/Components/Searches/StringSearchMetadata.cs
src/BootstrapBlazor/Components/Searches/MultipleSelectSearchMetadata.cs
Extract common SearchFormLocalizerOptions construction into an IStringLocalizer extension and reuse it in SearchForm and Table.
  • Add IStringLocalizerExtensions.GetSearchFormLocalizerOptions to build a SearchFormLocalizerOptions instance from a typed IStringLocalizer.
  • Update SearchForm to obtain its cached SearchFormLocalizerOptions via the new extension instead of manually constructing it.
  • Update Table search form generation to use the same extension when SearchFormLocalizerOptions is null.
src/BootstrapBlazor/Extensions/IStringLocalizerExtensions.cs
src/BootstrapBlazor/Components/SearchForm/SearchForm.razor.cs
src/BootstrapBlazor/Components/Table/Table.razor.Search.cs
Add unit coverage for custom metadata rendering using RenderContent.
  • Introduce a new CustomMetadata_Ok unit test that configures a SearchForm with a SearchItem whose Metadata subclass overrides RenderContent.
  • Implement a CustomeMetadata subclass of StringSearchMetadata inside the test that renders a BootstrapInput with attributes bound to the metadata value and handlers.
  • Assert that the rendered markup contains the expected input value derived from the custom metadata.
test/UnitTest/Components/SearchFormTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7784 Add a RenderContent method to ISearchFormItemMetadata (and its base implementation) to allow metadata classes to provide custom rendered content.
#7784 Update search form rendering to use the new RenderContent method when provided, falling back to existing metadata-based rendering, and add coverage to validate this behavior.

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

@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 left some high level feedback:

  • In SearchForm.AutoGenerateTemplate, calling item.Metadata.RenderContent() without a null check can introduce a new null reference path for items without metadata; consider using a null-conditional access or defaulting to CreateSearchItemComponentByMetadata() when Metadata is null.
  • The test helper class name CustomeMetadata appears to be a typo; renaming it to CustomMetadata would improve clarity and avoid confusion for future readers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `SearchForm.AutoGenerateTemplate`, calling `item.Metadata.RenderContent()` without a null check can introduce a new null reference path for items without metadata; consider using a null-conditional access or defaulting to `CreateSearchItemComponentByMetadata()` when `Metadata` is null.
- The test helper class name `CustomeMetadata` appears to be a typo; renaming it to `CustomMetadata` would improve clarity and avoid confusion for future readers.

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

Adds a customization hook to SearchForm search-item metadata so consumers can provide their own UI rendering, while refactoring localizer option construction into a shared helper.

Changes:

  • Added RenderContent() to ISearchFormItemMetadata and integrated it into SearchForm rendering (fallback to existing metadata-based rendering).
  • Renamed SearchMetadataBase to SearchFormItemMetadataBase and updated built-in metadata types to inherit the new base.
  • Extracted SearchFormLocalizerOptions construction into an IStringLocalizer extension and reused it in SearchForm and Table.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/UnitTest/Components/SearchFormTest.cs Adds a unit test verifying custom metadata can render custom search UI.
src/BootstrapBlazor/Extensions/IStringLocalizerExtensions.cs Introduces a helper to build SearchFormLocalizerOptions from a localizer.
src/BootstrapBlazor/Extensions/ISearchItemExtensions.cs Updates XML doc wording for metadata-based rendering helper.
src/BootstrapBlazor/Components/Table/Table.razor.Search.cs Refactors localizer options initialization to use the new extension method.
src/BootstrapBlazor/Components/Searches/StringSearchMetadata.cs Updates inheritance to the renamed metadata base class.
src/BootstrapBlazor/Components/Searches/SearchFormItemMetadataBase.cs Renames base class and adds a virtual RenderContent() default implementation.
src/BootstrapBlazor/Components/Searches/NumberSearchMetadata.cs Updates inheritance to the renamed metadata base class.
src/BootstrapBlazor/Components/Searches/MultipleSelectSearchMetadata.cs Updates inheritdoc reference to the renamed base class.
src/BootstrapBlazor/Components/Searches/ISearchFormItemMetadata.cs Adds the new RenderContent() API to metadata.
src/BootstrapBlazor/Components/Searches/DateTimeSearchMetadata.cs Updates inheritance to the renamed metadata base class.
src/BootstrapBlazor/Components/Searches/DateTimeRangeSearchMetadata.cs Updates inheritance to the renamed metadata base class.
src/BootstrapBlazor/Components/SearchForm/SearchForm.razor.cs Uses Metadata.RenderContent() when provided; refactors localizer options creation.
src/BootstrapBlazor.Server/Locales/zh-CN.json Reorders SearchFormTips entry (no value change).
Comments suppressed due to low confidence (1)

src/BootstrapBlazor/Components/Searches/SearchFormItemMetadataBase.cs:15

  • Renaming the public base type from SearchMetadataBase to SearchFormItemMetadataBase is a breaking change for consumers deriving from SearchMetadataBase. To preserve backward compatibility, consider keeping a SearchMetadataBase type as an [Obsolete] shim that inherits from SearchFormItemMetadataBase (at least for one major/minor release).

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

@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7785   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          764       764           
  Lines        34115     34109    -6     
  Branches      4696      4697    +1     
=========================================
- Hits         34115     34109    -6     
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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ArgoZhang ArgoZhang merged commit 18bfd5a into main Mar 23, 2026
6 checks passed
@ArgoZhang ArgoZhang deleted the refactor-search branch March 23, 2026 01:52
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(ISearchFormItemMetadata): add RenderContent method

2 participants