mirror of
https://github.com/sasjs/server.git
synced 2026-01-06 22:20:06 +00:00
fix: modify the directory tree algorithm to include relative path with each node
This commit is contained in:
@@ -16,9 +16,10 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
|
|||||||
import ChevronRightIcon from '@mui/icons-material/ChevronRight'
|
import ChevronRightIcon from '@mui/icons-material/ChevronRight'
|
||||||
|
|
||||||
interface TreeNode {
|
interface TreeNode {
|
||||||
path: string
|
|
||||||
name: string
|
name: string
|
||||||
children?: readonly TreeNode[]
|
relativePath: string
|
||||||
|
absolutePath: string
|
||||||
|
children: Array<TreeNode>
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStyles = makeStyles(() => ({
|
const useStyles = makeStyles(() => ({
|
||||||
@@ -49,21 +50,21 @@ const SideBar = (props: any) => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleSelect = (node: TreeNode) => {
|
const handleSelect = (node: TreeNode) => {
|
||||||
if (!node.children) {
|
if (!node.children.length) {
|
||||||
window.history.pushState(
|
window.history.pushState(
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
`${baseUrl}/SASjsDrive?filepath=${node.path}`
|
`${baseUrl}/SASjsDrive?filepath=${node.relativePath}`
|
||||||
)
|
)
|
||||||
props.setSelectedFilePath(node.path)
|
props.setSelectedFilePath(node.relativePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderTree = (nodes: TreeNode) => (
|
const renderTree = (nodes: TreeNode) => (
|
||||||
<TreeItem
|
<TreeItem
|
||||||
classes={{ root: classes.root }}
|
classes={{ root: classes.root }}
|
||||||
key={nodes.path}
|
key={nodes.relativePath}
|
||||||
nodeId={nodes.path}
|
nodeId={nodes.relativePath}
|
||||||
label={
|
label={
|
||||||
<ListItem
|
<ListItem
|
||||||
className={classes.listItem}
|
className={classes.listItem}
|
||||||
|
|||||||
@@ -1,7 +1,40 @@
|
|||||||
import dirTree from 'directory-tree'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import { TreeNode } from '../types'
|
||||||
|
import { getTmpFilesFolderPath } from '../utils'
|
||||||
|
|
||||||
export const sasjsExecutor = () => {
|
export const sasjsExecutor = () => {
|
||||||
const tree = dirTree(path.join(__dirname, '..', '..', 'tmp'))
|
const root: TreeNode = {
|
||||||
return tree
|
name: 'files',
|
||||||
|
relativePath: '',
|
||||||
|
absolutePath: getTmpFilesFolderPath(),
|
||||||
|
children: []
|
||||||
|
}
|
||||||
|
|
||||||
|
const stack = [root]
|
||||||
|
|
||||||
|
while (stack.length) {
|
||||||
|
const currentNode = stack.pop()
|
||||||
|
|
||||||
|
if (currentNode) {
|
||||||
|
const children = fs.readdirSync(currentNode.absolutePath)
|
||||||
|
|
||||||
|
for (let child of children) {
|
||||||
|
const absoluteChildPath = `${currentNode.absolutePath}/${child}`
|
||||||
|
const relativeChildPath = `${currentNode.relativePath}/${child}`
|
||||||
|
const childNode: TreeNode = {
|
||||||
|
name: child,
|
||||||
|
relativePath: relativeChildPath,
|
||||||
|
absolutePath: absoluteChildPath,
|
||||||
|
children: []
|
||||||
|
}
|
||||||
|
currentNode.children.push(childNode)
|
||||||
|
|
||||||
|
if (fs.statSync(childNode.absolutePath).isDirectory()) {
|
||||||
|
stack.push(childNode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return root
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user