-
Notifications
You must be signed in to change notification settings - Fork 208
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
Enhancing UserHasAccess component #472
Conversation
File size impactImpact on file sizes when merging user-access-enhancement into master. @openmrs/esm-devtools-app (+86%)
@openmrs/esm-implementer-tools-app (+27%)
@openmrs/esm-login-app (+33%)
@openmrs/esm-offline-tools-app (+32%)
@openmrs/esm-primary-navigation-app (+32%)
@openmrs/esm-app-shell (+0.002%)
|
Hey @Arjun-Go, thanks for the PR! I think that this concrete approach can potentially cause unwanted side-effects because it is making the component do too much/make too many assumptions about what the unauthorized fallback should look like. Consider that I think that, to achieve your goal of rendering some kind of fallback when a user doesn't have access, it would be much better to leave that fallback as a placeholder, e.g. like this (treat the following code as a suggestion, not the ultimate way it should look like): const fallbackWhenUnauthorized = (
<div className="omrs-inline-notifications-container">
<InlineNotification
title="Unauthorised"
subtitle="You cannot access this page."
kind="error"
/>
</div>
);
// Then somewhere else:
<UserHasAccess unauthorizedChildren={fallbackWhenUnauthorized} ...otherProps /> Moving the responsiblity to the user of the component keeps |
I absolutely agree with both @manuelroemer's assessment and suggestion here. |
Hi @manuelroemer, the suggestion really helped. I've refactored the code to incorporate your comments. Thanks!! |
2c522fa
to
87a89e1
Compare
|
||
export interface UserHasAccessProps { | ||
interface UserHasAccessProps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should still be exported
privilege: string; | ||
unauthorisedResponse?: React.ReactNode | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response
doesn't make sense as a name here. It's not a response, it's a thing to render. I suggest fallbackChildren
. Or just fallback
. Note that | undefined
is in most cases redundant with ?:
. Also, as an aside, we normatively use US spelling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unauthorisedResponse?: React.ReactNode | undefined; | |
fallback?: React.ReactNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure @brandones , changes have been made accordingly.
Requirements
For changes to apps
If applicable
Summary
Existing UserHasAccess component returns null when the user is unauthorised. In this PR, we have enhanced the component such that the user sees an error message / notification or can redirect to a given URL.
Screenshots