Skip to content

[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

Merged
merged 2 commits into from
Aug 16, 2023
Merged

[UI] Add Toc in Sidebar #458

merged 2 commits into from
Aug 16, 2023

Conversation

senwang86
Copy link
Collaborator

@senwang86 senwang86 commented Aug 15, 2023

Summary

  • Toc enables the viewport center.
  • Will add more follow-up UI tuning in future

Test

yarn add @mui/lab @mui/material

toc

Comment on lines 1234 to 1255
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;
}

Copy link
Collaborator

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>)
}

<>
{jsx}
<TocPodButton id={child.id} />
{toc.has(child.id) ? <ul>{dfs(child.id, toc, nodesMap)}</ul> : null}
Copy link
Collaborator

@lihebi lihebi Aug 15, 2023

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.

Copy link
Collaborator Author

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.

@lihebi
Copy link
Collaborator

lihebi commented Aug 15, 2023

Instead of showing (full) IDs, some options (ordered by priority, high to low):

  1. show pod/scope title (.name)
  2. show the title/first-line of rich text content
  3. show the function defined in code pod (I'll populate the parse result somewhere)
  4. show a shortened ID (e.g., first 8 characters)

@senwang86
Copy link
Collaborator Author

Instead of showing (full) IDs, some options (ordered by priority, high to low):

  1. show pod/scope title (.name)
  2. show the title/first-line of rich text content
  3. show the function defined in code pod (I'll populate the parse result somewhere)
  4. show a shortened ID (e.g., first 8 characters)

1d71993 addresses comments.

@senwang86
Copy link
Collaborator Author

senwang86 commented Aug 16, 2023

  1. show a shortened ID (e.g., first 8 characters)

1d71993 addresses comments.

@lihebi
Copy link
Collaborator

lihebi commented Aug 16, 2023

Nice, thanks!

@lihebi lihebi merged commit 93dfeb3 into codepod-io:main Aug 16, 2023
@senwang86 senwang86 deleted the Toc branch September 7, 2023 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants