-
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
Conversation
@Pe5h4 Can you review pls? |
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 Good, only minor thing. Also, has it been tested also when you dont have any resource given in the props?
)} | ||
{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 comment
The reason will be displayed to describe this comment to others. Learn more.
@aringocode I believe you don need here the optional chaining syntax ?
@Pe5h4 I've tested it now. Assuming the resource comes back undefined. This condition |
Alright |
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 PLease add this option to the documentation
@Pe5h4 What do you mean? Add information that there must be a necessary resource to see the disable item? |
Basically creating the documentation for TreeMenu as we spoke of about :) |
src/components/TreeMenu/index.js
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
I took hasSearch
parameter out of the props because it's only used in this file
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 Not sure about this action, hasSearch
is a part of the TreeMenuItem
and it can be eventually present in the Treemenu. Have you tested it with the hasSearch={true}
option?
src/components/TreeMenu/index.js
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
@aringocode Not sure about this action, hasSearch
is a part of the TreeMenuItem
and it can be eventually present in the Treemenu. Have you tested it with the hasSearch={true}
option?
doc/tree-menu.md
Outdated
|
||
- `data`: object or array, data in a special structure. The detailed data structure is described in the library documentation react-simple-tree-menu. | ||
|
||
- `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 comment
The reason will be displayed to describe this comment to others. Learn more.
@aringocode Its not a placeholer, it should render the Search
for the TreeMenu
doc/tree-menu.md
Outdated
|
||
- `hasSearch`: boolean, changes the styles for the search input and affects the display of placeholder | ||
|
||
- `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 comment
The reason will be displayed to describe this comment to others. Learn more.
@aringocode I dont understand this :(
doc/tree-menu.md
Outdated
- `resource`: string, resource granting display disabled tree-menu-item elements | ||
|
||
|
||
#### Optional: |
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.
There are more optional props, I would just add reference to this: https://github.com/iannbing/react-simple-tree-menu#api
doc/tree-menu.md
Outdated
## 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. | ||
|
||
- `resource`: string, resource granting display disabled tree-menu-item elements | ||
|
||
|
||
#### Optional: | ||
|
||
- `searchOptions`: object, conducts placeholder and the dropdown component | ||
|
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.
I think you can leave the very minimum of parameters in this documentation, because the parameters for a library are described in its documentation. And here will be only those parameters that we use in our component (resource, searchOption)
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 Only minor refactorisation request with the resource/resources being an optional prop
}) => { | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
@aringocode I think resources should be also passed to <TreeMenu />
as a prop, like we said - resource/resources should be a optional argument. Take a look to the ButtonWithAuthz, it has a similar approach - and why I think its better to do it this way?Because we will loose a dependency to some parts of the application when we will be decoupling the UI's to microfrontend apps
)} | ||
{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 comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, good. Test that also in Configuration
part of the UI please :)
@Pe5h4 I've tested it in all cases. configuration and library are displayed correctly |
src/components/TreeMenu/index.js
Outdated
@@ -9,7 +9,7 @@ import SimpleTreeMenu from 'react-simple-tree-menu'; | |||
import TreeMenuItem from "./TreeMenuItem"; | |||
|
|||
const TreeMenu = ({ | |||
data, searchOptions, ...props | |||
data, searchOptions, resources, ...props |
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 Not necessary, resources
are part of ...props
src/components/TreeMenu/index.js
Outdated
@@ -45,6 +45,7 @@ const TreeMenu = ({ | |||
{items.map(({ reset, ...props }) => ( | |||
<TreeMenuItem | |||
active="false" | |||
resources={resources} |
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 Not necessary here
@@ -24,28 +26,32 @@ const TreeMenuItem = ({ | |||
props.onClick && props.onClick(); | |||
} | |||
|
|||
|
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 Remove this empty line please
const paddingLeft = 1.25 * level + 0.5; | ||
const selected = focused ? " selected" : ""; | ||
const disabled = (isDisabled || sessionExpired) ? " disabled" : ""; | ||
// const showDisabledItems = isDisabled && resources && resource && |
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 Remove commented obsolete code
}) => { | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
@aringocode Remove commented obsolete code please :)
... | ||
|
||
<TreeMenu | ||
resource={resource} |
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? :)
|
||
- `searchOptions`: object, conducts placeholder and the dropdown component | ||
|
||
- `resource`: string, resource granting display disabled tree-menu-item elements |
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 Add also info about that resources
are optional argument
doc/tree-menu.md
Outdated
|
||
- `resource`: string, resource granting display disabled tree-menu-item elements | ||
|
||
- `resources`: array, list of resources that the user has |
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 resources: array, list of resources that the user has assigned
<TreeMenuItem | ||
active="false" | ||
{...params} |
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 Anyway, are the ...params
used anywhere? I dont see the being used in the TreeMenuItem
so I suppose you want to pass the {...params}
to the <li>
or somewhere, not to loose TreeMenuItem behavior
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.
What was originally passed to the TreeMenuItem when using just {...props}
?
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 Well, anyway, I just wanted some information, nevertheless, your previous solution with passing {...props}
together with {...params}
was ok. What I wanted was just answer to my questions, why did you choose this solution and if it is propely handled in the <TreeMenuItem />
component :)
<TreeMenuItem | ||
active="false" | ||
{...params} |
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 Well, anyway, I just wanted some information, nevertheless, your previous solution with passing {...props}
together with {...params}
was ok. What I wanted was just answer to my questions, why did you choose this solution and if it is propely handled in the <TreeMenuItem />
component :)
@Pe5h4 Yes, it is processed correctly. Props from the parent component did not come before, so I think we can leave this solution to avoid passing unnecessary parameters:
|
Changes
resource-treemenu-item.mp4