mirror of
https://github.com/sasjs/server.git
synced 2026-01-10 07:50:05 +00:00
fix(web-drive): upon delete remove entry of deleted file from directory tree in sidebar
This commit is contained in:
@@ -54,11 +54,47 @@ const Drive = () => {
|
|||||||
setSelectedFilePath(node.relativePath)
|
setSelectedFilePath(node.relativePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const removeFileFromTree = (path: string) => {
|
||||||
|
if (directoryData) {
|
||||||
|
const newTree = JSON.parse(JSON.stringify(directoryData)) as TreeNode
|
||||||
|
findAndRemoveNode(newTree, newTree, path)
|
||||||
|
setDirectoryData(newTree)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const findAndRemoveNode = (
|
||||||
|
node: TreeNode,
|
||||||
|
parentNode: TreeNode,
|
||||||
|
path: string
|
||||||
|
) => {
|
||||||
|
if (node.relativePath === path) {
|
||||||
|
removeNodeFromParent(parentNode, path)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (Array.isArray(node.children)) {
|
||||||
|
for (let i = 0; i < node.children.length; i++) {
|
||||||
|
if (findAndRemoveNode(node.children[i], node, path)) return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeNodeFromParent = (parent: TreeNode, path: string) => {
|
||||||
|
const index = parent.children.findIndex(
|
||||||
|
(node) => node.relativePath === path
|
||||||
|
)
|
||||||
|
if (index !== -1) {
|
||||||
|
parent.children.splice(index, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: 'flex' }}>
|
<Box sx={{ display: 'flex' }}>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<SideBar directoryData={directoryData} handleSelect={handleSelect} />
|
<SideBar directoryData={directoryData} handleSelect={handleSelect} />
|
||||||
<Main selectedFilePath={selectedFilePath} />
|
<Main
|
||||||
|
selectedFilePath={selectedFilePath}
|
||||||
|
removeFileFromTree={removeFileFromTree}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,12 @@ import Button from '@mui/material/Button'
|
|||||||
import Toolbar from '@mui/material/Toolbar'
|
import Toolbar from '@mui/material/Toolbar'
|
||||||
import CircularProgress from '@mui/material/CircularProgress'
|
import CircularProgress from '@mui/material/CircularProgress'
|
||||||
|
|
||||||
const Main = (props: any) => {
|
type Props = {
|
||||||
|
selectedFilePath: string
|
||||||
|
removeFileFromTree: (path: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const Main = (props: Props) => {
|
||||||
const baseUrl = window.location.origin
|
const baseUrl = window.location.origin
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
@@ -45,6 +50,7 @@ const Main = (props: any) => {
|
|||||||
.delete(`/SASjsApi/drive/file?_filePath=${filePath}`)
|
.delete(`/SASjsApi/drive/file?_filePath=${filePath}`)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
setFileContent('')
|
setFileContent('')
|
||||||
|
props.removeFileFromTree(filePath)
|
||||||
window.history.pushState('', '', `${baseUrl}/#/SASjsDrive`)
|
window.history.pushState('', '', `${baseUrl}/#/SASjsDrive`)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user