generated from RedHatInsights/frontend-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Improve routes handling #1192
Open
gkarat
wants to merge
4
commits into
RedHatInsights:master
Choose a base branch
from
gkarat:improve-routes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Improve routes handling #1192
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4f82a90
refactor(Routes): Remove * wrapping route
gkarat 92b6ad5
chore: Remove deprecated ErrorComponent prop passing
gkarat fed5d4d
refactor: Replace PermissionRoute with a plain component
gkarat c7be848
refactor: Use relative paths for routes at Routes.js.
gkarat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Bullseye, Spinner } from '@patternfly/react-core'; | ||
import { NotAuthorized } from '@redhat-cloud-services/frontend-components'; | ||
import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-components-utilities/RBACHook'; | ||
|
||
const AccessWrapper = ({ children }) => { | ||
const { hasAccess, isLoading } = usePermissionsWithContext([ | ||
'patch:*:*', | ||
'patch:*:read' | ||
]); | ||
|
||
return isLoading ? ( | ||
<Bullseye> | ||
<Spinner /> | ||
</Bullseye> | ||
) : hasAccess ? ( | ||
children | ||
) : ( | ||
<NotAuthorized serviceName="patch" /> | ||
); | ||
}; | ||
|
||
AccessWrapper.propTypes = { | ||
children: PropTypes.any | ||
}; | ||
|
||
export default AccessWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't know why it work here with absolute paths, but these should be relative. All other applications use relative paths for their routes[0].
However, I think we should try to make these relative as well and also make sure we consistently use the insights navigate stuff, so links resolve properly.
[0] https://github.com/RedHatInsights/compliance-frontend/blob/master/src/Routes.js#L23
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.
It simply matches the routes starting by the basename (which is
/
in our case because /insights/patch pathname prefix is cut by chrome/federated modules related reason). Navigating to /advisories will match with the route having a path/advisories
. As well as it will match the route with justadvisories
path. In our case, it doesn't have any disadvantages but inconsistency with other apps, as you mentioned. Though, all apps are inconsistent, Inventory has the same "root slash preference": https://github.com/RedHatInsights/insights-inventory-frontend/blob/master/src/Routes.js.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.
I would say these paths starting with a slash are actually more specific, they are fully matching the route. Though, if for example path="advisories" would be by accident placed under some other route, it will lead to the situation where any path that has some slices and ends with "advisories" will match. It's very in theory though, but just imagining.
Do you think it's worth consolidating?
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.
I think this here works maybe only because of some trickery we do in the routing in chrome, but I don't think it is really correct and might cause issues.
We should make these relative and remove the
/
from the paths (here and in all apps where we have this). These routes are nested within the/insights/patch
path and starting the path for them with a/
is not correct.We should also consistently use the
InsightsLink
anduseInsightsNavigate
, because these will turn relative paths like "advisories" into "/insights/patch/advisories".These changes seem unnecessary and everything kinda works at the moment, but this is only because of trickery and luck. What these changes do is make our routing in apps comply with React router conventions in order to reduce the burden on routing.
I also saw some ".." as a
to
attribute ofLink
components, these are dangerous, because they can lead to different places under a different context, for example with federated modules.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.
I think I get your point, this makes sense to use relative paths in accordance to the react-router documentation. Regarding the cut paths: I don't think it's just of trickery and luck :D IIRC, it's made on purpose that our applications have baseName set to / even though we always have some /insights/abc preceding. Which is made to avoid real base name rewrite or make the navigation work properly.
I will move the things to relative paths now.