Skip to content

feat(Table): add SearchFormLocalizerOptions parameter#7769

Merged
ArgoZhang merged 11 commits intomainfrom
feat-search-form
Mar 15, 2026
Merged

feat(Table): add SearchFormLocalizerOptions parameter#7769
ArgoZhang merged 11 commits intomainfrom
feat-search-form

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Mar 15, 2026

Link issues

fixes #7768

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 configurable localization support for table search form UI and refine advanced search behavior.

New Features:

  • Introduce SearchFormLocalizerOptions to configure localized texts used by the table search form.
  • Expose a SearchFormLocalizerOptions parameter on Table components to allow overriding default search form localization.

Enhancements:

  • Populate search form localization options from an injected IStringLocalizer to remove hardcoded search UI texts and enable proper localization.
  • Update table search metadata generation to use localized labels and option texts for enum, numeric, and boolean search fields.
  • Restrict the advanced search button to be effective only when the table search mode is Popup and clarify this in the component documentation comments.

Documentation:

  • Adjust XML documentation on ShowAdvancedSearch to describe its behavior in relation to Popup search mode and advanced search visibility.

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

sourcery-ai bot commented Mar 15, 2026

Reviewer's Guide

Adds configurable, localized search-form text for Table search items and refines when advanced search is enabled, by introducing SearchFormLocalizerOptions, wiring it into Table search metadata generation, and updating localization wiring and samples.

Sequence diagram for localized SearchFormItems generation

sequenceDiagram
    actor User
    participant Page as RazorPage
    participant Table as Table_TItem
    participant Localizer as IStringLocalizer_SearchFormLocalizerOptions
    participant Cols as ITableColumnCollection
    participant Ext as IEditItemExtensions

    User->>Page: Request page with Table
    Page->>Table: Render Table

    Table->>Table: Access SearchFormItems
    alt SearchFormLocalizerOptions is null
        Table->>Localizer: Get SelectAllText
        Localizer-->>Table: localized SelectAllText
        Table->>Localizer: Get BooleanAllText
        Localizer-->>Table: localized BooleanAllText
        Table->>Localizer: Get BooleanTrueText
        Localizer-->>Table: localized BooleanTrueText
        Table->>Localizer: Get BooleanFalseText
        Localizer-->>Table: localized BooleanFalseText
        Table->>Localizer: Get NumberStartValueLabelText
        Localizer-->>Table: localized NumberStartValueLabelText
        Table->>Localizer: Get NumberEndValueLabelText
        Localizer-->>Table: localized NumberEndValueLabelText
        Table->>Table: Create SearchFormLocalizerOptions instance
    end

    alt SearchItems provided
        Table->>Table: Use SearchItems
    else SearchItems not provided
        Table->>Table: GetSearchColumns()
        Table-->>Cols: request columns
        Cols-->>Table: ITableColumn list
        loop for each ITableColumn
            Table->>Ext: ParseSearchItem(column, SearchFormLocalizerOptions)
            Ext->>Ext: BuildSearchMetaData(column, SearchFormLocalizerOptions)
            Ext-->>Table: ISearchItem with localized MetaData
        end
    end

    Table-->>Page: Localized SearchFormItems
    Page-->>User: Rendered search form with localized texts
Loading

Class diagram for SearchFormLocalizerOptions integration into Table search

