Refactor download object and bulk action components (#5546)

This commit is contained in:
Kanagaraj M
2018-02-21 07:30:43 +05:30
committed by Harshavardhana
parent da4558a8f7
commit 6a42727e00
14 changed files with 604 additions and 24 deletions

View File

@@ -15,22 +15,41 @@
*/
import React from "react"
import { connect } from "react-redux"
import humanize from "humanize"
import Moment from "moment"
import ObjectItem from "./ObjectItem"
import ObjectActions from "./ObjectActions"
import * as actionsObjects from "./actions"
import { getCheckedList } from "./selectors"
export const ObjectContainer = ({ object }) => {
const actionButtons = <ObjectActions object={object} />
const props = {
export const ObjectContainer = ({
object,
checkedObjectsCount,
downloadObject
}) => {
let props = {
name: object.name,
contentType: object.contentType,
size: humanize.filesize(object.size),
lastModified: Moment(object.lastModified).format("lll"),
actionButtons: actionButtons
lastModified: Moment(object.lastModified).format("lll")
}
return <ObjectItem {...props} />
if (checkedObjectsCount == 0) {
props.actionButtons = <ObjectActions object={object} />
}
return <ObjectItem {...props} onClick={() => downloadObject(object.name)} />
}
export default ObjectContainer
const mapStateToProps = state => {
return {
checkedObjectsCount: getCheckedList(state).length
}
}
const mapDispatchToProps = dispatch => {
return {
downloadObject: object => dispatch(actionsObjects.downloadObject(object))
}
}
export default connect(mapStateToProps, mapDispatchToProps)(ObjectContainer)