-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add resource for tree-menu-item #437
Changes from 9 commits
5d76c75
ae038d9
7a00246
a32e013
740a46f
5b96399
0d3e581
0136301
a86aaf6
3d79eff
4031a15
03da9be
994b12b
5a7dc22
501fa52
7acfbde
6ebb35d
67662d3
4d1b6fc
6c52111
574e133
9932bdd
c5ad003
b52266a
36aa35c
570842d
953674b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 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'; | ||
... | ||
|
||
<TreeMenu | ||
resource={resource} | ||
data={treeData} | ||
hasSearch={true} | ||
hasNodes={true} // default: false | ||
searchOptions={{ | ||
placeholder: t("Search"), | ||
dropdown: { | ||
title: t("Actions"), | ||
children: ChildrenCustomDropdownComponent | ||
} | ||
}} | ||
/> | ||
|
||
``` | ||
|
||
|
||
## Props: | ||
|
||
#### Required: | ||
|
||
- `data`: object or array, data in a special structure. The detailed data structure is described in the library documentation react-simple-tree-menu. | ||
Pe5h4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- `hasSearch`: boolean, changes the styles for the search input and affects the display of placeholder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aringocode Its not a placeholer, it should render the |
||
|
||
- `hasNodes`: boolean, if a `TreeNode` is the last node of its branch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aringocode I dont understand this :( |
||
|
||
- `resource`: string, resource granting display disabled tree-menu-item elements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aringocode Add also info about that |
||
|
||
|
||
#### Optional: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are more optional props, I would just add reference to this: https://github.com/iannbing/react-simple-tree-menu#api |
||
- `searchOptions`: object, conducts placeholder and the dropdown component | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ const TreeMenuItem = ({ | |
level = 0, hasNodes, isOpen, | ||
label, searchTerm, openNodes, | ||
toggleNode, matchSearch, focused, | ||
type, isDisabled, ...props | ||
type, isDisabled, resource, ...props | ||
}) => { | ||
const sessionExpired = useSelector(state => state.auth?.sessionExpired); | ||
const resources = useSelector(state => state.auth?.resources); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aringocode I think resources should be also passed to |
||
const paddingLeft = 1.25 * level + 0.5; | ||
const selected = focused ? " selected" : ""; | ||
const disabled = (isDisabled || sessionExpired) ? " disabled" : ""; | ||
|
@@ -24,28 +25,32 @@ const TreeMenuItem = ({ | |
props.onClick && props.onClick(); | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aringocode Remove this empty line please |
||
return ( | ||
<li | ||
{...props} | ||
active="false" | ||
className={`tree-menu-item${selected}${disabled}`} | ||
style={{ paddingLeft: `${paddingLeft}rem` }} | ||
onClick={e => {handleClick(e)}} | ||
> | ||
{(type == "folder") && ( | ||
<div | ||
style={{ display: 'inline-block' }} | ||
// Clickable toggle icon, not restricted as handleClick method | ||
onClick={e => { | ||
e.stopPropagation(); | ||
hasNodes && toggleNode && toggleNode(); | ||
}} | ||
> | ||
<ToggleIcon on={isOpen} selected={selected} /> | ||
</div> | ||
)} | ||
{label} | ||
</li> | ||
isDisabled && (resources.indexOf(resource) == -1) && (resources.indexOf("authz:superuser") == -1) ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aringocode Are you aware of that this feature will hide all the content in the Treemenu when e.g. session will expire? I think this has to be handled a bit different way. Also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Pe5h4 I tested, if the session ends, the items don't disappear anywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aringocode Are you sure, even tho when the testing user does not have superuser rights or correct resource? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Pe5h4 Yeah, I'm sure. These screenshots show resources for a user without access to disabled items and superuser. As you can see in these screenshots, the items did not disappear after the session ended. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, good. Test that also in |
||
null | ||
: | ||
<li | ||
{...props} | ||
active="false" | ||
className={`tree-menu-item${selected}${disabled}`} | ||
style={{ paddingLeft: `${paddingLeft}rem` }} | ||
onClick={e => {handleClick(e)}} | ||
> | ||
{(type == "folder") && ( | ||
<div | ||
style={{ display: 'inline-block' }} | ||
// Clickable toggle icon, not restricted as handleClick method | ||
onClick={e => { | ||
e.stopPropagation(); | ||
hasNodes && toggleNode && toggleNode(); | ||
}} | ||
> | ||
<ToggleIcon on={isOpen} selected={selected} /> | ||
</div> | ||
)} | ||
{label} | ||
</li> | ||
) | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import SimpleTreeMenu from 'react-simple-tree-menu'; | |
import TreeMenuItem from "./TreeMenuItem"; | ||
|
||
const TreeMenu = ({ | ||
data, searchOptions, ...props | ||
data, searchOptions, hasSearch, ...props | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aringocode Not sure about this action, |
||
}) => { | ||
const [isDropdownMenuOpen, setDropdownMenu] = useState(false); | ||
|
||
|
@@ -22,20 +22,20 @@ const TreeMenu = ({ | |
{({ search, items }) => ( | ||
<> | ||
<InputGroup> | ||
<InputGroupText className={props.hasSearch ? "p-0 border-0" : "p-0 border-0 w-100"}> | ||
<InputGroupText className={hasSearch ? "p-0 border-0" : "p-0 border-0 w-100"}> | ||
{searchOptions?.dropdown && ( | ||
<ButtonDropdown | ||
className={props.hasSearch ? "" : "w-100"} | ||
className={hasSearch ? "" : "w-100"} | ||
size="sm" | ||
isOpen={isDropdownMenuOpen} | ||
toggle={() => setDropdownMenu(prev => !prev)} | ||
> | ||
<DropdownToggle className={props.hasSearch ? "" : "w-100"} caret>{searchOptions.dropdown.title}</DropdownToggle> | ||
<DropdownToggle className={hasSearch ? "" : "w-100"} caret>{searchOptions.dropdown.title}</DropdownToggle> | ||
{searchOptions.dropdown.children} | ||
</ButtonDropdown> | ||
)} | ||
</InputGroupText> | ||
{props.hasSearch && | ||
{hasSearch && | ||
<Input | ||
onChange={e => search(e.target.value)} | ||
placeholder={searchOptions?.placeholder} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aringocode If there is a resource in the example, there should be also
resources
, innit? :)