classDiagram
    direction LR

    class Table_TItem {
        +bool ShowSearchButton
        +bool ShowAdvancedSearch
        +SearchMode SearchMode
        +IEnumerable~ISearchItem~ SearchItems
        +SearchFormLocalizerOptions~nullable~ SearchFormLocalizerOptions
        +IEnumerable~ISearchItem~ SearchFormItems
        +List~IFilterAction~ GetAdvanceSearches()
        +IEnumerable~ITableColumn~ GetSearchColumns()
    }

    class SearchFormLocalizerOptions {
        +string SelectAllText
        +string BooleanAllText
        +string BooleanTrueText
        +string BooleanFalseText
        +string NumberStartValueLabelText
        +string NumberEndValueLabelText
    }

    class IStringLocalizer_SearchFormLocalizerOptions {
        +string this[string name]
    }

    class ITableColumn {
        +string GetFieldName()
        +Type PropertyType
        +Type GetRealType()
        +string GetDisplayName()
        +string GroupName
        +int GroupOrder
        +int Order
        +ISearchFormItemMetaData SearchFormItemMetaData
    }

    class IEditItemExtensions {
        +static ISearchItem ParseSearchItem(ITableColumn column, SearchFormLocalizerOptions options)
        -static ISearchFormItemMetaData BuildSearchMetaData(ITableColumn column, SearchFormLocalizerOptions options)
    }

    class ISearchItem {
    }

    class SearchItem {
        +SearchItem(string fieldName, Type propertyType, string displayName)
        +string FieldName
        +Type PropertyType
        +string DisplayName
        +string GroupName
        +int GroupOrder
        +int Order
        +ISearchFormItemMetaData MetaData
    }

    class ISearchFormItemMetaData {
    }

    class SelectSearchMetaData {
        +IEnumerable~SelectedItem~ Items
    }

    class NumberSearchMetaData {
        +string StartValueLabelText
        +string EndValueLabelText
        +Type ValueType
    }

    class DateTimeRangeSearchMetaData {
    }

    class SelectedItem {
        +string Value
        +string Text
    }

    class IFilterAction {
    }

    class SearchMode {
        <<enumeration>>
        Top
        Popup
        None
    }

    Table_TItem --> IStringLocalizer_SearchFormLocalizerOptions : uses
    Table_TItem --> SearchFormLocalizerOptions : has
    Table_TItem --> ISearchItem : produces
    Table_TItem --> ITableColumn : reads

    IEditItemExtensions ..> ITableColumn : extends
    IEditItemExtensions ..> SearchFormLocalizerOptions : uses
    IEditItemExtensions --> ISearchFormItemMetaData : builds

    SearchItem ..|> ISearchItem
    SearchItem --> ISearchFormItemMetaData : has

    SelectSearchMetaData ..|> ISearchFormItemMetaData
    NumberSearchMetaData ..|> ISearchFormItemMetaData
    DateTimeRangeSearchMetaData ..|> ISearchFormItemMetaData

    SelectSearchMetaData --> SelectedItem : contains

    Table_TItem --> IFilterAction : returns

    Table_TItem --> SearchMode : configures advanced search
Loading

Flow diagram for when advanced search is enabled

flowchart LR
    A[Start] --> B[Check ShowAdvancedSearch]
    B -->|false| Z[Advanced search disabled]
    B -->|true| C[Check SearchMode]
    C -->|not Popup| Z
    C -->|Popup| D[Check CustomerSearchModel is null]
    D -->|false| Z
    D -->|true| E[Create default advanced search filters]
    E --> F[Return List of IFilterAction]
    F --> G[Advanced search popup available]
    Z --> H[End]
    G --> H
Loading

File-Level Changes

Change Details Files
Introduce SearchFormLocalizerOptions and expose it as a Table parameter for configuring localized search-form labels.
  • Add readonly record struct SearchFormLocalizerOptions with properties for select-all, boolean, and numeric range label texts.
  • Expose a nullable SearchFormLocalizerOptions parameter on Table to allow external configuration.
  • Inject an IStringLocalizer into Table for resolving default localized values when options are not provided.
