diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b9ecefdb..b6f1a57ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,8 @@ - Change "?" in HelpButton to word "Help" (INDIGO Sprint 230721, [!439](https://github.com/TeskaLabs/asab-webui/pull/439)) +- Add a condition that will allow users with the right resource to see hidden tree-menu-items, add docs for TreeMenu (INDIGO Sprint 230721, [!437](https://github.com/TeskaLabs/asab-webui/pull/437)) + ### Bugfix - Bug fix for HelpComponent, not display a Helpcomoponent when the user changing the page (INDIGO Sprint 230317, [!401](https://github.com/TeskaLabs/asab-webui/pull/401)) diff --git a/doc/tree-menu.md b/doc/tree-menu.md new file mode 100644 index 000000000..4fba3e578 --- /dev/null +++ b/doc/tree-menu.md @@ -0,0 +1,46 @@ +# ASAB WebUI TreeMenu component + +This component is based on the library [react-simple-tree-menu](https://github.com/iannbing/react-simple-tree-menu). + +Displays menu items in a clear structure. + +## Example code + +```javascript +import { TreeMenu } from 'asab-webui'; +... + + + +``` + + +## Props: +More parameters can be found [here](https://github.com/iannbing/react-simple-tree-menu#api). + +#### Required: + + - `data`: object or array, data in a special structure. The detailed data structure is described in the library documentation react-simple-tree-menu. + + +#### Optional: + + - `searchOptions`: object, conducts placeholder and the dropdown component + + - `resource`: string, resource granting display disabled tree-menu-item elements + + - `resources`: resources: array, list of resources that the user has assigned + diff --git a/src/components/TreeMenu/TreeMenuItem.js b/src/components/TreeMenu/TreeMenuItem.js index c989386b5..e9b82e5a5 100644 --- a/src/components/TreeMenu/TreeMenuItem.js +++ b/src/components/TreeMenu/TreeMenuItem.js @@ -7,13 +7,12 @@ const TreeMenuItem = ({ level = 0, hasNodes, isOpen, label, searchTerm, openNodes, toggleNode, matchSearch, focused, - type, isDisabled, ...props + type, isDisabled, resource, resources, ...props }) => { const sessionExpired = useSelector(state => state.auth?.sessionExpired); const paddingLeft = 1.25 * level + 0.5; const selected = focused ? " selected" : ""; const disabled = (isDisabled || sessionExpired) ? " disabled" : ""; - // Method to manage clicks on whole rows of the Tree item const handleClick = (e) => { // If type is folder and node is closed, make whole line clickable for toggling nodes @@ -25,27 +24,30 @@ const TreeMenuItem = ({ } return ( -
  • {handleClick(e)}} - > - {(type == "folder") && ( -
    { - e.stopPropagation(); - hasNodes && toggleNode && toggleNode(); - }} - > - -
    - )} - {label} -
  • + isDisabled && resources && (resources.indexOf(resource) == -1) && (resources.indexOf("authz:superuser") == -1) ? + null + : +
  • {handleClick(e)}} + > + {(type == "folder") && ( +
    { + e.stopPropagation(); + hasNodes && toggleNode && toggleNode(); + }} + > + +
    + )} + {label} +
  • ) }; diff --git a/src/components/TreeMenu/index.js b/src/components/TreeMenu/index.js index c19bdb659..d55384e48 100644 --- a/src/components/TreeMenu/index.js +++ b/src/components/TreeMenu/index.js @@ -12,7 +12,6 @@ const TreeMenu = ({ data, searchOptions, ...props }) => { const [isDropdownMenuOpen, setDropdownMenu] = useState(false); - return (
    } - {items.map(({ reset, ...props }) => ( + {items.map(({ reset, ...params }) => ( ))} diff --git a/src/modules/maintenance/ConfigModule/ConfigContainers/TreeViewComponent.js b/src/modules/maintenance/ConfigModule/ConfigContainers/TreeViewComponent.js index 2985d4e52..f6afdf5bc 100644 --- a/src/modules/maintenance/ConfigModule/ConfigContainers/TreeViewComponent.js +++ b/src/modules/maintenance/ConfigModule/ConfigContainers/TreeViewComponent.js @@ -5,12 +5,7 @@ import { useTranslation } from 'react-i18next'; import { TreeMenu } from 'asab-webui'; import { types } from './actions/actions'; -import { - Input, - InputGroup, InputGroupText, - ButtonDropdown, DropdownToggle, - DropdownMenu, DropdownItem -} from "reactstrap"; +import { DropdownMenu, DropdownItem } from "reactstrap"; export function TreeViewComponent(props) {