Skip to content

Commit

Permalink
ISPN-14697 Role detail
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Oct 30, 2023
1 parent 49d657b commit 973ba1a
Show file tree
Hide file tree
Showing 20 changed files with 1,150 additions and 85 deletions.
37 changes: 17 additions & 20 deletions src/app/AccessManagement/CreateRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,24 @@ import { useTranslation } from 'react-i18next';
import formUtils, { IField } from '@services/formUtils';
import { AddCircleOIcon, ExclamationCircleIcon, TimesIcon } from '@patternfly/react-icons';
import { useCreateRole, useFetchAvailableRoles } from '@app/services/rolesHook';
import { PERMISSIONS_MAP } from '@services/infinispanRefData';

const CreateRole = (props: { isModalOpen: boolean; submitModal: () => void; closeModal: () => void }) => {
const { t } = useTranslation();
const { roles } = useFetchAvailableRoles();
const brandname = t('brandname.brandname');
const initialSelectOptions: SelectOptionProps[] = [
{ value: 'ALL', children: 'ALL', description: t('access-management.roles.permission-all') },
{ value: 'ADMIN', children: 'ADMIN', description: t('access-management.roles.permission-admin') },
{ value: 'ALL_READ', children: 'ALL_READ', description: t('access-management.roles.permission-all-read') },
{ value: 'READ', children: 'READ', description: t('access-management.roles.permission-read') },
{ value: 'BULK_READ', children: 'BULK_READ', description: t('access-management.roles.permission-bulk-read') },
{ value: 'ALL_WRITE', children: 'ALL_WRITE', description: t('access-management.roles.permission-all-write') },
{ value: 'WRITE', children: 'WRITE', description: t('access-management.roles.permission-write') },
{ value: 'BULK_WRITE', children: 'BULK_WRITE', description: t('access-management.roles.permission-bulk-write') },
{ value: 'MONITOR', children: 'MONITOR', description: t('access-management.roles.permission-monitor') },
{ value: 'CREATE', children: 'CREATE', description: t('access-management.roles.permission-create') },
{ value: 'EXEC', children: 'EXEC', description: t('access-management.roles.permission-exec') },
{ value: 'LISTEN', children: 'LISTEN', description: t('access-management.roles.permission-listen') },
{ value: 'LIFECYCLE', children: 'LIFECYCLE', description: t('access-management.roles.permission-lifecycle') },
{ value: 'NONE', children: 'NONE', description: t('access-management.roles.permission-none') }
];
const initPermissions = () => {
const array: SelectOptionProps[] = [];
PERMISSIONS_MAP.forEach((value, key, map) => {
array.push({
value: key,
children: key,
description: value
});
});
return array;
};
const initialSelectOptions: SelectOptionProps[] = initPermissions();

const roleNameInitialState: IField = {
value: '',
isValid: false,
Expand Down Expand Up @@ -244,10 +241,10 @@ const CreateRole = (props: { isModalOpen: boolean; submitModal: () => void; clos
disableFocusTrap={true}
actions={[
<Button key={'Create'} aria-label={'Create'} variant={ButtonVariant.primary} onClick={handleSubmit}>
{t('access-management.roles.modal-save-action')}
{t('common.actions.save')}
</Button>,
<Button key={'Cancel'} aria-label={'Cancel'} variant={ButtonVariant.link} onClick={onCloseModal}>
{t('access-management.roles.modal-cancel-button')}
{t('common.actions.cancel')}
</Button>
]}
>
Expand Down Expand Up @@ -322,7 +319,7 @@ const CreateRole = (props: { isModalOpen: boolean; submitModal: () => void; clos
{...option}
hasCheckbox
isSelected={selectedPermissions.includes(option.value)}
description={option.description}
description={t(option.description as string)}
ref={null}
/>
))}
Expand Down
4 changes: 2 additions & 2 deletions src/app/AccessManagement/DeleteRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const DeleteRole = (props: { name: string; isModalOpen: boolean; submitModal: ()
onDeleteRole();
}}
>
{t('access-management.roles.delete-action')}
{t('common.actions.delete')}
</Button>,
<Button
key={'Cancel'}
Expand All @@ -37,7 +37,7 @@ const DeleteRole = (props: { name: string; isModalOpen: boolean; submitModal: ()
onClick={props.closeModal}
data-cy="cancelRoleDeleteButton"
>
{t('access-management.roles.modal-cancel-button')}
{t('common.actions.cancel')}
</Button>
]}
>
Expand Down
168 changes: 168 additions & 0 deletions src/app/AccessManagement/RoleDetail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import React, { useEffect, useState } from 'react';
import {
Card,
CardBody,
Dropdown,
DropdownItem,
DropdownList,
MenuToggle,
MenuToggleElement,
Nav,
NavItem,
NavList,
PageSection,
PageSectionVariants,
Text,
TextContent,
TextVariants,
Toolbar,
ToolbarContent,
ToolbarGroup,
ToolbarItem
} from '@patternfly/react-core';
import { useTranslation } from 'react-i18next';
import { DataContainerBreadcrumb } from '@app/Common/DataContainerBreadcrumb';
import { RoleGeneral } from '@app/AccessManagement/RoleDetailContent/RoleGeneral';
import { RolePermissions } from '@app/AccessManagement/RoleDetailContent/RolePermissions';
import { DeleteRole } from '@app/AccessManagement/DeleteRole';
import { useHistory } from 'react-router';
import { useDescribeRole } from '@app/services/rolesHook';

const RoleDetail = (props) => {
const roleName = decodeURIComponent(props.computedMatch.params.roleName);
const history = useHistory();
const { t } = useTranslation();
const { role } = useDescribeRole(roleName);
const [activeTabKey, setActiveTabKey] = useState('0');
const [showGeneralDescription, setShowGeneralDescription] = useState(true);
const [showPermissions, setShowPermissions] = useState(false);
// const [showCaches, setShowCaches] = useState(false);
const [isOpen, setIsOpen] = useState(false);
const [isDeleteRole, setIsDeleteRole] = useState(false);

const onToggleClick = () => {
setIsOpen(!isOpen);
};

const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
setIsOpen(false);
};

useEffect(() => {
setShowGeneralDescription(activeTabKey === '0');
setShowPermissions(activeTabKey === '1');
// setShowCaches(activeTabKey === '2');
}, [activeTabKey]);

interface AccessTab {
key: string;
name: string;
}

const handleTabClick = (event, nav) => {
setActiveTabKey(nav.itemId);
};

const tabs: AccessTab[] = [
{ name: t('access-management.role.tab-general'), key: '0' },
{ name: t('access-management.role.tab-permissions'), key: '1' }
// { name: t('access-management.role.tab-caches'), key: '2' }
];

const buildTabs = () => {
return (
<Nav data-cy="navigationTabs" onSelect={handleTabClick} variant={'tertiary'}>
<NavList>
{tabs.map((tab) => (
<NavItem
aria-label={'nav-item-' + tab.name}
key={'nav-item-' + tab.key}
itemId={tab.key}
isActive={activeTabKey === tab.key}
>
{tab.name}
</NavItem>
))}
</NavList>
</Nav>
);
};

const displayActions = () => {
if (!role || role.implicit) {
return;
}

return (
<ToolbarGroup align={{ default: 'alignRight' }}>
<ToolbarItem>
<Dropdown
isOpen={isOpen}
onSelect={onSelect}
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)}
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle ref={toggleRef} onClick={onToggleClick} isExpanded={isOpen}>
{t('access-management.role.actions')}
</MenuToggle>
)}
ouiaId="roleDetailDropdown"
shouldFocusToggleOnSelect
>
<DropdownList>
<DropdownItem value={0} key="deleteRole" onClick={() => setIsDeleteRole(true)}>
{t('common.actions.delete')}
</DropdownItem>
</DropdownList>
</Dropdown>
</ToolbarItem>
</ToolbarGroup>
);
};

