Folder.jsx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React from 'react'
  2. import { translate } from 'react-i18next'
  3. import PropTypes from 'prop-types'
  4. import classnames from 'classnames'
  5. import FileItem from './FileItem.jsx'
  6. // @TODO set Folder as a component, state open will come from parent container (which will come from redux) // update: or not ?
  7. class Folder extends React.Component {
  8. constructor (props) {
  9. super(props)
  10. this.state = {
  11. open: false
  12. }
  13. }
  14. handleClickToggleFolder = () => {
  15. !this.state.open && this.props.folderData.content.length === 0 && this.props.onClickFolder(this.props.folderData.id)
  16. this.setState({open: !this.state.open})
  17. }
  18. handleClickNewFile = e => {
  19. e.stopPropagation() // because we have a link inside a link (togler and newFile)
  20. console.log('new file') // @TODO
  21. }
  22. render () {
  23. const { app, folderData: { title, content }, onClickItem, onClickFolder, isLast, t } = this.props
  24. return (
  25. <div className={classnames('folder', {'active': this.state.open, 'item-last': isLast})}>
  26. <div className='folder__header' onClick={this.handleClickToggleFolder}>
  27. <div className='folder__header__triangleborder'>
  28. <div className='folder__header__triangleborder__triangle' />
  29. </div>
  30. <div className='folder__header__name'>
  31. <div className='folder__header__name__icon'>
  32. <i className={classnames('fa', {'fa-folder-open-o': this.state.open, 'fa-folder-o': !this.state.open})} />
  33. </div>
  34. <div className='folder__header__name__text'>
  35. { title }
  36. </div>
  37. <div className='folder__header__name__addbtn' onClick={this.handleClickNewFile}>
  38. <div className='folder__header__name__addbtn__text btn btn-primary'>
  39. {t('Folder.create')} ...
  40. </div>
  41. </div>
  42. </div>
  43. <div className='folder__header__contenttype'>
  44. <div className='folder__header__contenttype__text'>
  45. {t('Folder.content_type')} :
  46. </div>
  47. <div className='folder__header__contenttype__icon'>
  48. <i className='fa fa-list-ul' />
  49. <i className='fa fa-file-text-o' />
  50. <i className='fa fa-comments' />
  51. </div>
  52. </div>
  53. </div>
  54. <div className='folder__content'>
  55. { content.map((c, i) => c.type === 'folder'
  56. ? <Folder
  57. app={app}
  58. folderData={c}
  59. onClickItem={onClickItem}
  60. onClickFolder={onClickFolder}
  61. isLast={isLast}
  62. t={t}
  63. key={c.id}
  64. />
  65. : <FileItem
  66. icon={(app[c.type] || {icon: ''}).icon}
  67. name={c.title}
  68. type={c.type}
  69. status={c.status}
  70. onClickItem={() => onClickItem(c)}
  71. isLast={isLast && i === content.length - 1}
  72. key={c.id}
  73. />
  74. )}
  75. </div>
  76. </div>
  77. )
  78. }
  79. }
  80. export default translate()(Folder)
  81. Folder.propTypes = {
  82. folderData: PropTypes.shape({
  83. title: PropTypes.string.isRequired,
  84. content: PropTypes.array
  85. }),
  86. app: PropTypes.object,
  87. onClickItem: PropTypes.func.isRequired,
  88. onClickFolder: PropTypes.func.isRequired,
  89. isLast: PropTypes.bool.isRequired
  90. }