Skip to content

Commit

Permalink
fix(rbac): fix the roles table to also watch policies
Browse files Browse the repository at this point in the history
  • Loading branch information
debsmita1 committed Jan 18, 2024
1 parent a25a64d commit 6fe96ec
Show file tree
Hide file tree
Showing 6 changed files with 4,121 additions and 5,950 deletions.
6 changes: 2 additions & 4 deletions plugins/rbac/src/components/CreateRole/AddMembersForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export const AddMembersForm = ({
membersData,
}: AddMembersFormProps) => {
const [search, setSearch] = React.useState<string>('');
const [selectedMember, setSelectedMember] = React.useState<SelectedMember>(
{} as SelectedMember,
);
const [selectedMember, setSelectedMember] = React.useState<SelectedMember>();

const getDescription = (member: MemberEntity) => {
const memberCount = getMembersCount(member);
Expand Down Expand Up @@ -75,7 +73,7 @@ export const AddMembersForm = ({
<br />
<Autocomplete
options={membersOptions}
getOptionLabel={(option: SelectedMember) => option.label || ''}
getOptionLabel={(option: SelectedMember) => option.label}
getOptionSelected={(option: SelectedMember, value: SelectedMember) =>
option.etag === value.etag
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/rbac/src/components/RbacPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('RbacPage', () => {
mockUseRoles.mockReturnValue({
loading: true,
data: [],
retry: jest.fn(),
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
createRoleLoading: false,
});
Expand Down
16 changes: 8 additions & 8 deletions plugins/rbac/src/components/RolesList/RolesList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('RolesList', () => {
mockUseRoles.mockReturnValue({
loading: false,
data: useRolesMockData,
retry: jest.fn(),
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
createRoleLoading: false,
});
Expand All @@ -80,7 +80,7 @@ describe('RolesList', () => {
mockUseRoles.mockReturnValue({
loading: false,
data: [],
retry: jest.fn(),
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
createRoleLoading: false,
});
Expand All @@ -96,7 +96,7 @@ describe('RolesList', () => {
mockUseRoles.mockReturnValue({
loading: false,
data: useRolesMockData,
retry: jest.fn(),
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
createRoleLoading: false,
});
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('RolesList', () => {
},
},
],
retry: jest.fn(),
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
createRoleLoading: false,
});
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('RolesList', () => {
},
},
],
retry: jest.fn(),
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: true,
createRoleLoading: false,
});
Expand All @@ -175,7 +175,7 @@ describe('RolesList', () => {
mockUseRoles.mockReturnValue({
loading: false,
data: useRolesMockData,
retry: jest.fn(),
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
createRoleLoading: false,
});
Expand All @@ -192,7 +192,7 @@ describe('RolesList', () => {
mockUseRoles.mockReturnValue({
loading: false,
data: useRolesMockData,
retry: jest.fn(),
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: true,
createRoleLoading: false,
});
Expand All @@ -209,7 +209,7 @@ describe('RolesList', () => {
mockUseRoles.mockReturnValue({
loading: false,
data: useRolesMockData,
retry: jest.fn(),
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
createRoleLoading: false,
});
Expand Down
17 changes: 15 additions & 2 deletions plugins/rbac/src/components/RolesList/RolesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const useStyles = makeStyles(theme => ({

export const RolesList = () => {
const { toastMessage, setToastMessage } = useToast();
const [isMounted, setIsMounted] = React.useState<boolean>(false);
const mountedRef = React.useRef(false);
const { openDialog, setOpenDialog, deleteRoleName } = useDeleteDialog();

const [roles, setRoles] = React.useState<number | undefined>();
Expand All @@ -32,7 +34,8 @@ export const RolesList = () => {

const closeDialog = () => {
setOpenDialog(false);
retry();
retry.roleRetry();
retry.policiesRetry();
};

const onAlertClose = () => {
Expand All @@ -42,6 +45,16 @@ export const RolesList = () => {
setRoles(searchResults.length);
};

React.useEffect(() => {
mountedRef.current = true;
if (!loading) {
setIsMounted(true);
}
return () => {
mountedRef.current = false;
};
}, [loading]);

return (
<>
<SnackbarAlert toastMessage={toastMessage} onAlertClose={onAlertClose} />
Expand All @@ -57,7 +70,7 @@ export const RolesList = () => {
}
options={{ padding: 'default', search: true, paging: true }}
data={data}
isLoading={loading}
isLoading={!isMounted}
columns={columns}
renderSummaryRow={summary => onSearchResultsChange(summary.data)}
emptyContent={
Expand Down
14 changes: 8 additions & 6 deletions plugins/rbac/src/hooks/useRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useRoles = (
data: RolesData[];
createRoleLoading: boolean;
createRoleAllowed: boolean;
retry: () => void;
retry: { roleRetry: () => void; policiesRetry: () => void };
} => {
const rbacApi = useApi(rbacApiRef);
const {
Expand All @@ -33,10 +33,11 @@ export const useRoles = (
retry: roleRetry,
} = useAsyncRetry(async () => await rbacApi.getRoles());

const { loading: policiesLoading, value: policies } = useAsyncRetry(
async () => await rbacApi.getPolicies(),
[],
);
const {
loading: policiesLoading,
value: policies,
retry: policiesRetry,
} = useAsyncRetry(async () => await rbacApi.getPolicies(), []);

const deletePermissionResult = usePermission({
permission: policyEntityDeletePermission,
Expand Down Expand Up @@ -111,6 +112,7 @@ export const useRoles = (
useInterval(
() => {
roleRetry();
policiesRetry();
},
loading ? null : pollInterval || 10000,
);
Expand All @@ -120,6 +122,6 @@ export const useRoles = (
data,
createRoleLoading,
createRoleAllowed,
retry: roleRetry,
retry: { roleRetry, policiesRetry },
};
};
Loading

0 comments on commit 6fe96ec

Please sign in to comment.