1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00

fix: fileTree api response to include an additional attribute isFolder

This commit is contained in:
2022-07-19 16:13:46 +05:00
parent 6c35412d2f
commit 0f19384999
4 changed files with 12 additions and 2 deletions

View File

@@ -143,6 +143,7 @@ export class ExecutionController {
name: 'files',
relativePath: '',
absolutePath: getFilesFolder(),
isFolder: true,
children: []
}
@@ -152,15 +153,22 @@ export class ExecutionController {
const currentNode = stack.pop()
if (currentNode) {
currentNode.isFolder = fs
.statSync(currentNode.absolutePath)
.isDirectory()
const children = fs.readdirSync(currentNode.absolutePath)
for (let child of children) {
const absoluteChildPath = `${currentNode.absolutePath}/${child}`
const absoluteChildPath = path.join(currentNode.absolutePath, child)
// relative path will only be used in frontend component
// so, no need to convert '/' to platform specific separator
const relativeChildPath = `${currentNode.relativePath}/${child}`
const childNode: TreeNode = {
name: child,
relativePath: relativeChildPath,
absolutePath: absoluteChildPath,
isFolder: false,
children: []
}
currentNode.children.push(childNode)

View File

@@ -2,5 +2,6 @@ export interface TreeNode {
name: string
relativePath: string
absolutePath: string
isFolder: boolean
children: Array<TreeNode>
}

View File

@@ -126,7 +126,7 @@ const TreeViewNode = ({
: undefined
}
>
{hasChild &&
{node.isFolder &&
['Add Folder', 'Add File'].map((item) => (
<MenuItem key={item}>{item}</MenuItem>
))}

View File

@@ -34,5 +34,6 @@ export interface RegisterPermissionPayload {
export interface TreeNode {
name: string
relativePath: string
isFolder: boolean
children: Array<TreeNode>
}