2017-01-23 21:07:22 -05:00
|
|
|
/*
|
2021-04-19 13:30:42 -04:00
|
|
|
* Copyright (c) 2015-2021 MinIO, Inc.
|
2017-01-23 21:07:22 -05:00
|
|
|
*
|
2021-04-19 13:30:42 -04:00
|
|
|
* This file is part of MinIO Object Storage stack
|
2017-01-23 21:07:22 -05:00
|
|
|
*
|
2021-04-19 13:30:42 -04:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2017-01-23 21:07:22 -05:00
|
|
|
*
|
2021-04-19 13:30:42 -04:00
|
|
|
* This program is distributed in the hope that it will be useful
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-01-23 21:07:22 -05:00
|
|
|
*/
|
|
|
|
|
2018-02-28 15:22:18 -05:00
|
|
|
import React from "react"
|
|
|
|
import { connect } from "react-redux"
|
|
|
|
import ReactDropzone from "react-dropzone"
|
|
|
|
import * as actions from "./actions"
|
2017-01-23 21:07:22 -05:00
|
|
|
|
|
|
|
// Dropzone is a drag-and-drop element for uploading files. It will create a
|
|
|
|
// landing zone of sorts that automatically receives the files.
|
2018-02-28 15:22:18 -05:00
|
|
|
export class Dropzone extends React.Component {
|
2017-01-23 21:07:22 -05:00
|
|
|
onDrop(files) {
|
2018-02-28 15:22:18 -05:00
|
|
|
const { uploadFile } = this.props
|
2017-01-23 21:07:22 -05:00
|
|
|
// FIXME: Currently you can upload multiple files, but only one abort
|
|
|
|
// modal will be shown, and progress updates will only occur for one
|
|
|
|
// file at a time. See #171.
|
|
|
|
files.forEach(file => {
|
2018-02-28 15:22:18 -05:00
|
|
|
uploadFile(file)
|
2017-01-23 21:07:22 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-03-26 15:49:12 -04:00
|
|
|
// Overwrite the default styling from react-dropzone; otherwise it
|
|
|
|
// won't handle child elements correctly.
|
|
|
|
const style = {
|
2020-09-30 01:27:41 -04:00
|
|
|
flex: "1",
|
2018-03-26 15:49:12 -04:00
|
|
|
borderWidth: "0",
|
|
|
|
borderStyle: "dashed",
|
|
|
|
borderColor: "#fff"
|
|
|
|
}
|
|
|
|
const activeStyle = {
|
|
|
|
borderWidth: "2px",
|
|
|
|
borderColor: "#777"
|
|
|
|
}
|
|
|
|
const rejectStyle = {
|
|
|
|
backgroundColor: "#ffdddd"
|
|
|
|
}
|
2020-06-04 20:24:18 -04:00
|
|
|
const getStyle = (isDragActive, isDragAccept, isDragReject) => ({
|
|
|
|
...style,
|
|
|
|
...(isDragActive ? activeStyle : {}),
|
|
|
|
...(isDragReject ? rejectStyle : {})
|
|
|
|
})
|
2018-03-26 15:49:12 -04:00
|
|
|
|
2017-01-23 21:07:22 -05:00
|
|
|
// disableClick means that it won't trigger a file upload box when
|
|
|
|
// the user clicks on a file.
|
|
|
|
return (
|
2018-02-28 15:22:18 -05:00
|
|
|
<ReactDropzone
|
|
|
|
onDrop={this.onDrop.bind(this)}
|
|
|
|
>
|
2020-06-04 20:24:18 -04:00
|
|
|
{({getRootProps, getInputProps, isDragActive, isDragAccept, isDragReject}) => (
|
|
|
|
<div
|
|
|
|
{...getRootProps({
|
|
|
|
onClick: event => event.stopPropagation()
|
|
|
|
})}
|
|
|
|
style={getStyle(isDragActive, isDragAccept, isDragReject)}
|
|
|
|
>
|
|
|
|
<input {...getInputProps()} />
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
)}
|
2017-01-23 21:07:22 -05:00
|
|
|
</ReactDropzone>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-02-28 15:22:18 -05:00
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
2018-03-22 15:25:56 -04:00
|
|
|
uploadFile: file => dispatch(actions.uploadFile(file))
|
2018-02-28 15:22:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(undefined, mapDispatchToProps)(Dropzone)
|