metamaps--metamaps/frontend/src/components/TopicCard/index.js

65 lines
2 KiB
JavaScript
Raw Normal View History

2017-01-13 00:45:21 -05:00
import React, { PropTypes, Component } from 'react'
import Title from './Title'
import Links from './Links'
2017-01-25 15:49:11 -05:00
import Desc from './Desc'
import Attachments from './Attachments'
2017-01-25 15:49:11 -05:00
2017-01-13 00:45:21 -05:00
class ReactTopicCard extends Component {
render = () => {
const { topic, ActiveMapper } = this.props
2017-01-28 16:39:17 -05:00
const authorizedToEdit = topic.authorizeToEdit(ActiveMapper)
2017-01-25 17:03:30 -05:00
const hasAttachment = topic.get('link') && topic.get('link') !== ''
const topicId = topic.isNew() ? topic.cid : topic.id // TODO should we be using cid here???
2017-01-24 17:25:28 -05:00
2017-01-13 00:45:21 -05:00
let classname = 'permission'
2017-01-24 17:25:28 -05:00
if (authorizedToEdit) {
classname += ' canEdit'
} else {
classname += ' cannotEdit'
}
2017-01-13 00:45:21 -05:00
if (topic.authorizePermissionChange(ActiveMapper)) classname += ' yourTopic'
return (
<div className={classname}>
<div className={`CardOnGraph ${hasAttachment ? 'hasAttachment' : ''}`} id={`topic_${topicId}`}>
<Title name={topic.get('name')}
2017-01-28 16:39:17 -05:00
authorizedToEdit={authorizedToEdit}
onChange={this.props.updateTopic}
/>
2017-01-25 17:03:30 -05:00
<Links topic={topic}
ActiveMapper={this.props.ActiveMapper}
updateTopic={this.props.updateTopic}
2017-01-28 17:27:01 -05:00
metacodeSets={this.props.metacodeSets}
2017-01-25 17:03:30 -05:00
/>
2017-01-25 15:49:11 -05:00
<Desc desc={topic.get('desc')}
2017-01-28 16:39:17 -05:00
authorizedToEdit={authorizedToEdit}
2017-01-25 15:49:11 -05:00
onChange={this.props.updateTopic}
/>
<Attachments topic={this.props.topic}
ActiveMapper={this.props.ActiveMapper}
updateTopic={this.props.updateTopic}
/>
2017-01-13 00:45:21 -05:00
<div className="clearfloat"></div>
</div>
</div>
)
}
}
2017-01-13 00:45:21 -05:00
ReactTopicCard.propTypes = {
topic: PropTypes.object,
ActiveMapper: PropTypes.object,
2017-01-28 17:27:01 -05:00
updateTopic: PropTypes.func,
metacodeSets: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string,
metacodes: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number,
icon_path: PropTypes.string, // url
name: PropTypes.string
}))
}))
2017-01-13 00:45:21 -05:00
}
export default ReactTopicCard