1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-07 22:50:05 +00:00

feat: implemented delete file/folder functionality

This commit is contained in:
2022-07-19 22:49:34 +05:00
parent 721165ff12
commit 177675bc89
4 changed files with 70 additions and 13 deletions

View File

@@ -107,6 +107,8 @@ const SASjsEditor = ({
setOpenModal(true)
})
.finally(() => setIsLoading(false))
} else {
setFileContent('')
}
}, [selectedFilePath])

View File

@@ -56,6 +56,12 @@ const Studio = () => {
) => {
if (node.relativePath === path) {
removeNodeFromParent(parentNode, path)
// reset selected file path and file path query param
if (
node.relativePath === selectedFilePath ||
selectedFilePath.startsWith(node.relativePath)
)
setSearchParams({})
return true
}
if (Array.isArray(node.children)) {
@@ -81,6 +87,7 @@ const Studio = () => {
selectedFilePath={selectedFilePath}
directoryData={directoryData}
handleSelect={handleSelect}
removeFileFromTree={removeFileFromTree}
/>
<SASjsEditor
selectedFilePath={selectedFilePath}

View File

@@ -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}
/>
)}