src/BootstrapBlazor/Options/SearchFormLocalizerOptions.cs
src/BootstrapBlazor/Components/Table/Table.razor.Search.cs
src/BootstrapBlazor/Components/Table/Table.razor.Localization.cs
Wire SearchFormLocalizerOptions into search-item metadata generation to replace hard-coded Chinese texts with localized strings.
  • Change ITableColumnExtensions.ParseSearchItem to accept a SearchFormLocalizerOptions argument and pass it into BuildSearchMetaData.
  • Update BuildSearchMetaData to use SearchFormLocalizerOptions for enum select-all text, numeric start/end labels, and boolean select/all/true/false items instead of hard-coded literals.
  • Update Table.SearchFormItems to lazily initialize SearchFormLocalizerOptions from the injected localizer and pass it to ParseSearchItem when creating default search items.
src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs
src/BootstrapBlazor/Components/Table/Table.razor.Search.cs
Tighten conditions under which advanced search is shown and clarify related documentation.
  • Update XML doc comments for ShowAdvancedSearch to clarify it only applies when SearchMode is Popup.
  • Change GetAdvanceSearches condition to require SearchMode == SearchMode.Popup and remove dependency on UseSearchForm.
src/BootstrapBlazor/Components/Table/Table.razor.Search.cs
Minor sample and localization wiring adjustments to support the new behavior.
  • Tidy formatting of the TablesSearch.razor sample Table markup.
  • Prepare localization JSON and project files to include strings for SearchFormLocalizerOptions (diff not fully shown but files are touched).
  • Add a placeholder comment in Table.razor.cs indicating where SearchForm localization should be initialized during parameter initialization.
src/BootstrapBlazor.Server/Components/Samples/Table/TablesSearch.razor
src/BootstrapBlazor.Server/Locales/en-US.json
src/BootstrapBlazor.Server/Locales/zh-CN.json
src/BootstrapBlazor/BootstrapBlazor.csproj
src/BootstrapBlazor/Locales/en.json
src/BootstrapBlazor/Locales/zh.json
src/BootstrapBlazor/Components/Table/Table.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7768 Expose a SearchFormLocalizerOptions parameter on the Table component to allow configuration of search form localization.
#7768 Integrate SearchFormLocalizerOptions into the search form generation so that search item metadata (e.g., select-all text, boolean labels, numeric range labels) is localized/configurable via this parameter.

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 found 1 issue, and left some high level feedback:

  • The SearchFormItems getter now mutates the SearchFormLocalizerOptions parameter and uses it as lazy initialization; consider moving this initialization into OnInitParameters (where you already left a TODO-style comment) or another lifecycle method to avoid side effects in a property getter.
  • Changing ITableColumnExtensions.ParseSearchItem and BuildSearchMetaData to always require a SearchFormLocalizerOptions argument is a breaking signature change; if possible, add an overload that preserves the previous parameter-less usage and routes to the new overload with default options.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `SearchFormItems` getter now mutates the `SearchFormLocalizerOptions` parameter and uses it as lazy initialization; consider moving this initialization into `OnInitParameters` (where you already left a TODO-style comment) or another lifecycle method to avoid side effects in a property getter.