return (
<>
<PageSection variant={PageSectionVariants.light} style={{ paddingBottom: 0 }}>
<DataContainerBreadcrumb
parentPage={'/access-management'}
label={'access-management.title'}
currentPage={t('access-management.role.breadcrumb', { roleName: roleName })}
/>
<Toolbar id="role-detail-toolbar">
<ToolbarContent>
<ToolbarGroup>
<ToolbarItem>
<TextContent>
<Text component={TextVariants.h1}>{roleName}</Text>
</TextContent>
</ToolbarItem>
</ToolbarGroup>
{displayActions()}
</ToolbarContent>
</Toolbar>
{buildTabs()}
</PageSection>
<PageSection variant={PageSectionVariants.default}>
<Card>
<CardBody>
{showGeneralDescription && <RoleGeneral name={roleName} />}
{showPermissions && <RolePermissions name={roleName} />}
{/*{showCaches && <RoleCaches />}*/}
</CardBody>
</Card>
</PageSection>
<DeleteRole
name={roleName}
isModalOpen={isDeleteRole}
submitModal={() => {
setIsDeleteRole(false);
history.push('/access-management');
}}
closeModal={() => {
setIsDeleteRole(false);
}}
/>
</>
);
};

export { RoleDetail };
Loading

0 comments on commit 973ba1a

Please sign in to comment.