Skip to content

Commit dca755e

Browse files
authoredAug 29, 2023
fix: Fix non-working RBACProvider on empty appName (#1900)
This fixes the RBACProvider component: now, with the empty appName property, it fetches permissions and update the state properly.
1 parent a5e01d5 commit dca755e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
 

‎packages/components/src/RBACProvider/RBACProvider.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ const hasAccessWithUserPermissions = (userPermissions: (Access | string)[], chec
1919
};
2020

2121
export interface RBACProviderProps {
22-
appName: string;
23-
checkResourceDefinitions: boolean;
22+
appName?: string | null;
23+
checkResourceDefinitions?: boolean;
2424
}
2525

2626
export const RBACProvider: React.FunctionComponent<RBACProviderProps> = ({ appName, checkResourceDefinitions = false, children }) => {
2727
const [permissionState, setPermissionState] = useState(initialPermissions);
2828

2929
const fetchPermissions = async () => {
30-
const { isOrgAdmin, permissions: userPermissions } = await getRBAC(appName, true);
30+
const { isOrgAdmin, permissions: userPermissions } = await getRBAC(appName === null ? '' : appName, true);
3131

3232
setPermissionState((currentPerms) => ({
3333
...currentPerms,
@@ -38,8 +38,14 @@ export const RBACProvider: React.FunctionComponent<RBACProviderProps> = ({ appNa
3838
};
3939

4040
useEffect(() => {
41-
if (appName) {
41+
// if null or string - then fetch the permissions
42+
if (appName !== undefined) {
4243
fetchPermissions();
44+
} else {
45+
setPermissionState((currentPerms) => ({
46+
...currentPerms,
47+
isLoading: false,
48+
}));
4349
}
4450
}, [appName]);
4551

0 commit comments

Comments
 (0)