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:
@@ -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)
|
||||
|
||||
@@ -2,5 +2,6 @@ export interface TreeNode {
|
||||
name: string
|
||||
relativePath: string
|
||||
absolutePath: string
|
||||
isFolder: boolean
|
||||
children: Array<TreeNode>
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ const TreeViewNode = ({
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{hasChild &&
|
||||
{node.isFolder &&
|
||||
['Add Folder', 'Add File'].map((item) => (
|
||||
<MenuItem key={item}>{item}</MenuItem>
|
||||
))}
|
||||
|
||||
@@ -34,5 +34,6 @@ export interface RegisterPermissionPayload {
|
||||
export interface TreeNode {
|
||||
name: string
|
||||
relativePath: string
|
||||
isFolder: boolean
|
||||
children: Array<TreeNode>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user