-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
438 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import * as React from 'react'; | ||
import { useState } from 'react'; | ||
import { | ||
Card, | ||
CardBody, | ||
Nav, | ||
NavItem, | ||
NavList, | ||
PageSection, | ||
PageSectionVariants, | ||
Text, | ||
TextContent, | ||
TextVariants | ||
} from '@patternfly/react-core'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { RoleTableDisplay } from '@app/AccessManagement/RoleTableDisplay'; | ||
|
||
const AccessManager = () => { | ||
const { t } = useTranslation(); | ||
const brandname = t('brandname.brandname'); | ||
const [activeTabKey, setActiveTabKey] = useState('0'); | ||
const [showRoles, setShowRoles] = useState(true); | ||
const [showAccessControl, setShowAccessControl] = useState(false); | ||
|
||
interface AccessTab { | ||
key: string; | ||
name: string; | ||
} | ||
const handleTabClick = (nav) => { | ||
const tabIndex = nav.itemId; | ||
setActiveTabKey(tabIndex); | ||
setShowRoles(tabIndex == '0'); | ||
setShowAccessControl(tabIndex == '1'); | ||
}; | ||
const buildTabs = () => { | ||
const tabs: AccessTab[] = [ | ||
{ name: t('access-management.tab-roles'), key: '0' }, | ||
]; | ||
|
||
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 buildSelectedContent = ( | ||
<Card> | ||
<CardBody> | ||
{showRoles && <RoleTableDisplay />} | ||
{showAccessControl && <div>Access Control</div>} | ||
</CardBody> | ||
</Card> | ||
); | ||
|
||
return ( | ||
<> | ||
<PageSection variant={PageSectionVariants.light} style={{ paddingBottom: 0 }}> | ||
<TextContent style={{ marginBottom: '1rem' }}> | ||
<Text component={TextVariants.h1}>{t('access-management.title')}</Text> | ||
<Text component={TextVariants.p}>{t('access-management.description', { brandname: brandname })}</Text> | ||
</TextContent> | ||
{buildTabs()} | ||
</PageSection> | ||
<PageSection variant={PageSectionVariants.default}>{buildSelectedContent}</PageSection> | ||
</> | ||
); | ||
}; | ||
|
||
export { AccessManager }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
Bullseye, | ||
Chip, | ||
ChipGroup, | ||
EmptyState, | ||
EmptyStateBody, | ||
EmptyStateIcon, | ||
EmptyStateVariant, | ||
Icon, | ||
Pagination, | ||
SearchInput, | ||
Title, | ||
Toolbar, | ||
ToolbarContent, | ||
ToolbarFilter, | ||
ToolbarGroup, | ||
ToolbarItem, | ||
ToolbarItemVariant | ||
} from '@patternfly/react-core'; | ||
import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { LockIcon, SearchIcon } from '@patternfly/react-icons'; | ||
import { useFetchAvailableRoles } from '@app/services/rolesHook'; | ||
import { filterRoles } from '@app/utils/searchFilter'; | ||
import { RoleFilterOption } from '@services/infinispanRefData'; | ||
|
||
const RoleTableDisplay = () => { | ||
const { t } = useTranslation(); | ||
const brandname = t('brandname.brandname'); | ||
const { roles, loading, error } = useFetchAvailableRoles(); | ||
const [selectSearchOption, setSelectSearchOption] = useState<string>(RoleFilterOption.name); | ||
const [searchValue, setSearchValue] = useState<string>(''); | ||
const [rolesPagination, setRolesPagination] = useState({ | ||
page: 1, | ||
perPage: 10 | ||
}); | ||
|
||
const [filteredRoles, setFilteredRoles] = useState<Role[]>([]); | ||
|
||
useEffect(() => { | ||
if (searchValue !== '') { | ||
setFilteredRoles(filterRoles(searchValue, roles, selectSearchOption)); | ||
} else { | ||
setFilteredRoles(roles); | ||
} | ||
}, [searchValue, roles]); | ||
|
||
const columnNames = { | ||
name: t('access-management.roles.role-name'), | ||
permissions: t('access-management.roles.permissions'), | ||
description: t('access-management.roles.role-description') | ||
}; | ||
|
||
const onSetPage = (_event, pageNumber) => { | ||
setRolesPagination({ | ||
...rolesPagination, | ||
page: pageNumber | ||
}); | ||
}; | ||
|
||
const onPerPageSelect = (_event, perPage) => { | ||
setRolesPagination({ | ||
page: 1, | ||
perPage: perPage | ||
}); | ||
}; | ||
|
||
const onSearchChange = (value: string) => { | ||
setSearchValue(value); | ||
}; | ||
|
||
const pagination = ( | ||
<Pagination | ||
itemCount={roles.length} | ||
perPage={rolesPagination.perPage} | ||
page={rolesPagination.page} | ||
onSetPage={onSetPage} | ||
widgetId="pagination-roles" | ||
onPerPageSelect={onPerPageSelect} | ||
isCompact | ||
/> | ||
); | ||
|
||
const buildSearch = ( | ||
<ToolbarGroup variant="filter-group"> | ||
<ToolbarFilter categoryName={selectSearchOption}> | ||
<SearchInput | ||
placeholder={`Find by ${selectSearchOption}`} | ||
value={searchValue} | ||
onChange={(_event, value) => onSearchChange(value)} | ||
onSearch={(_event, value) => onSearchChange(value)} | ||
onClear={() => setSearchValue('')} | ||
/> | ||
</ToolbarFilter> | ||
</ToolbarGroup> | ||
); | ||
|
||
return ( | ||
<React.Fragment> | ||
<Toolbar id="role-table-toolbar" className={'role-table-display'}> | ||
<ToolbarContent> | ||
{buildSearch} | ||
<ToolbarItem variant={ToolbarItemVariant.pagination}>{pagination}</ToolbarItem> | ||
</ToolbarContent> | ||
</Toolbar> | ||
<Table className={'roles-table'} aria-label={'roles-table-label'} variant={'compact'}> | ||
<Thead noWrap> | ||
<Tr> | ||
<Th info={{ | ||
popover: ( | ||
<div> | ||
{t("access-management.roles.role-name-tooltip")} | ||
</div> | ||
), | ||
ariaLabel: 'Role name more information', | ||
popoverProps: { | ||
headerContent: columnNames.name, | ||
footerContent: ( | ||
<a target="_blank" rel='noreferrer' href={t("brandname.default-roles-docs-link")}> | ||
{t("access-management.roles.roles-hint-link", { brandname: brandname })} | ||
</a> | ||
) | ||
} | ||
}}> | ||
{columnNames.name} | ||
</Th> | ||
<Th>{columnNames.permissions}</Th> | ||
<Th>{columnNames.description}</Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{filteredRoles.length == 0 ? ( | ||
<Tr> | ||
<Td colSpan={3}> | ||
<Bullseye> | ||
<EmptyState variant={EmptyStateVariant.sm}> | ||
<EmptyStateIcon icon={SearchIcon} /> | ||
<Title headingLevel="h2" size="lg"> | ||
{t('access-management.roles.no-roles-found')} | ||
</Title> | ||
<EmptyStateBody> | ||
{roles.length == 0 | ||
? t('access-management.roles.no-roles-body') | ||
: t('access-management.roles.no-filtered-roles-body')} | ||
</EmptyStateBody> | ||
</EmptyState> | ||
</Bullseye> | ||
</Td> | ||
</Tr> | ||
) : ( | ||
filteredRoles.map((row) => { | ||
return ( | ||
<Tr key={row.name}> | ||
<Td dataLabel={columnNames.name} width={15}> | ||
{ row.implicit && | ||
<Icon size="sm" isInline> | ||
<LockIcon className="role-icon" /> | ||
</Icon> | ||
} | ||
{row.name} | ||
</Td> | ||
<Td dataLabel={columnNames.permissions} width={30}>{ | ||
<ChipGroup> | ||
{row.permissions.map(currentChip => ( | ||
<Chip key={currentChip} isReadOnly={true}> | ||
{currentChip} | ||
</Chip> | ||
))} | ||
</ChipGroup> | ||
}</Td> | ||
<Td dataLabel={columnNames.description}>{row.description}</Td> | ||
</Tr> | ||
); | ||
}) | ||
)} | ||
</Tbody> | ||
</Table> | ||
<Toolbar id="role-table-toolbar" className={'role-table-display'}> | ||
<ToolbarItem variant={ToolbarItemVariant.pagination}>{pagination}</ToolbarItem> | ||
</Toolbar> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export { RoleTableDisplay }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.