Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Yi Cai <yicai@redhat.com>
  • Loading branch information
ciiay committed May 31, 2024
1 parent 2a31062 commit fa31127
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
42 changes: 28 additions & 14 deletions plugins/rbac/src/components/RolesList/RolesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import React from 'react';

import { Table, WarningPanel } from '@backstage/core-components';

import { Box, makeStyles } from '@material-ui/core';
import { Alert } from '@material-ui/lab';
import { makeStyles } from '@material-ui/core';

import { useLocationToast } from '../../hooks/useLocationToast';
import { useRoles } from '../../hooks/useRoles';
Expand Down Expand Up @@ -45,27 +44,42 @@ export const RolesList = () => {
setRoles(searchResults.length);
};

const getErrorWarning = () => {
const errorTitleBase = 'Something went wrong while fetching the';
const errorWarningArr = [
{ message: error?.rolesError, title: `${errorTitleBase} roles` },
{
message: error?.policiesError,
title: `${errorTitleBase} permission policies`,
},
{
message: error?.roleConditionError,
title: `${errorTitleBase} role conditions`,
},
];

return (
errorWarningArr.find(({ message }) => message) || {
message: '',
title: '',
}
);
};

const errorWarning = getErrorWarning();

return (
<>
<SnackbarAlert toastMessage={toastMessage} onAlertClose={onAlertClose} />
{error?.roleConditionError && (
<Box>
<Alert severity="warning">{error?.roleConditionError}</Alert>
</Box>
)}
<RolesListToolbar
createRoleAllowed={createRoleAllowed}
createRoleLoading={createRoleLoading}
/>
{(error?.rolesError || error?.policiesError) && (
{errorWarning.message && (
<div style={{ paddingBottom: '16px' }}>
<WarningPanel
message={error.rolesError || error.policiesError}
title={
error.rolesError
? 'Something went wrong while fetching the roles'
: 'Something went wrong while fetching the permission policies'
}
message={errorWarning.message}
title={errorWarning.title}
severity="error"
/>
</div>
Expand Down
6 changes: 3 additions & 3 deletions plugins/rbac/src/hooks/useRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useRoles = (
const [newRoles, setNewRoles] = React.useState<
RoleWithConditionalPoliciesCount[]
>([]);
const [fetchRoleConditionsError, setFetchRoleConditionsError] =
const [roleConditionError, setRoleConditionError] =
React.useState<string>('');
const {
value: roles,
Expand Down Expand Up @@ -102,7 +102,7 @@ export const useRoles = (
: 0,
};
} catch (error) {
setFetchRoleConditionsError(
setRoleConditionError(
`Error fetching role conditions for role ${role.name}, please try again later.`,
);
return {
Expand Down Expand Up @@ -186,7 +186,7 @@ export const useRoles = (
(typeof policies === 'object'
? (policies as any as Response)?.statusText
: '')) as string,
roleConditionError: fetchRoleConditionsError,
roleConditionError,
},
createRoleLoading,
createRoleAllowed,
Expand Down

0 comments on commit fa31127

Please sign in to comment.