Skip to content

Add conditional edit/delete button disabling #1850

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

Merged
merged 6 commits into from
Jun 6, 2025
Merged

Conversation

apinkert
Copy link
Contributor

@apinkert apinkert commented Jun 4, 2025

For RHCLOUD-39840

Conditionally disables a workspace's edit/delete button based on workspace type as well as user permissions. Also adds basic e2e tests to test workspace type conditions.

image

Summary by Sourcery

Add conditional disabling of workspace edit and delete actions based on workspace type and user RBAC permissions.

New Features:

  • Fetch and store user RBAC permissions via Chrome to control workspace actions

Enhancements:

  • Extend workspace type enum to include 'ungrouped-hosts'
  • Disable edit/delete buttons dynamically according to workspace type and user permission

Tests:

  • Add Cypress e2e tests to verify edit/delete button states for root, default, and standard workspaces based on permissions

@apinkert apinkert requested a review from a team as a code owner June 4, 2025 20:31
Copy link
Contributor

sourcery-ai bot commented Jun 4, 2025

Reviewer's Guide

Implements permission- and type-based disabling of workspace edit/delete actions by fetching user write permissions from Chrome, centralizing disable logic in helper functions, extends the workspace type enum to include 'ungrouped-hosts', and adds Cypress tests to verify correct button states across workspace types.

Sequence Diagram: Fetching and Applying User Permissions

sequenceDiagram
    title Sequence Diagram: Fetching and Applying User Permissions
    participant WLT as WorkspaceListTable Component
    participant Chrome as Chrome Service

    WLT->>Chrome: getUserPermissions()
    activate Chrome
    Chrome-->>WLT: userPermissions
    deactivate Chrome
    WLT->>WLT: Updates state with userPermissions
    WLT->>WLT: Applies new logic (canModify) during row rendering
Loading

File-Level Changes

Change Details Files
Introduce permission-driven button disable logic
  • Imported useChrome, defined PermissionObject and userPermissions state
  • Fetched user permissions via chrome.getUserPermissions in useEffect
  • Created isValidEditType and isValidDeleteType helpers for workspace types
  • Implemented canModify to combine type checks with userPermissions
  • Updated action menu items to use canModify for their isDisabled flags
src/smart-components/workspaces/WorkspaceListTable.tsx
Extend workspace type enumeration
  • Added 'ungrouped-hosts' to Workspace.type union
  • Adjusted reducer to support new workspace type
src/redux/reducers/workspaces-reducer.ts
Add end-to-end tests for conditional button states
  • Created edit-workspaces.cy.ts with mocks for root, default, and standard workspaces
  • Verified edit/delete buttons are enabled or disabled via OUIA selectors
cypress/e2e/edit-workspaces.cy.ts

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

  • The delete button’s isDisabled logic uses && to combine child existence and permission checks—this means if a workspace has no children but the user lacks permission, it won’t be disabled; flip it to disable when either condition is true.
  • Guard against permissions.find(...) returning undefined before calling setUserPermissions (or provide a fallback) to avoid setting userPermissions to undefined and crashing when accessing its fields.
  • Rather than two nearly identical switch functions, consider using a single config map or lookup object for edit/delete validity to reduce duplication and simplify future type additions.
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.

Copy link
Contributor

@karelhala karelhala left a comment

Choose a reason for hiding this comment

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

Looking really solid! Just a few code cleanup things.

Copy link
Contributor

@karelhala karelhala left a comment

Choose a reason for hiding this comment

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

Checked it locally and it looks really good! One minor visual update and we are golden.

@karelhala karelhala merged commit 33b2111 into master Jun 6, 2025
8 of 9 checks passed
@apinkert apinkert deleted the modify-workspaces branch June 6, 2025 20:10
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