Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Mar 22, 2025

Link issues

fixes #5693

Summary By Copilot

This pull request introduces several changes to the Tabs component in the BootstrapBlazor project, focusing on adding new toolbar functionalities and enhancing existing tab styles. The most important changes include adding toolbar templates, updating localization files, and modifying the tab component to support new toolbar features.

Enhancements to Tab Toolbar:

  • Added new parameters ToolbarTemplate, ShowToolbar, ShowRefreshToolbarButton, ShowFullscreenToolbarButton, RefreshToolbarTooltipText, and FullscreenToolbarTooltipText to the Tab component to support toolbar customization. (src/BootstrapBlazor/Components/Tab/Tab.razor.cs - [1] [2] [3]
  • Modified the Tab component to include the new toolbar template and buttons with tooltip support. (src/BootstrapBlazor/Components/Tab/Tab.razor - [1] [2]
  • Updated the TabToolbarButton component to support tooltips and handle click events. (src/BootstrapBlazor/Components/Tab/TabToolbarButton.razor - [1] src/BootstrapBlazor/Components/Tab/TabToolbarButton.razor.cs - [2] [3]

Localization Updates:

  • Added new localization strings for toolbar-related parameters in English and Chinese localization files. (src/BootstrapBlazor.Server/Locales/en-US.json - [1] src/BootstrapBlazor.Server/Locales/zh-CN.json - [2] src/BootstrapBlazor/Locales/en.json - [3] src/BootstrapBlazor/Locales/zh.json - [4]

Other Changes:

  • Updated the Tabs.razor sample to demonstrate the new toolbar features and tab styles. (src/BootstrapBlazor.Server/Components/Samples/Tabs.razor - [1] [2] [3] [4]
  • Added CSS styles to ensure proper alignment and display of toolbar buttons. (src/BootstrapBlazor/Components/Tab/Tab.razor.scss - src/BootstrapBlazor/Components/Tab/Tab.razor.scssR674-R679)
  • Included a cascading value to pass the Tab component instance to templates. (src/BootstrapBlazor/Components/Tab/Tab.razor - [1] [2]

These changes collectively enhance the functionality and customization options of the Tabs component, making it more versatile and user-friendly.

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

Adds a ToolbarTemplate parameter to the Tab component, allowing users to customize the toolbar with custom content. It also adds ShowRefreshToolbarButton and ShowFullscreenToolbarButton parameters to control the visibility of the refresh and fullscreen buttons, and provides localization support for toolbar-related text.

New Features:

  • Adds a ToolbarTemplate parameter to the Tab component to allow users to customize the toolbar.
  • Adds ShowRefreshToolbarButton and ShowFullscreenToolbarButton parameters to control the visibility of the refresh and fullscreen buttons.

Tests:

  • Adds tests for the new toolbar template and tooltip text functionality.

@bb-auto bb-auto bot added the enhancement New feature or request label Mar 22, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 22, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new ToolbarTemplate parameter to the Tab component, allowing users to customize the toolbar. It also adds built-in refresh and fullscreen buttons with customizable tooltips. The implementation includes a new TabToolbarButton component, localization updates, sample updates, and CSS styling.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Added new parameters to the Tab component for toolbar customization.
  • Added ToolbarTemplate parameter to allow custom toolbar content.
  • Added ShowToolbar parameter to control toolbar visibility.
  • Added ShowRefreshToolbarButton and ShowFullscreenToolbarButton parameters to control the visibility of default buttons.
  • Added RefreshToolbarTooltipText and FullscreenToolbarTooltipText parameters to customize button tooltips.
src/BootstrapBlazor/Components/Tab/Tab.razor.cs
src/BootstrapBlazor/Components/Tab/Tab.razor
Implemented a new TabToolbarButton component to support tooltips and click events.
  • Created TabToolbarButton component with Icon and OnClickAsync parameters.
  • Added TooltipText parameter to the TabToolbarButton component.
  • Handled click events within the TabToolbarButton component.
src/BootstrapBlazor/Components/Tab/TabToolbarButton.razor
src/BootstrapBlazor/Components/Tab/TabToolbarButton.razor.cs
Updated localization files with new strings for toolbar-related parameters.
  • Added localization strings for RefreshToolbarTooltipText.
  • Added localization strings for FullscreenToolbarTooltipText.
src/BootstrapBlazor.Server/Locales/en-US.json
src/BootstrapBlazor.Server/Locales/zh-CN.json
src/BootstrapBlazor/Locales/en.json
src/BootstrapBlazor/Locales/zh.json
Updated the sample Tabs component to showcase the new toolbar features.
  • Added a new Toolbar demo to Tabs.razor to demonstrate the new toolbar features.
  • Added attributes to the AttributeTable component in Tabs.razor.cs to display the new properties.
src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
src/BootstrapBlazor.Server/Components/Samples/Tabs.razor.cs
Added CSS styles for toolbar buttons.
  • Added styles to ensure proper alignment and display of toolbar buttons.
src/BootstrapBlazor/Components/Tab/Tab.razor.scss
Included a cascading value for the Tab component instance.
  • Added CascadingValue to pass the Tab component instance to templates.
src/BootstrapBlazor/Components/Tab/Tab.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#5693 Add a ToolbarTemplate parameter to the Tab component.

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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 added this to the v9.4.0 milestone Mar 22, 2025
@ArgoZhang ArgoZhang merged commit cbcfba4 into main Mar 22, 2025
3 checks passed
@ArgoZhang ArgoZhang deleted the feat-tab branch March 22, 2025 17:08
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 @ArgoZhang - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a sample that demonstrates the ToolbarTemplate functionality with interactive elements.
  • The new parameters should be added to the component's documentation page.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

Comment on lines +71 to +72
cut.Contains("test-refresh-icon");
cut.Contains("test-refresh-tooltip-text");
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (testing): Missing assertion for FullscreenToolbarButton

The test for ToolbarTooltipText_Ok is missing assertions for the fullscreen button's icon and tooltip text. Please add cut.Contains("test-fullscreen-icon"); and cut.Contains("test-fullscreen-tooltip-text"); to ensure these properties are also rendered correctly.

Comment on lines +28 to +29
[Fact]
public void ToolbarTemplate_Ok()
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Missing test cases for null/empty ToolbarTemplate

It would be beneficial to add tests to verify the behavior when ToolbarTemplate is null or empty. This ensures the component handles these scenarios gracefully and doesn't throw exceptions or render unexpected content.

Suggested implementation:

        [Fact]
        public void ToolbarTemplate_Null()
        {
            // Test behavior when ToolbarTemplate is not provided (i.e., null)
            var cut = Context.RenderComponent<Tab>(pb =>
            {
                pb.AddChildContent<TabItem>(pb =>
                {
                    pb.Add(a => a.Text, "Tab1");
                    pb.Add(a => a.Url, "/Index");
                    pb.Add(a => a.Closable, true);
                    pb.Add(a => a.Icon, "fa-solid fa-font-awesome");
                    pb.Add(a => a.ChildContent, "Tab1-Content");
                });
                // ToolbarTemplate intentionally omitted to simulate null value.
            });

            // Assert the component renders correctly without the toolbar content.
            // Adjust the assertion as needed based on the actual expected markup.
            Assert.DoesNotContain("test-toolbar-template", cut.Markup);
        }

        [Fact]
        public void ToolbarTemplate_Empty()
        {
            // Test behavior when ToolbarTemplate is provided but empty.
            var cut = Context.RenderComponent<Tab>(pb =>
            {
                pb.AddChildContent<TabItem>(pb =>
                {
                    pb.Add(a => a.Text, "Tab1");
                    pb.Add(a => a.Url, "/Index");
                    pb.Add(a => a.Closable, true);
                    pb.Add(a => a.Icon, "fa-solid fa-font-awesome");
                    pb.Add(a => a.ChildContent, "Tab1-Content");
                });
                // Provide an empty template.
                pb.Add(a => a.ToolbarTemplate, builder => { });
            });

            // Assert that the rendered markup does not contain any unintended toolbar content.
            Assert.DoesNotContain("test-toolbar-template", cut.Markup);
        }

Depending on how the Tab component is expected to behave, you may need to adjust the assertions to check for specific markup conditions.

Type = "RenderFragment",
ValueList = " — ",
DefaultValue = " — "
},
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (complexity): Consider creating a helper method to construct the attribute definitions to reduce repetition and improve maintainability of the code.

To reduce repetition and improve maintainability, consider extracting a helper method to construct these attribute definitions. For example, you could create a helper that takes the specific parameters and returns the new attribute instance:

private AttributeItem CreateAttributeItem(string name, string descriptionKey, string type, string valueList, string defaultValue)
{
    return new AttributeItem
    {
        Name = name,
        Description = Localizer[descriptionKey].Value,
        Type = type,
        ValueList = valueList,
        DefaultValue = defaultValue
    };
}

Then, you can simplify the array initialization:

var attributes = new[]
{
    CreateAttributeItem(nameof(Tab.ShowToolbar), "AttributeShowToolbar", "bool", "true|false", "false"),
    CreateAttributeItem(nameof(Tab.ToolbarTemplate), "AttributeToolbarTemplate", "RenderFragment", " — ", " — "),
    CreateAttributeItem(nameof(Tab.ShowRefreshToolbarButton), "AttributeShowRefreshToolbarButton", "bool", "true|false", "true"),
    CreateAttributeItem(nameof(Tab.ShowFullscreenToolbarButton), "AttributeShowFullscreenToolbarButton", "bool", "true|false", "true"),
    CreateAttributeItem(nameof(Tab.RefreshToolbarTooltipText), "AttributeRefreshToolbarTooltipText", "string?", " — ", " — "),
    CreateAttributeItem(nameof(Tab.FullscreenToolbarTooltipText), "AttributeFullscreenToolbarTooltipText", "string?", " — ", " — "),
    CreateAttributeItem(nameof(Tab.RefreshToolbarButtonIcon), "AttributeRefreshToolbarButtonIcon", "string?", " — ", " — "),
    CreateAttributeItem(nameof(Tab.FullscreenToolbarButtonIcon), "AttributeFullscreenToolbarButtonIcon", "string?", " — ", " — ")
};

This approach retains all functionality and significantly reduces the duplicated patterns in your code.

@codecov
Copy link

codecov bot commented Mar 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (7253bc4) to head (22eb0fc).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #5694   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          657       657           
  Lines        29776     29789   +13     
  Branches      4220      4223    +3     
=========================================
+ Hits         29776     29789   +13     

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

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(Tab): add ToolbarTemplate parameter

2 participants