Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented May 8, 2025

Link issues

fixes #5998

Summary By Copilot

This pull request refactors the logic for determining edit and delete permissions in the Table component by replacing the CanEdit and CanDelete methods with ProhibitEdit and ProhibitDelete. Corresponding updates have been made to the unit tests to ensure consistency.

Refactoring of permission logic in Table component:

  • Replaced CanEdit with ProhibitEdit and CanDelete with ProhibitDelete in the Table.razor.Toolbar.cs file. This change inverts the logic to focus on prohibitions rather than permissions. ([[1]](https://github.com/dotnetcore/BootstrapBlazor/pull/5999/files#diff-ca9e82d70b95de7204b56fbdace327d330eaef6777601f3d897b0e07c8c3eff8L548-R548), [[2]](https://github.com/dotnetcore/BootstrapBlazor/pull/5999/files#diff-ca9e82d70b95de7204b56fbdace327d330eaef6777601f3d897b0e07c8c3eff8L995-R995), [[3]](https://github.com/dotnetcore/BootstrapBlazor/pull/5999/files#diff-ca9e82d70b95de7204b56fbdace327d330eaef6777601f3d897b0e07c8c3eff8L1006-R1011))

Updates to unit tests:

  • Updated all references to CanEdit and CanDelete in the TableTest.cs file to use ProhibitEdit and ProhibitDelete, ensuring the tests align with the new logic. ([[1]](https://github.com/dotnetcore/BootstrapBlazor/pull/5999/files#diff-3546a7a8520a1cc0576ca6a1077d468561e7b825b061c3d1aac2daae7a62a160L8654-R8655), [[2]](https://github.com/dotnetcore/BootstrapBlazor/pull/5999/files#diff-3546a7a8520a1cc0576ca6a1077d468561e7b825b061c3d1aac2daae7a62a160L8664-R8665), [[3]](https://github.com/dotnetcore/BootstrapBlazor/pull/5999/files#diff-3546a7a8520a1cc0576ca6a1077d468561e7b825b061c3d1aac2daae7a62a160L8683-R8690), [[4]](https://github.com/dotnetcore/BootstrapBlazor/pull/5999/files#diff-3546a7a8520a1cc0576ca6a1077d468561e7b825b061c3d1aac2daae7a62a160L8702-R8705))

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

Refactor the permission logic in the Table component by renaming methods from CanEdit and CanDelete to ProhibitEdit and ProhibitDelete, inverting the permission check logic.

Enhancements:

  • Renamed permission check methods to focus on prohibitions rather than permissions

Tests:

  • Updated unit tests to use the new method names and reflect the inverted permission logic

@ArgoZhang ArgoZhang requested a review from Copilot May 8, 2025 07:25
@bb-auto bb-auto bot added the enhancement New feature or request label May 8, 2025
@bb-auto bb-auto bot added this to the v9.6.0 milestone May 8, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 8, 2025

Reviewer's Guide

This pull request refactors permission checking in the Table component by renaming methods. Specifically, CanEdit and CanDelete in Table.razor.Toolbar.cs were renamed to ProhibitEdit and ProhibitDelete. This was implemented by renaming the method definitions and updating all internal call sites. The underlying conditional logic of these methods was not changed; the new names now accurately reflect that they return true when an action is prohibited. Unit tests in TableTest.cs were updated to use the new method names, including adjustments to reflection calls and test helper methods.

File-Level Changes

Change Details Files
Renamed permission-checking methods in Table.razor.Toolbar.cs to ProhibitEdit and ProhibitDelete for semantic clarity, aligning names with their existing prohibitory logic.
  • Renamed CanEdit() method to ProhibitEdit().
  • Renamed CanDelete() method to ProhibitDelete().
  • Updated internal calls to reflect new method names.
src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs
Adapted unit tests in TableTest.cs to reflect the method renaming, ensuring test consistency.
  • Renamed test helper methods from CanEdit/CanDelete to ProhibitEdit/ProhibitDelete.
  • Updated method name strings used in reflection to "ProhibitEdit" and "ProhibitDelete".
  • Modified assertions to use the renamed helper methods.
test/UnitTest/Components/TableTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#5998 Rename the CanEdit method to ProhibitEdit in the Table component.
#5998 Rename the CanDelete method to ProhibitDelete in the Table component.
#5998 Update all references to the renamed methods in the unit tests.

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 refactors the Table component’s permission logic by renaming methods from CanEdit/CanDelete to ProhibitEdit/ProhibitDelete, inverting their semantics.

  • Updated method calls in both the Table component and its unit tests
  • Refactored internal helper functions to align with the new prohibition-based naming

Reviewed Changes

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

File Description
test/UnitTest/Components/TableTest.cs Updated unit tests to call ProhibitEdit/ProhibitDelete instead of CanEdit/CanDelete
src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs Refactored method names and their corresponding invocations for editing and deletion logic
Comments suppressed due to low confidence (2)

test/UnitTest/Components/TableTest.cs:8687

  • [nitpick] Consider renaming the helper method to 'IsEditProhibited' to make it clearer that it returns a boolean indicating whether editing is prohibited.
static bool ProhibitEdit(Table<Foo> @this)

src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs:1006

  • [nitpick] Consider renaming 'ProhibitEdit' to 'IsEditProhibited' (and similarly for 'ProhibitDelete') to indicate more clearly that these methods return a boolean status.
private bool ProhibitEdit() => (ShowExtendEditButtonCallback != null && !ShowExtendEditButtonCallback(SelectedRows[0])) || !ShowExtendEditButton || (DisableExtendEditButtonCallback != null && DisableExtendEditButtonCallback(SelectedRows[0])) || DisableExtendEditButton;

@ArgoZhang ArgoZhang merged commit 91d0f52 into main May 8, 2025
3 checks passed
@ArgoZhang ArgoZhang deleted the refactor-table branch May 8, 2025 07:25
@codecov
Copy link

codecov bot commented May 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (417d198) to head (9b0998a).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #5999   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          670       670           
  Lines        30624     30624           
  Branches      4356      4356           
=========================================
  Hits         30624     30624           

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

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 and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 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.

}

static bool CanEdit(Table<Foo> @this)
static bool ProhibitEdit(Table<Foo> @this)
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): Consider adding test cases for scenarios where editing/deleting is permitted.

Add tests confirming ProhibitEdit(cut.Instance) and ProhibitDelete(cut.Instance) return false when editing and deleting are allowed (e.g., buttons enabled and callbacks permit the action) to ensure the logic doesn’t wrongly block these operations.

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.

refactor(Table): rename ProhibitEdit/Delete method name

2 participants