- Changing `ITableColumnExtensions.ParseSearchItem` and `BuildSearchMetaData` to always require a `SearchFormLocalizerOptions` argument is a breaking signature change; if possible, add an overload that preserves the previous parameter-less usage and routes to the new overload with default options.

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor/Components/Table/Table.razor.Search.cs" line_range="173" />
<code_context>
         {
-            // TODO: 增加多语言支持
-            _searchItems ??= SearchItems ?? GetSearchColumns().Select(i => i.ParseSearchItem()).ToList();
+            if (SearchFormLocalizerOptions is null)
+            {
+                SearchFormLocalizerOptions = new SearchFormLocalizerOptions()
</code_context>
<issue_to_address>
**issue (complexity):** Consider refactoring the search form localization logic to separate parameter handling, default resolution, and caching, and to move initialization outside the property getter.

You can simplify this by separating:

* parameter input (`SearchFormLocalizerOptions?`)
* resolved, non-null options used internally
* search item caching

and by moving initialization out of the getter.

### 1. Keep `[Parameter]` but introduce a non-nullable backing field

```csharp
[Parameter]
public SearchFormLocalizerOptions? SearchFormLocalizerOptions { get; set; }

private SearchFormLocalizerOptions _effectiveSearchFormLocalizerOptions;
```

### 2. Initialize the effective options once (e.g. in `OnParametersSet`)

This avoids mutating the `[Parameter]` in the getter and removes the nullable+`.Value` complexity:

```csharp
protected override void OnParametersSet()
{
    _effectiveSearchFormLocalizerOptions = SearchFormLocalizerOptions ?? new SearchFormLocalizerOptions
    {
        SelectAllText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.SelectAllText)],
        BooleanAllText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.BooleanAllText)],
        BooleanTrueText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.BooleanTrueText)],
        BooleanFalseText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.BooleanFalseText)],
        NumberStartValueLabelText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.NumberStartValueLabelText)],
        NumberEndValueLabelText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.NumberEndValueLabelText)]
    };

    // If options influence search items, invalidate cache when they change
    _searchItems = null;

    base.OnParametersSet();
}
```

### 3. Make `SearchFormItems` only handle caching/building

No side effects, no nullable `.Value`:

```csharp
private IEnumerable<ISearchItem> SearchFormItems
{
    get
    {
        _searchItems ??= SearchItems
            ?? GetSearchColumns()
                .Select(i => i.ParseSearchItem(_effectiveSearchFormLocalizerOptions))
                .ToList();

        return _searchItems;
    }
}
```

This keeps all current functionality (parameter override + localized defaults) while reducing complexity around parameter mutation, nullability, and getter side effects.
</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

This PR introduces localization support for the Table search form’s auto-generated search item metadata (enum “All”, boolean values, number range labels), adds the corresponding localization resources, and updates related Table behavior/docs.

Changes:

  • Added SearchFormLocalizerOptions and wired Table to provide localized default labels for generated search form items.
  • Updated ITableColumnISearchItem conversion to accept localization options when building metadata.
  • Added new localization entries in both library and server locale JSON files; bumped package version.

Reviewed changes

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

Show a summary per file
File Description
src/BootstrapBlazor/Options/SearchFormLocalizerOptions.cs New options type for search-form label localization.
src/BootstrapBlazor/Locales/zh.json Adds localized strings for SearchFormLocalizerOptions.
src/BootstrapBlazor/Locales/en.json Adds localized strings for SearchFormLocalizerOptions.
src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs Updates search-item generation to use localized option values.
src/BootstrapBlazor/Components/Table/Table.razor.Search.cs Adds Table parameter + default options creation from localizer; changes advanced-search filter gating.
src/BootstrapBlazor/Components/Table/Table.razor.Localization.cs Injects localizer for SearchFormLocalizerOptions.
src/BootstrapBlazor/Components/Table/Table.razor.cs Version-related minor change; adds placeholder comment.
src/BootstrapBlazor/BootstrapBlazor.csproj Bumps package version to 10.4.1-beta03.
src/BootstrapBlazor.Server/Locales/zh-CN.json Adds/moves sample-page localized strings for SearchForm section.
src/BootstrapBlazor.Server/Locales/en-US.json Adds/moves sample-page localized strings for SearchForm section.
src/BootstrapBlazor.Server/Components/Samples/Table/TablesSearch.razor Formatting-only indentation change.

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

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.99%. Comparing base (83ca545) to head (372fe23).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7769   +/-   ##
=======================================
  Coverage   99.99%   99.99%           
=======================================
  Files         764      764           
  Lines       33933    33953   +20     
  Branches     4672     4673    +1     
=======================================
+ Hits        33930    33951   +21     
  Misses          2        2           
+ Partials        1        0    -1     
Flag Coverage Δ
BB 99.99% <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 148775c into main Mar 15, 2026
4 checks passed
@ArgoZhang ArgoZhang deleted the feat-search-form branch March 15, 2026 07:14
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(Table): add SearchFormLocalizerOptions parameter

2 participants