Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(download) #337

Merged
merged 8 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/CoreMetadata/CoreMetadataHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@ class CoreMetadataHeader extends Component {

render() {
if (this.props.metadata) {
// display the download button if the user can download this file
// display the download button if the user can download this file
const { user, projectAvail } = this.props;
const projectId = this.props.metadata.project_id;
const canDownload = canUserDownload(user, projectAvail, projectId);
let downloadButton = null;
if (canDownload) {
const downloadLink = `/user/data/download/${this.props.metadata.object_id}?expires_in=10&redirect`;

downloadButton = (
<button
onClick={this.props.onDownloadFile}
className='button-primary-orange'
>
{DOWNLOAD_BTN_CAPTION}
</button>);
<a href={downloadLink}>
<button className='button-primary-orange'>
{DOWNLOAD_BTN_CAPTION}
</button>
</a>);
}

const properties = `${this.props.metadata.data_format} | ${fileSizeTransform(this.props.metadata.file_size)} | ${this.props.metadata.object_id} | ${this.dateTransform(this.props.metadata.updated_datetime)}`;
Expand Down Expand Up @@ -89,7 +90,6 @@ class CoreMetadataHeader extends Component {
CoreMetadataHeader.propTypes = {
metadata: PropTypes.object,
error: PropTypes.string,
onDownloadFile: PropTypes.func.isRequired,
user: PropTypes.object.isRequired,
projectAvail: PropTypes.object.isRequired,
};
Expand Down
30 changes: 1 addition & 29 deletions src/CoreMetadata/reduxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import CoreMetadataHeader from './CoreMetadataHeader';
import FileTypePicture from '../components/FileTypePicture';
import CoreMetadataTable from './CoreMetadataTable';
import { coreMetadataPath, userapiPath } from '../localconf';
import { coreMetadataPath } from '../localconf';
import { fetchWithCreds } from '../actions';

export const fetchCoreMetadata = objectId =>
Expand All @@ -28,33 +28,6 @@ export const fetchCoreMetadata = objectId =>
})
.then(msg => dispatch(msg));

const downloadFile = id => (dispatch) => {
const path = `${userapiPath}data/download/${id}?expires_in=10&redirect`;
const method = 'GET';
return fetchWithCreds({
path,
method,
})
.then(({ status, data }) => {
switch (status) {
case 200:
return {
type: 'DOWNLOAD_FILE',
file: data,
};
default:
return {
type: 'DOWNLOAD_FILE_ERROR',
error: data.error,
};
}
})
.then((msg) => {
dispatch(msg);
window.location.href = path; // redirect to download
});
};

export const ReduxCoreMetadataHeader = (() => {
const mapStateToProps = state => ({
metadata: state.coreMetadata.metadata,
Expand All @@ -64,7 +37,6 @@ export const ReduxCoreMetadataHeader = (() => {
});

const mapDispatchToProps = dispatch => ({
onDownloadFile: id => dispatch(downloadFile(id)),
});

return connect(mapStateToProps, mapDispatchToProps)(CoreMetadataHeader);
Expand Down
4 changes: 2 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ async function init() {
/>
<Route
exact
path='/files/:object_id'
path='/files/*'
component={
props => (<ProtectedContent
filter={() =>
store.dispatch(fetchCoreMetadata(props.match.params.object_id))
store.dispatch(fetchCoreMetadata(props.match.params[0]))
}
component={CoreMetadataPage}
{...props}
Expand Down