2022-03-23 15:25:28 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import TreeView from '@mui/lab/TreeView';
|
|
|
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
|
|
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
|
|
|
import TreeItem from '@mui/lab/TreeItem';
|
2022-04-19 04:39:51 +00:00
|
|
|
import {useRouter} from 'next/router'
|
|
|
|
import {styled} from '@mui/material/styles';
|
|
|
|
|
|
|
|
const TCTreeItem = styled(TreeItem)(({theme}) => ({
|
|
|
|
'& .MuiTreeItem-content': {
|
|
|
|
'& .MuiTreeItem-label': {
|
|
|
|
fontSize: '1rem',
|
|
|
|
paddingLeft: '6px',
|
|
|
|
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif,',
|
2022-04-19 04:41:07 +00:00
|
|
|
lineHeight: 2.0,
|
2022-04-19 04:39:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2022-03-23 15:25:28 +00:00
|
|
|
|
|
|
|
export default function FolderTree(props) {
|
|
|
|
const renderTree = (nodes) => (
|
2022-04-19 04:39:51 +00:00
|
|
|
<TCTreeItem key={nodes.id} nodeId={nodes.id} label={nodes.name}>
|
2022-03-23 15:25:28 +00:00
|
|
|
{Array.isArray(nodes.children)
|
|
|
|
? nodes.children.map((node) => renderTree(node))
|
|
|
|
: null}
|
2022-04-19 04:39:51 +00:00
|
|
|
</TCTreeItem>
|
2022-03-23 15:25:28 +00:00
|
|
|
);
|
|
|
|
|
2022-03-24 04:15:43 +00:00
|
|
|
const router = useRouter()
|
2022-03-24 08:19:01 +00:00
|
|
|
// const childrenNodeIds = props.tree.children.map(aNode => {return aNode.id})
|
|
|
|
const expandedNodes = [props.tree.id]
|
2022-03-23 15:25:28 +00:00
|
|
|
return (
|
|
|
|
<TreeView
|
|
|
|
aria-label="rich object"
|
2022-04-19 04:39:51 +00:00
|
|
|
defaultCollapseIcon={<ExpandMoreIcon/>}
|
2022-03-24 08:19:01 +00:00
|
|
|
defaultExpanded={expandedNodes}
|
2022-04-19 04:39:51 +00:00
|
|
|
defaultExpandIcon={<ChevronRightIcon/>}
|
|
|
|
onNodeSelect={(event, nodIds) => {
|
|
|
|
const currentNode = props.flattenNodes.find(aNode => {
|
|
|
|
return aNode.id === nodIds
|
|
|
|
})
|
2022-03-24 04:15:43 +00:00
|
|
|
// console.log(event)
|
|
|
|
// console.log(currentNode)
|
|
|
|
if (currentNode != null && currentNode.routePath != null) {
|
|
|
|
router.push(currentNode.routePath)
|
2022-04-18 10:53:23 +00:00
|
|
|
// router.reload()
|
2022-03-24 04:15:43 +00:00
|
|
|
}
|
|
|
|
}}
|
2022-04-19 04:39:51 +00:00
|
|
|
sx={{flexGrow: 1, maxWidth: 400, overflowY: 'auto'}}
|
2022-03-23 15:25:28 +00:00
|
|
|
>
|
|
|
|
{renderTree(props.tree)}
|
|
|
|
</TreeView>
|
|
|
|
);
|
|
|
|
}
|