mirror of
https://github.com/sasjs/server.git
synced 2025-12-27 10:40:05 +00:00
feat: implemented delete file/folder functionality
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { useMemo } from 'react'
|
||||
|
||||
import axios from 'axios'
|
||||
import { Box, Drawer, Toolbar } from '@mui/material'
|
||||
|
||||
import TreeView from '../../components/tree'
|
||||
@@ -11,9 +11,15 @@ type Props = {
|
||||
selectedFilePath: string
|
||||
directoryData: TreeNode | null
|
||||
handleSelect: (filePath: string) => void
|
||||
removeFileFromTree: (filePath: string) => void
|
||||
}
|
||||
|
||||
const SideBar = ({ selectedFilePath, directoryData, handleSelect }: Props) => {
|
||||
const SideBar = ({
|
||||
selectedFilePath,
|
||||
directoryData,
|
||||
handleSelect,
|
||||
removeFileFromTree
|
||||
}: Props) => {
|
||||
const defaultExpanded = useMemo(() => {
|
||||
const splittedPath = selectedFilePath.split('/')
|
||||
const arr = ['']
|
||||
@@ -27,6 +33,20 @@ const SideBar = ({ selectedFilePath, directoryData, handleSelect }: Props) => {
|
||||
return arr
|
||||
}, [selectedFilePath])
|
||||
|
||||
const deleteNode = (path: string, isFolder: boolean) => {
|
||||
const axiosPromise = axios.delete(
|
||||
`/SASjsApi/drive/${
|
||||
isFolder ? `folder?_folderPath=${path}` : `file?_filePath=${path}`
|
||||
}`
|
||||
)
|
||||
|
||||
axiosPromise
|
||||
.then(() => removeFileFromTree(path))
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
variant="permanent"
|
||||
@@ -43,6 +63,7 @@ const SideBar = ({ selectedFilePath, directoryData, handleSelect }: Props) => {
|
||||
node={directoryData}
|
||||
selectedFilePath={selectedFilePath}
|
||||
handleSelect={handleSelect}
|
||||
deleteNode={deleteNode}
|
||||
defaultExpanded={defaultExpanded}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user