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

Defer project kebab check and disable #3003

Conversation

emilys314
Copy link
Contributor

Closes RHOAIENG-1163 and #1932

Description

When a user doesn't have permission to Edit Project, Delete Project, or Edit Permissions, the actions will be grayed out and disabled. This prevents a user from trying to do the action and later getting an insufficient permissions error. (We decided to not hide them, because then we would have to hide the entire kebab menu if there were no permissions, which requires a check on display of the table.)

This also defers the project permission checks until the menu will be opened. This saves us from having to make 1 (or more) api calls per project being displayed on the table on page load.

How Has This Been Tested?

Tested locally with varying user permissions. Checked that projects with sufficient permissions allow actions, and without required permissions, the options will be disabled and the tooltip will show.

Added a test to check the insufficient permissions behaviour.

Test Impact

Mocked access review calls should be done if actions in the kebab menu are going to be used, since they are gated now.

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Commits have been squashed into descriptive, self-contained units of work (e.g. 'WIP' and 'Implements feedback' style messages have been removed)
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change (find relevant UX in the SMEs section).

aria-disabled being used to add tooltip for a disabled item:

image

Throttled testing to show permissions disabled while network call is still loading:

Screencast.from.2024-07-15.08-52-48.mp4

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

@openshift-ci openshift-ci bot requested review from alexcreasy and mturley July 15, 2024 13:12
@emilys314 emilys314 force-pushed the defer-project-kebab-check-and-disable branch from a668565 to 073bee0 Compare July 15, 2024 16:09
Copy link
Member

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

Great, thanks for working on this. Not the easiest and clearest first ticket, but we got there 🙂

Couple comments about implementation, let me know if you have any questions.

@emilys314 emilys314 force-pushed the defer-project-kebab-check-and-disable branch 2 times, most recently from 6e59503 to 0e6ef65 Compare July 15, 2024 19:13
setShouldRunCheck(true);
}, []);

const noPermissionToolTip = (allow: boolean, loaded: boolean) =>
Copy link
Member

Choose a reason for hiding this comment

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

Technically a nit because our linter should be doing this if we wanted it...

But typically you always want to type functions for both input and return -- in this case, it's a little less important, but I think it's a good practice to get into.

If you create this function in the root, I believe our linter yells at you to add a return type.

Suggested change
const noPermissionToolTip = (allow: boolean, loaded: boolean) =>
const noPermissionToolTip = (allow: boolean, loaded: boolean): Partial<KebabItem> =>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, I just added the Partial<KebabItem> | undefined return type onto it. Oddly the linter doesn't complain if the function is at the root either.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting... I swore we had that linter. cc @christianvogt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the eslint rule is disabled for that
in frontend/.eslintrc on line 156

    "@typescript-eslint/explicit-function-return-type": "off",

Copy link
Contributor

Choose a reason for hiding this comment

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

We do have this rule enabled: @typescript-eslint/explicit-module-boundary-types
This forces a type for all exported properties. Anything else internal to the module can use inference.

@emilys314 emilys314 force-pushed the defer-project-kebab-check-and-disable branch from 0e6ef65 to b9392f5 Compare July 17, 2024 13:22
Copy link
Member

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

Looks good. We may end up eventually being "wrong" if the user gets permissions mid-viewing of the page.

Example: I invited someone as a contributor to my project. They wanted to change the description because of a typo. I go 'ah okay, let me promote you to Admin' -- they'd need to refresh or paginate forward/back to get a new state for the dropdown.

It's minor, and very specific changing of permissions that is not likely to happen. Our solution may even just be a timeout reset of the hover state. Either way, I don't imagine this to be a big concern. if we get the bug we can handle it at that time for the use-case that is provided.

@openshift-ci openshift-ci bot added the lgtm label Jul 17, 2024
Copy link
Contributor

openshift-ci bot commented Jul 17, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 81961d4 into opendatahub-io:main Jul 17, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants