Attachment.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import Icon from '../Common/Icon';
  4. import User from '../User/User';
  5. export default class Attachment extends React.Component {
  6. constructor(props) {
  7. super(props);
  8. this._onAttachmentDeleteClicked = this._onAttachmentDeleteClicked.bind(this);
  9. }
  10. iconNameByFormat(format) {
  11. if (format.match(/image\/.+/i)) {
  12. return 'file-image-o';
  13. }
  14. return 'file-o';
  15. }
  16. _onAttachmentDeleteClicked(event) {
  17. this.props.onAttachmentDeleteClicked(this.props.attachment);
  18. }
  19. render() {
  20. const attachment = this.props.attachment;
  21. const attachmentId = attachment._id
  22. const formatIcon = this.iconNameByFormat(attachment.fileFormat);
  23. let fileInUse = '';
  24. if (this.props.inUse) {
  25. fileInUse = <span className="attachment-in-use label label-info">In Use</span>;
  26. }
  27. return (
  28. <li>
  29. <User user={attachment.creator} />
  30. <Icon name={formatIcon} />
  31. <a href={attachment.url}> {attachment.originalName}</a>
  32. {fileInUse}
  33. <a className="text-danger attachment-delete" onClick={this._onAttachmentDeleteClicked}><Icon name="trash-o" /></a>
  34. </li>
  35. );
  36. }
  37. }
  38. Attachment.propTypes = {
  39. attachment: PropTypes.object.isRequired,
  40. inUse: PropTypes.bool.isRequired,
  41. onAttachmentDeleteClicked: PropTypes.func.isRequired,
  42. };
  43. Attachment.defaultProps = {
  44. };