Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support IEnumerable data lookup #4859

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tiansfather
Copy link
Contributor

@tiansfather tiansfather commented Dec 16, 2024

{PR title}

Summary of the changes (Less than 80 chars)

Description

fixes #{bug number} (in this specific format)

Regression?

  • Yes
  • No

[If yes, specify the version the behavior has regressed from]

[是否影响老版本]

Risk

  • High
  • Medium
  • Low

[Justify the selection above]

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 IEnumerable data lookup in table columns by converting IEnumerable types to List for lookup matching, and enhance the RenderValue method to handle these types effectively.

New Features:

  • Add support for IEnumerable data lookup in table columns, allowing conversion of IEnumerable types to List for lookup matching.

    Enhancements:

    • Improve the RenderValue method to handle IEnumerable types by converting them to List and performing lookup matches accordingly.

Copy link

bb-auto bot commented Dec 16, 2024

Thanks for your PR, @tiansfather. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copy link

sourcery-ai bot commented Dec 16, 2024

Reviewer's Guide by Sourcery

This PR enhances the table column functionality by adding support for IEnumerable data lookup. The implementation modifies the RenderValue method to handle IEnumerable types, converting them to a List and implementing proper lookup value matching for collection types.

Sequence diagram for RenderValue method with IEnumerable

sequenceDiagram
    participant ITableColumnExtensions
    participant ITableColumn
    participant Builder
    participant IEnumerable
    participant List

    ITableColumnExtensions->>ITableColumn: GetItemValue(item)
    alt Lookup is not null and val is IEnumerable
        ITableColumnExtensions->>IEnumerable: GetEnumerator()
        IEnumerable->>List: Add(Current)
        ITableColumnExtensions->>ITableColumn: Lookup matching
        alt Lookup matches found
            ITableColumnExtensions->>Builder: RenderTooltip(matched Text)
        else No matches
            ITableColumnExtensions->>Builder: RenderTooltip(enumeratorDatas)
        end
    else Lookup is not null and val is not IEnumerable
        ITableColumnExtensions->>ITableColumn: Lookup matching
        alt Lookup match found
            ITableColumnExtensions->>Builder: RenderTooltip(matched Text)
        end
    end
Loading

Class diagram for ITableColumnExtensions changes

classDiagram
    class ITableColumnExtensions {
        +List<IFilterAction> ToSearches(IEnumerable<ITableColumn> columns)
        +RenderFragment RenderValue<TItem>(ITableColumn col, TItem item)
    }

    ITableColumnExtensions : RenderValue<TItem> --> GetEnumeratorDatas

    class GetEnumeratorDatas {
        +List<object> GetEnumeratorDatas(IEnumerable enumerableObj)
    }

    class ITableColumn {
        +object GetItemValue(TItem item)
        +RenderFragment RenderTooltip(string text, TItem item)
        +Type PropertyType
        +IEnumerable<LookupItem> Lookup
        +StringComparison LookupStringComparison
    }

    class LookupItem {
        +string Value
        +string Text
    }
Loading

File-Level Changes

Change Details Files
Added support for IEnumerable data type handling in table columns
  • Introduced a new helper function GetEnumeratorDatas to convert IEnumerable to List
  • Modified lookup value matching to support collection types
  • Updated the string representation logic for IEnumerable types
  • Adjusted type checking to support generic collections like List, List
src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs
Enhanced value rendering logic for table columns
  • Improved content handling for lookup values
  • Added comma-separated string representation for collection values
  • Replaced direct IEnumerable check with more generic type checking
src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

@bb-auto bb-auto bot requested a review from ArgoZhang December 16, 2024 06:18
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Dec 16, 2024
Copy link

@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 @tiansfather - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please fill out the PR template completely, including summary, bug number, and risk assessment. This helps with tracking and reviewing changes.
  • Consider using LINQ methods (like .ToList()) instead of manual enumeration in GetEnumeratorDatas. This would be more efficient and idiomatic C#.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs Outdated Show resolved Hide resolved
Comment on lines 194 to 195
// 转化 Lookup 数据源
var lookupVal = col.Lookup.FirstOrDefault(l => l.Value.Equals(val.ToString(), col.LookupStringComparison));
if (lookupVal != null)
if ((Nullable.GetUnderlyingType(col.PropertyType) ?? col.PropertyType).IsGenericType && val is IEnumerable v)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Repeated type checking logic could be simplified

Extract the type checking expression into a local variable to avoid repetition and improve readability.

Suggested change
// 转化 Lookup 数据源
var lookupVal = col.Lookup.FirstOrDefault(l => l.Value.Equals(val.ToString(), col.LookupStringComparison));
if (lookupVal != null)
if ((Nullable.GetUnderlyingType(col.PropertyType) ?? col.PropertyType).IsGenericType && val is IEnumerable v)
// 转化 Lookup 数据源
var isNullableGenericEnumerable = (Nullable.GetUnderlyingType(col.PropertyType) ?? col.PropertyType).IsGenericType;
if (isNullableGenericEnumerable && val is IEnumerable v)

Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 91.83673% with 4 lines in your changes missing coverage. Please review.

Project coverage is 99.98%. Comparing base (1c48683) to head (7c8c3e3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...otstrapBlazor/Extensions/ITableColumnExtensions.cs 91.83% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main    #4859      +/-   ##
===========================================
- Coverage   100.00%   99.98%   -0.02%     
===========================================
  Files          623      623              
  Lines        27832    27875      +43     
  Branches      3982     3983       +1     
===========================================
+ Hits         27832    27871      +39     
- Misses           0        4       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants