Skip to content
Snippets Groups Projects
Commit 475c80b1 authored by vkovtun's avatar vkovtun
Browse files

BIS-753: Refactoring download to be able to handle double click download.

parent 3bf092ae
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -157,6 +157,8 @@ class DataBrowser extends React.Component {
const { directory, path } = row.data
if (directory) {
await this.setPath(path)
} else {
}
}
......@@ -172,6 +174,24 @@ class DataBrowser extends React.Component {
})
}
async handleDownload() {
const { multiselectedFiles } = this.state
const file = multiselectedFiles.values().next().value;
try {
this.setState({ loading: true })
const dataArray = await this.controller.download(file)
const blob = new Blob(dataArray, { type: "application/octet-stream" })
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = file.name
link.click()
} finally {
this.setState({ loading: false })
}
}
async onError(error) {
await AppController.getInstance().errorChange(error)
}
......@@ -230,14 +250,14 @@ class DataBrowser extends React.Component {
return size.toFixed(1) + '\xa0' + unit
}
fetchPercentage() {
fetchSpaceStatus() {
this.controller.free().then(space => {
this.setState({ freeSpace: space.free, totalSpace: space.total })
})
}
componentDidMount() {
this.fetchPercentage()
this.fetchSpaceStatus()
}
render() {
......@@ -262,8 +282,8 @@ class DataBrowser extends React.Component {
viewType={viewType}
onViewTypeChange={this.handleViewTypeChange}
onShowInfoChange={this.handleShowInfoChange}
onDownload={this.handleDownload}
showInfo={showInfo}
selectedFile={selectedFile}
multiselectedFiles={multiselectedFiles}
datastoreServer={this.datastoreServer}
sessionToken={sessionToken}
......
......@@ -184,24 +184,6 @@ class LeftToolbar extends React.Component {
this.closeDeleteDialog()
}
async handleDownload() {
const { multiselectedFiles } = this.props
const file = multiselectedFiles.values().next().value;
try {
this.setState({ loading: true })
const dataArray = await this.controller.download(file)
const blob = new Blob(dataArray, { type: "application/octet-stream" })
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = file.name
link.click()
} finally {
this.setState({ loading: false })
}
}
renderNoSelectionContextToolbar() {
const { classes, buttonSize } = this.props
return ([
......@@ -235,7 +217,8 @@ class LeftToolbar extends React.Component {
datastoreServer,
sessionToken,
owner,
path
path,
onDownload
} = this.props
const {
width,
......@@ -261,7 +244,7 @@ class LeftToolbar extends React.Component {
variant='outlined'
disabled={multiselectedFiles.size !== 1 || multiselectedFiles.values().next().value.directory}
startIcon={<DownloadIcon />}
onClick={this.handleDownload}
onClick={onDownload}
>
{messages.get(messages.DOWNLOAD)}
</Button>,
......
......@@ -51,12 +51,12 @@ class Toolbar extends React.Component {
classes,
showInfo,
onShowInfoChange,
selectedFile,
multiselectedFiles,
datastoreServer,
sessionToken,
owner,
path
path,
onDownload
} = this.props
return (
<div className={classes.toolbar}>
......@@ -68,6 +68,7 @@ class Toolbar extends React.Component {
owner={owner}
path={path}
controller={this.controller}
onDownload={onDownload}
/>
<RightToolbar
buttonSize={buttonSize}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment