1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-18 19:30:06 +00:00

feat(web): added delete option in Drive

This commit is contained in:
Saad Jutt
2022-03-14 06:26:12 +05:00
parent 67d200d817
commit 7a6e6c8bec
2 changed files with 37 additions and 9 deletions

View File

@@ -23,7 +23,7 @@ const Main = (props: any) => {
if (props.selectedFilePath) { if (props.selectedFilePath) {
setIsLoading(true) setIsLoading(true)
axios axios
.get(`/SASjsApi/drive/file?filePath=${props.selectedFilePath}`) .get(`/SASjsApi/drive/file?_filePath=${props.selectedFilePath}`)
.then((res: any) => { .then((res: any) => {
setFileContent(res.data) setFileContent(res.data)
}) })
@@ -36,6 +36,25 @@ const Main = (props: any) => {
} }
}, [props.selectedFilePath]) }, [props.selectedFilePath])
const handleDeleteBtnClick = () => {
setIsLoading(true)
const filePath = props.selectedFilePath
axios
.delete(`/SASjsApi/drive/file?_filePath=${filePath}`)
.then((res) => {
setFileContent('')
window.history.pushState('', '', `${baseUrl}/#/SASjsDrive`)
})
.catch((err) => {
console.log(err)
})
.finally(() => {
setIsLoading(false)
})
}
const handleEditSaveBtnClick = () => { const handleEditSaveBtnClick = () => {
if (!editMode) { if (!editMode) {
setFileContentBeforeEdit(fileContent) setFileContentBeforeEdit(fileContent)
@@ -112,6 +131,13 @@ const Main = (props: any) => {
direction="row" direction="row"
sx={{ justifyContent: 'center', marginTop: '20px' }} sx={{ justifyContent: 'center', marginTop: '20px' }}
> >
<Button
variant="contained"
onClick={handleDeleteBtnClick}
disabled={isLoading || !props?.selectedFilePath}
>
Delete
</Button>
<Button <Button
variant="contained" variant="contained"
onClick={handleEditSaveBtnClick} onClick={handleEditSaveBtnClick}

View File

@@ -64,14 +64,16 @@ const SideBar = (props: any) => {
}, [setFilePathOnMount]) }, [setFilePathOnMount])
const handleSelect = (node: TreeNode) => { const handleSelect = (node: TreeNode) => {
if (!node.children.length) { if (node.children.length) return
window.history.pushState(
'', if (!node.name.includes('.')) return
'',
`${baseUrl}/#/SASjsDrive?filePath=${node.relativePath}` window.history.pushState(
) '',
setSelectedFilePath(node.relativePath) '',
} `${baseUrl}/#/SASjsDrive?filePath=${node.relativePath}`
)
setSelectedFilePath(node.relativePath)
} }
const renderTree = (nodes: TreeNode) => ( const renderTree = (nodes: TreeNode) => (