Skip to content

Commit

Permalink
fix(RBACProvider): Don't block state update via "loading"
Browse files Browse the repository at this point in the history
  • Loading branch information
bastilian committed Jul 29, 2022
1 parent 98e4894 commit d6d69d9
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/components/src/RBACProvider/RBACProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { Access } from '@redhat-cloud-services/rbac-client';
import { Bullseye, Spinner } from '@patternfly/react-core';

Expand All @@ -21,11 +21,9 @@ export interface RBACProviderProps {
}

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

const fetchPermissions = async () => {
loading.current = true;
const { isOrgAdmin, permissions: userPermissions } = await getRBAC(appName, true);

setPermissionState((currentPerms: any) => ({
Expand All @@ -34,11 +32,10 @@ export const RBACProvider: React.FunctionComponent<RBACProviderProps> = ({ appNa
isOrgAdmin,
permissions: userPermissions,
}));
loading.current = false;
};

useEffect(() => {
if (!loading.current && permissionState.permissions.length == 0) {
if (appName) {
fetchPermissions();
}
}, [appName]);
Expand Down

0 comments on commit d6d69d9

Please sign in to comment.