Skip to content

Commit

Permalink
feat(web): added delete option in Drive
Browse files Browse the repository at this point in the history
  • Loading branch information
saadjutt01 committed Mar 14, 2022
1 parent 67d200d commit 7a6e6c8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
28 changes: 27 additions & 1 deletion web/src/containers/Drive/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Main = (props: any) => {
if (props.selectedFilePath) {
setIsLoading(true)
axios
.get(`/SASjsApi/drive/file?filePath=${props.selectedFilePath}`)
.get(`/SASjsApi/drive/file?_filePath=${props.selectedFilePath}`)
.then((res: any) => {
setFileContent(res.data)
})
Expand All @@ -36,6 +36,25 @@ const Main = (props: any) => {
}
}, [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 = () => {
if (!editMode) {
setFileContentBeforeEdit(fileContent)
Expand Down Expand Up @@ -112,6 +131,13 @@ const Main = (props: any) => {
direction="row"
sx={{ justifyContent: 'center', marginTop: '20px' }}
>
<Button
variant="contained"
onClick={handleDeleteBtnClick}
disabled={isLoading || !props?.selectedFilePath}
>
Delete
</Button>
<Button
variant="contained"
onClick={handleEditSaveBtnClick}
Expand Down
18 changes: 10 additions & 8 deletions web/src/containers/Drive/sideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ const SideBar = (props: any) => {
}, [setFilePathOnMount])

const handleSelect = (node: TreeNode) => {
if (!node.children.length) {
window.history.pushState(
'',
'',
`${baseUrl}/#/SASjsDrive?filePath=${node.relativePath}`
)
setSelectedFilePath(node.relativePath)
}
if (node.children.length) return

if (!node.name.includes('.')) return

window.history.pushState(
'',
'',
`${baseUrl}/#/SASjsDrive?filePath=${node.relativePath}`
)
setSelectedFilePath(node.relativePath)
}

const renderTree = (nodes: TreeNode) => (
Expand Down

0 comments on commit 7a6e6c8

Please sign in to comment.