mirror of
https://github.com/minio/minio.git
synced 2025-11-23 19:17:43 -05:00
Refactor make bucket and upload components (#5521)
This commit is contained in:
committed by
Harshavardhana
parent
9bfa07ecf5
commit
44f8f7059c
@@ -19,6 +19,7 @@ import classNames from "classnames"
|
||||
import { connect } from "react-redux"
|
||||
import SideBar from "./SideBar"
|
||||
import MainContent from "./MainContent"
|
||||
import AlertContainer from "../alert/AlertContainer"
|
||||
|
||||
class Browser extends React.Component {
|
||||
render() {
|
||||
@@ -30,6 +31,7 @@ class Browser extends React.Component {
|
||||
>
|
||||
<SideBar />
|
||||
<MainContent />
|
||||
<AlertContainer />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
57
browser/app/js/browser/ConfirmModal.js
Normal file
57
browser/app/js/browser/ConfirmModal.js
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Minio Cloud Storage (C) 2016, 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 { Modal, ModalBody } from "react-bootstrap"
|
||||
|
||||
let ConfirmModal = ({
|
||||
baseClass,
|
||||
icon,
|
||||
text,
|
||||
sub,
|
||||
okText,
|
||||
cancelText,
|
||||
okHandler,
|
||||
cancelHandler,
|
||||
show
|
||||
}) => {
|
||||
return (
|
||||
<Modal
|
||||
bsSize="small"
|
||||
animation={false}
|
||||
show={show}
|
||||
className={"modal-confirm " + (baseClass || "")}
|
||||
>
|
||||
<ModalBody>
|
||||
<div className="mc-icon">
|
||||
<i className={icon} />
|
||||
</div>
|
||||
<div className="mc-text">{text}</div>
|
||||
<div className="mc-sub">{sub}</div>
|
||||
</ModalBody>
|
||||
<div className="modal-footer">
|
||||
<button className="btn btn-danger" onClick={okHandler}>
|
||||
{okText}
|
||||
</button>
|
||||
<button className="btn btn-link" onClick={cancelHandler}>
|
||||
{cancelText}
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
export default ConfirmModal
|
||||
83
browser/app/js/browser/MainActions.js
Normal file
83
browser/app/js/browser/MainActions.js
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 { connect } from "react-redux"
|
||||
import { Dropdown, OverlayTrigger, Tooltip } from "react-bootstrap"
|
||||
import * as actionsBuckets from "../buckets/actions"
|
||||
import * as uploadsActions from "../uploads/actions"
|
||||
|
||||
export const MainActions = ({ uploadFile, showMakeBucketModal }) => {
|
||||
const uploadTooltip = <Tooltip id="tt-upload-file">Upload file</Tooltip>
|
||||
const makeBucketTooltip = (
|
||||
<Tooltip id="tt-create-bucket">Create bucket</Tooltip>
|
||||
)
|
||||
const onFileUpload = e => {
|
||||
e.preventDefault()
|
||||
uploadFile(e.target.files[0])
|
||||
e.target.value = null
|
||||
}
|
||||
|
||||
return (
|
||||
<Dropdown dropup className="feb-actions" id="fe-action-toggle">
|
||||
<Dropdown.Toggle noCaret className="feba-toggle">
|
||||
<span>
|
||||
<i className="fa fa-plus" />
|
||||
</span>
|
||||
</Dropdown.Toggle>
|
||||
<Dropdown.Menu>
|
||||
<OverlayTrigger placement="left" overlay={uploadTooltip}>
|
||||
<a href="#" className="feba-btn feba-upload">
|
||||
<input
|
||||
type="file"
|
||||
onChange={onFileUpload}
|
||||
style={{ display: "none" }}
|
||||
id="file-input"
|
||||
/>
|
||||
<label htmlFor="file-input">
|
||||
{" "}
|
||||
<i className="fa fa-cloud-upload" />{" "}
|
||||
</label>
|
||||
</a>
|
||||
</OverlayTrigger>
|
||||
<OverlayTrigger placement="left" overlay={makeBucketTooltip}>
|
||||
<a
|
||||
href="#"
|
||||
id="show-make-bucket"
|
||||
className="feba-btn feba-bucket"
|
||||
onClick={e => {
|
||||
e.preventDefault()
|
||||
showMakeBucketModal()
|
||||
}}
|
||||
>
|
||||
<i className="fa fa-hdd-o" />
|
||||
</a>
|
||||
</OverlayTrigger>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
)
|
||||
}
|
||||
|
||||
const mapStateToProps = state => state
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
uploadFile: file => dispatch(uploadsActions.uploadFile(file)),
|
||||
showMakeBucketModal: () => dispatch(actionsBuckets.showMakeBucketModal())
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(MainActions)
|
||||
@@ -18,12 +18,18 @@ import React from "react"
|
||||
import MobileHeader from "./MobileHeader"
|
||||
import Header from "./Header"
|
||||
import ObjectsSection from "../objects/ObjectsSection"
|
||||
import MainActions from "./MainActions"
|
||||
import MakeBucketModal from "../buckets/MakeBucketModal"
|
||||
import UploadModal from "../uploads/UploadModal"
|
||||
|
||||
export const MainContent = () => (
|
||||
<div className="fe-body">
|
||||
<MobileHeader />
|
||||
<Header />
|
||||
<ObjectsSection />
|
||||
<MainActions />
|
||||
<MakeBucketModal />
|
||||
<UploadModal />
|
||||
</div>
|
||||
)
|
||||
|
||||
|
||||
47
browser/app/js/browser/__tests__/MainActions.test.js
Normal file
47
browser/app/js/browser/__tests__/MainActions.test.js
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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, mount } from "enzyme"
|
||||
import { MainActions } from "../MainActions"
|
||||
|
||||
describe("MainActions", () => {
|
||||
it("should render without crashing", () => {
|
||||
shallow(<MainActions />)
|
||||
})
|
||||
|
||||
it("should call showMakeBucketModal when create bucket icon is clicked", () => {
|
||||
const showMakeBucketModal = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<MainActions showMakeBucketModal={showMakeBucketModal} />
|
||||
)
|
||||
wrapper
|
||||
.find("#show-make-bucket")
|
||||
.simulate("click", { preventDefault: jest.fn() })
|
||||
expect(showMakeBucketModal).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("should call uploadFile when a file is selected for upload", () => {
|
||||
const uploadFile = jest.fn()
|
||||
const wrapper = shallow(<MainActions uploadFile={uploadFile} />)
|
||||
const file = new Blob(["file content"], { type: "text/plain" })
|
||||
wrapper.find("#file-input").simulate("change", {
|
||||
preventDefault: jest.fn(),
|
||||
target: { files: [file] }
|
||||
})
|
||||
expect(uploadFile).toHaveBeenCalledWith(file)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user