Skip to content

Commit

Permalink
fix: Use the context version of usePermissions (#1977)
Browse files Browse the repository at this point in the history
usePermissions is unstable and cause bugs in apps that import the
InventoryTable module. This makes it stick to the RBAC context and
guarantees that RD are not checked.
  • Loading branch information
gkarat authored Aug 14, 2023
1 parent fab5588 commit f75fc01
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"@patternfly/react-table": "^4.113.3",
"@patternfly/react-core": "^4.276.11",
"@patternfly/react-icons": "^4.93.7",
"@redhat-cloud-services/frontend-components": "^3.11.2",
"@redhat-cloud-services/frontend-components": "^3.11.3",
"@redhat-cloud-services/frontend-components-notifications": "^3.2.14",
"@redhat-cloud-services/frontend-components-utilities": "^3.7.4",
"@redhat-cloud-services/frontend-components-utilities": "^3.7.5",
"@redhat-cloud-services/host-inventory-client": "1.2.3",
"@unleash/proxy-client-react": "^3.5.0",
"awesome-debounce-promise": "^2.1.0",
Expand Down
9 changes: 7 additions & 2 deletions src/Utilities/Wrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { usePermissions } from '@redhat-cloud-services/frontend-components-utilities/RBACHook';
import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-components-utilities/RBACHook';
import { GENERAL_HOSTS_READ_PERMISSIONS } from '../constants';

const RenderWrapper = ({
cmp: Component,
Expand All @@ -9,7 +10,11 @@ const RenderWrapper = ({
store,
...props
}) => {
const { hasAccess } = usePermissions('inventory', ['inventory:hosts:read']);
const { hasAccess } = usePermissionsWithContext(
[GENERAL_HOSTS_READ_PERMISSIONS],
true,
false // omit RD check to find out if there are any inventory:hosts:read available
);

return (
<Component
Expand Down

0 comments on commit f75fc01

Please sign in to comment.