Attachment.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. const fileType = <span className="attachment-filetype label label-default">{attachment.fileFormat}</span>;
  28. return (
  29. <li>
  30. <User user={attachment.creator} />
  31. <Icon name={formatIcon} />
  32. <a href={attachment.url}> {attachment.originalName}</a>
  33. {fileType}
  34. {fileInUse}
  35. <a className="text-danger attachment-delete" onClick={this._onAttachmentDeleteClicked}><Icon name="trash-o" /></a>
  36. </li>
  37. );
  38. }
  39. }
  40. Attachment.propTypes = {
  41. attachment: PropTypes.object.isRequired,
  42. inUse: PropTypes.bool.isRequired,
  43. onAttachmentDeleteClicked: PropTypes.func.isRequired,
  44. };
  45. Attachment.defaultProps = {
  46. };