mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
refactor Dropzone component and added tests (#5578)
This commit is contained in:
parent
54e5ee6535
commit
6a15b89b9a
@ -23,13 +23,16 @@ import BucketPolicyModal from "../buckets/BucketPolicyModal"
|
|||||||
import MakeBucketModal from "../buckets/MakeBucketModal"
|
import MakeBucketModal from "../buckets/MakeBucketModal"
|
||||||
import UploadModal from "../uploads/UploadModal"
|
import UploadModal from "../uploads/UploadModal"
|
||||||
import ObjectsBulkActions from "../objects/ObjectsBulkActions"
|
import ObjectsBulkActions from "../objects/ObjectsBulkActions"
|
||||||
|
import Dropzone from "../uploads/Dropzone"
|
||||||
|
|
||||||
export const MainContent = () => (
|
export const MainContent = () => (
|
||||||
<div className="fe-body">
|
<div className="fe-body">
|
||||||
<ObjectsBulkActions />
|
<ObjectsBulkActions />
|
||||||
<MobileHeader />
|
<MobileHeader />
|
||||||
<Header />
|
<Dropzone>
|
||||||
<ObjectsSection />
|
<Header />
|
||||||
|
<ObjectsSection />
|
||||||
|
</Dropzone>
|
||||||
<MainActions />
|
<MainActions />
|
||||||
<BucketPolicyModal />
|
<BucketPolicyModal />
|
||||||
<MakeBucketModal />
|
<MakeBucketModal />
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Minio Cloud Storage (C) 2016 Minio, Inc.
|
* Minio Cloud Storage (C) 2016, 2018 Minio, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -14,23 +14,21 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react'
|
import React from "react"
|
||||||
import ReactDropzone from 'react-dropzone'
|
import { connect } from "react-redux"
|
||||||
import * as actions from '../actions'
|
import ReactDropzone from "react-dropzone"
|
||||||
|
import * as actions from "./actions"
|
||||||
|
|
||||||
// Dropzone is a drag-and-drop element for uploading files. It will create a
|
// Dropzone is a drag-and-drop element for uploading files. It will create a
|
||||||
// landing zone of sorts that automatically receives the files.
|
// landing zone of sorts that automatically receives the files.
|
||||||
export default class Dropzone extends React.Component {
|
export class Dropzone extends React.Component {
|
||||||
|
|
||||||
onDrop(files) {
|
onDrop(files) {
|
||||||
|
const { uploadFile } = this.props
|
||||||
// FIXME: Currently you can upload multiple files, but only one abort
|
// FIXME: Currently you can upload multiple files, but only one abort
|
||||||
// modal will be shown, and progress updates will only occur for one
|
// modal will be shown, and progress updates will only occur for one
|
||||||
// file at a time. See #171.
|
// file at a time. See #171.
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
let req = new XMLHttpRequest()
|
uploadFile(file)
|
||||||
|
|
||||||
// Dispatch the upload.
|
|
||||||
web.dispatch(actions.uploadFile(file, req))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,29 +36,39 @@ export default class Dropzone extends React.Component {
|
|||||||
// Overwrite the default styling from react-dropzone; otherwise it
|
// Overwrite the default styling from react-dropzone; otherwise it
|
||||||
// won't handle child elements correctly.
|
// won't handle child elements correctly.
|
||||||
const style = {
|
const style = {
|
||||||
height: '100%',
|
height: "100%",
|
||||||
borderWidth: '0',
|
borderWidth: "0",
|
||||||
borderStyle: 'dashed',
|
borderStyle: "dashed",
|
||||||
borderColor: '#fff'
|
borderColor: "#fff"
|
||||||
}
|
}
|
||||||
const activeStyle = {
|
const activeStyle = {
|
||||||
borderWidth: '2px',
|
borderWidth: "2px",
|
||||||
borderColor: '#777'
|
borderColor: "#777"
|
||||||
}
|
}
|
||||||
const rejectStyle = {
|
const rejectStyle = {
|
||||||
backgroundColor: '#ffdddd'
|
backgroundColor: "#ffdddd"
|
||||||
}
|
}
|
||||||
|
|
||||||
// disableClick means that it won't trigger a file upload box when
|
// disableClick means that it won't trigger a file upload box when
|
||||||
// the user clicks on a file.
|
// the user clicks on a file.
|
||||||
return (
|
return (
|
||||||
<ReactDropzone style={ style }
|
<ReactDropzone
|
||||||
activeStyle={ activeStyle }
|
style={style}
|
||||||
rejectStyle={ rejectStyle }
|
activeStyle={activeStyle}
|
||||||
disableClick={ true }
|
rejectStyle={rejectStyle}
|
||||||
onDrop={ this.onDrop }>
|
disableClick={true}
|
||||||
{ this.props.children }
|
onDrop={this.onDrop.bind(this)}
|
||||||
|
>
|
||||||
|
{this.props.children}
|
||||||
</ReactDropzone>
|
</ReactDropzone>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = dispatch => {
|
||||||
|
return {
|
||||||
|
uploadFile: file => dispatch(actions.uploadFile(file))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(undefined, mapDispatchToProps)(Dropzone)
|
34
browser/app/js/uploads/__tests__/Dropzone.test.js
Normal file
34
browser/app/js/uploads/__tests__/Dropzone.test.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Minio Cloud Storage (C) 2018 Minio, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from "react"
|
||||||
|
import { shallow } from "enzyme"
|
||||||
|
import { Dropzone } from "../Dropzone"
|
||||||
|
|
||||||
|
describe("Dropzone", () => {
|
||||||
|
it("should render without crashing", () => {
|
||||||
|
shallow(<Dropzone />)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should call uploadFile with files", () => {
|
||||||
|
const uploadFile = jest.fn()
|
||||||
|
const wrapper = shallow(<Dropzone uploadFile={uploadFile} />)
|
||||||
|
const file1 = new Blob(["file content1"], { type: "text/plain" })
|
||||||
|
const file2 = new Blob(["file content2"], { type: "text/plain" })
|
||||||
|
wrapper.first().prop("onDrop")([file1, file2])
|
||||||
|
expect(uploadFile.mock.calls).toEqual([[file1], [file2]])
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user