1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import * as classnames from 'classnames';
10 Table, TableBody, TableCell, TableHead, TableRow,
13 } from '@material-ui/core';
14 import { withStyles } from '@material-ui/core';
15 import Dropzone from 'react-dropzone';
16 import { CloudUploadIcon } from "../icon/icon";
17 import { formatFileSize, formatProgress, formatUploadSpeed } from "~/common/formatters";
18 import { UploadFile } from '~/store/file-uploader/file-uploader-actions';
20 type CssRules = "root" | "dropzone" | "dropzoneWrapper" | "container" | "uploadIcon";
22 import './file-upload.css';
23 import { DOMElement, RefObject } from "react";
25 const styles: StyleRulesCallback<CssRules> = theme => ({
37 border: "1px solid rgba(0, 0, 0, 0.42)"
43 verticalAlign: "middle"
47 interface FileUploadPropsData {
50 onDrop: (files: File[]) => void;
53 interface FileUploadState {
57 export type FileUploadProps = FileUploadPropsData & WithStyles<CssRules>;
59 export const FileUpload = withStyles(styles)(
60 class extends React.Component<FileUploadProps, FileUploadState> {
61 constructor(props: FileUploadProps) {
68 const { classes, onDrop, disabled, files } = this.props;
69 return <div className={"file-upload-dropzone " + classes.dropzoneWrapper}>
70 <div className={classnames("dropzone-border-left", { "dropzone-border-left-active": this.state.focused })}/>
71 <div className={classnames("dropzone-border-right", { "dropzone-border-right-active": this.state.focused })}/>
72 <div className={classnames("dropzone-border-top", { "dropzone-border-top-active": this.state.focused })}/>
73 <div className={classnames("dropzone-border-bottom", { "dropzone-border-bottom-active": this.state.focused })}/>
74 <Dropzone className={classes.dropzone}
75 onDrop={files => onDrop(files)}
77 const el = document.getElementsByClassName("file-upload-dropzone")[0];
78 const inputs = el.getElementsByTagName("input");
79 if (inputs.length > 0) {
96 {files.length === 0 &&
97 <Grid container justify="center" alignItems="center" className={classes.container}>
98 <Grid item component={"span"}>
99 <Typography variant={"subheading"}>
100 <CloudUploadIcon className={classes.uploadIcon} /> Drag and drop data or click to browse
105 <Table style={{ width: "100%" }}>
108 <TableCell>File name</TableCell>
109 <TableCell>File size</TableCell>
110 <TableCell>Upload speed</TableCell>
111 <TableCell>Upload progress</TableCell>
116 <TableRow key={f.id}>
117 <TableCell>{f.file.name}</TableCell>
118 <TableCell>{formatFileSize(f.file.size)}</TableCell>
119 <TableCell>{formatUploadSpeed(f.prevLoaded, f.loaded, f.prevTime, f.currentTime)}</TableCell>
120 <TableCell>{formatProgress(f.loaded, f.total)}</TableCell>