-
Notifications
You must be signed in to change notification settings - Fork 16
[UI] Add Toc in Sidebar #458
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
Conversation
ui/src/components/Sidebar.tsx
Outdated
function dfs( | ||
nodeId: string, | ||
toc: Map<string, ReactflowNode[]>, | ||
nodesMap: Y.Map<ReactflowNode<NodeData>> | ||
) { | ||
let jsx = <></>; | ||
|
||
if (toc.has(nodeId) && toc.get(nodeId)!.length > 0) { | ||
toc.get(nodeId)?.forEach((child) => { | ||
jsx = ( | ||
<> | ||
{jsx} | ||
<TocPodButton id={child.id} /> | ||
{toc.has(child.id) ? <ul>{dfs(child.id, toc, nodesMap)}</ul> : null} | ||
</> | ||
); | ||
}); | ||
} | ||
|
||
return jsx; | ||
} | ||
|
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.
This isn't "React style" code.
// Component must be CamelCase
function ToC({id}) {
if (!toc.has(id)) return null; // Return early
const children = toc.get(id)
return ( // directly return the Component, not assign and return a variable
<Box>
<TocPodButton id={child.id} />
{children.map(child=>(
// ToC is used directly as a component name.
// A non-CamelCase function cannot be used as a component name.
<ToC id={child}/>
))}
</Box>)
}
ui/src/components/Sidebar.tsx
Outdated
<> | ||
{jsx} | ||
<TocPodButton id={child.id} /> | ||
{toc.has(child.id) ? <ul>{dfs(child.id, toc, nodesMap)}</ul> : null} |
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.
You are using <ul>
to control padding and using ListItem
to show lists. These two things sound like two alternatives to achieve the same functionality, not to be used together.
How about using MUI's TreeView? It seems to offer a good padded UI with additional features such as folding and multi-selection.
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.
TreeView is indeed a better option.
Instead of showing (full) IDs, some options (ordered by priority, high to low):
|
1d71993 addresses comments. |
1d71993 addresses comments. |
Nice, thanks! |
Summary
Test
yarn add @mui/lab @mui/material