1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Don't render fileDragAndDropDialog if it's not needed

This commit is contained in:
Brett Sun 2015-12-08 18:16:11 +01:00
parent a0db6d3037
commit 04d7e6951a
2 changed files with 109 additions and 107 deletions

View File

@ -1,9 +1,11 @@
'use strict'; 'use strict';
import React from 'react'; import React from 'react';
import classNames from 'classnames';
import ProgressBar from 'react-bootstrap/lib/ProgressBar'; import ProgressBar from 'react-bootstrap/lib/ProgressBar';
import FileDragAndDropDialog from './file_drag_and_drop_dialog'; import FileDragAndDropDialog from './file_drag_and_drop_dialog';
import FileDragAndDropErrorDialog from './file_drag_and_drop_error_dialog';
import FileDragAndDropPreviewIterator from './file_drag_and_drop_preview_iterator'; import FileDragAndDropPreviewIterator from './file_drag_and_drop_preview_iterator';
import { FileStatus } from '../react_s3_fine_uploader_utils'; import { FileStatus } from '../react_s3_fine_uploader_utils';
@ -22,11 +24,11 @@ let FileDragAndDrop = React.createClass({
onDrop: React.PropTypes.func.isRequired, onDrop: React.PropTypes.func.isRequired,
onDragOver: React.PropTypes.func, onDragOver: React.PropTypes.func,
onInactive: React.PropTypes.func, onInactive: React.PropTypes.func,
filesToUpload: React.PropTypes.array,
handleDeleteFile: React.PropTypes.func, handleDeleteFile: React.PropTypes.func,
handleCancelFile: React.PropTypes.func, handleCancelFile: React.PropTypes.func,
handlePauseFile: React.PropTypes.func, handlePauseFile: React.PropTypes.func,
handleResumeFile: React.PropTypes.func, handleResumeFile: React.PropTypes.func,
handleRetryFiles: React.PropTypes.func,
enableLocalHashing: React.PropTypes.bool, enableLocalHashing: React.PropTypes.bool,
uploadMethod: React.PropTypes.string, uploadMethod: React.PropTypes.string,
@ -142,23 +144,46 @@ let FileDragAndDrop = React.createClass({
this.refs.fileSelector.getDOMNode().dispatchEvent(evt); this.refs.fileSelector.getDOMNode().dispatchEvent(evt);
}, },
getPreviewIterator() {
const { areAssetsDownloadable, areAssetsEditable, filesToUpload } = this.props;
return (
<FileDragAndDropPreviewIterator
files={filesToUpload}
handleDeleteFile={this.handleDeleteFile}
handleCancelFile={this.handleCancelFile}
handlePauseFile={this.handlePauseFile}
handleResumeFile={this.handleResumeFile}
areAssetsDownloadable={areAssetsDownloadable}
areAssetsEditable={areAssetsEditable}/>
);
},
getUploadDialog() {
const { enableLocalHashing, fileClassToUpload, multiple, uploadMethod } = this.props;
return (
<FileDragAndDropDialog
multipleFiles={multiple}
onClick={this.handleOnClick}
enableLocalHashing={enableLocalHashing}
uploadMethod={uploadMethod}
fileClassToUpload={fileClassToUpload} />
);
},
render: function () { render: function () {
const { const {
filesToUpload, filesToUpload,
dropzoneInactive, dropzoneInactive,
className,
hashingProgress, hashingProgress,
handleCancelHashing, handleCancelHashing,
multiple, multiple,
enableLocalHashing,
uploadMethod,
fileClassToUpload, fileClassToUpload,
areAssetsDownloadable,
areAssetsEditable,
allowedExtensions } = this.props; allowedExtensions } = this.props;
// has files only is true if there are files that do not have the status deleted, canceled, or failed // has files only is true if there are files that do not have the status deleted, canceled, or failed
let hasFiles = filesToUpload const hasFiles = filesToUpload
.filter((file) => { .filter((file) => {
return file.status !== FileStatus.DELETED && return file.status !== FileStatus.DELETED &&
file.status !== FileStatus.CANCELED && file.status !== FileStatus.CANCELED &&
@ -167,14 +192,12 @@ let FileDragAndDrop = React.createClass({
}) })
.length > 0; .length > 0;
let updatedClassName = hasFiles ? 'has-files ' : ''; const failedFiles = filesToUpload.filter((file) => file.status === FileStatus.UPLOAD_FAILED);
updatedClassName += dropzoneInactive ? 'inactive-dropzone' : 'active-dropzone'; let hasError = showError && errorClass && failedFiles.length > 0;
updatedClassName += ' file-drag-and-drop';
// if !== -2: triggers a FileDragAndDrop-global spinner // if !== -2: triggers a FileDragAndDrop-global spinner
if(hashingProgress !== -2) { if(hashingProgress !== -2) {
return ( return (
<div className={className}>
<div className="file-drag-and-drop-hashing-dialog"> <div className="file-drag-and-drop-hashing-dialog">
<p>{getLangText('Computing hash(es)... This may take a few minutes.')}</p> <p>{getLangText('Computing hash(es)... This may take a few minutes.')}</p>
<p> <p>
@ -185,30 +208,15 @@ let FileDragAndDrop = React.createClass({
label="%(percent)s%" label="%(percent)s%"
className="ascribe-progress-bar"/> className="ascribe-progress-bar"/>
</div> </div>
</div>
); );
} else { } else {
return ( return (
<div <div
className={updatedClassName} className={classNames('file-drag-and-drop', dropzoneInactive ? 'inactive-dropzone' : 'active-dropzone', { 'has-files': hasFiles })}
onDrag={this.handleDrop} onDrag={this.handleDrop}
onDragOver={this.handleDragOver} onDragOver={this.handleDragOver}
onDrop={this.handleDrop}> onDrop={this.handleDrop}>
<FileDragAndDropDialog {!hasFiles && !hasError ? this.getUploadDialog() : null}
multipleFiles={multiple}
hasFiles={hasFiles}
onClick={this.handleOnClick}
enableLocalHashing={enableLocalHashing}
uploadMethod={uploadMethod}
fileClassToUpload={fileClassToUpload} />
<FileDragAndDropPreviewIterator
files={filesToUpload}
handleDeleteFile={this.handleDeleteFile}
handleCancelFile={this.handleCancelFile}
handlePauseFile={this.handlePauseFile}
handleResumeFile={this.handleResumeFile}
areAssetsDownloadable={areAssetsDownloadable}
areAssetsEditable={areAssetsEditable}/>
{/* {/*
Opera doesn't trigger simulated click events Opera doesn't trigger simulated click events
if the targeted input has `display:none` set. if the targeted input has `display:none` set.

View File

@ -9,7 +9,6 @@ import { getCurrentQueryParams } from '../../../utils/url_utils';
let FileDragAndDropDialog = React.createClass({ let FileDragAndDropDialog = React.createClass({
propTypes: { propTypes: {
hasFiles: React.PropTypes.bool,
multipleFiles: React.PropTypes.bool, multipleFiles: React.PropTypes.bool,
enableLocalHashing: React.PropTypes.bool, enableLocalHashing: React.PropTypes.bool,
uploadMethod: React.PropTypes.string, uploadMethod: React.PropTypes.string,
@ -36,16 +35,12 @@ let FileDragAndDropDialog = React.createClass({
render() { render() {
const { const {
hasFiles,
multipleFiles, multipleFiles,
enableLocalHashing, enableLocalHashing,
uploadMethod, uploadMethod,
fileClassToUpload, fileClassToUpload,
onClick } = this.props; onClick } = this.props;
if (hasFiles) {
return null;
} else {
if (enableLocalHashing && !uploadMethod) { if (enableLocalHashing && !uploadMethod) {
const currentQueryParams = getCurrentQueryParams(); const currentQueryParams = getCurrentQueryParams();
@ -112,7 +107,6 @@ let FileDragAndDropDialog = React.createClass({
} }
} }
} }
}
}); });
export default FileDragAndDropDialog; export default FileDragAndDropDialog;