WorkspaceContent.jsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import Folder from '../component/Workspace/Folder.jsx'
  4. import FileItem from '../component/Workspace/FileItem.jsx'
  5. import FileItemHeader from '../component/Workspace/FileItemHeader.jsx'
  6. import PageWrapper from '../component/common/layout/PageWrapper.jsx'
  7. import PageTitle from '../component/common/layout/PageTitle.jsx'
  8. import PageContent from '../component/common/layout/PageContent.jsx'
  9. import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
  10. import { FETCH_CONFIG } from '../helper.js'
  11. import {
  12. getAppList,
  13. getWorkspaceContent
  14. } from '../action-creator.async.js'
  15. class WorkspaceContent extends React.Component {
  16. constructor (props) {
  17. super(props)
  18. this.state = {
  19. activeFileType: ''
  20. }
  21. }
  22. componentDidMount () {
  23. const { workspaceList, app, match, dispatch } = this.props
  24. if (match.params.idws !== undefined) dispatch(getWorkspaceContent(match.params.idws))
  25. else if (workspaceList.length > 0) dispatch(getWorkspaceContent(workspaceList[0].id)) // load first ws if none specified
  26. Object.keys(app).length === 0 && dispatch(getAppList())
  27. }
  28. componentDidUpdate (prevProps) {
  29. const { workspaceList, match, dispatch } = this.props
  30. if (prevProps.match.params.idws === match.params.idws) return
  31. if (match.params.idws !== undefined) dispatch(getWorkspaceContent(match.params.idws))
  32. // else load first ws if none specified
  33. else if (match.params.idws === undefined && workspaceList.length > 0) dispatch(getWorkspaceContent(workspaceList[0].id))
  34. }
  35. handleClickContentItem = content => {
  36. const { user, workspace } = this.props
  37. GLOBAL_renderApp({
  38. workspace: {
  39. id: workspace.id,
  40. title: workspace.title
  41. },
  42. appConfig: {
  43. ...this.props.app[content.type],
  44. apiUrl: FETCH_CONFIG.apiUrl
  45. },
  46. loggedUser: user.isLoggedIn ? user : {},
  47. content
  48. })
  49. }
  50. render () {
  51. const { workspace, app } = this.props
  52. return (
  53. <PageWrapper customeClass='workspace'>
  54. <PageTitle
  55. parentClass='workspace__header'
  56. customClass='justify-content-between'
  57. title={workspace.title}
  58. >
  59. <DropdownCreateButton parentClass='workspace__header__btnaddworkspace' />
  60. </PageTitle>
  61. <PageContent parentClass='workspace__content'>
  62. <div className='workspace__content__fileandfolder folder__content active'>
  63. <FileItemHeader />
  64. { workspace.content.map((c, i) => c.type === 'folder'
  65. ? <Folder app={app} folderData={c} key={c.id} isLast={i === workspace.content.length - 1} />
  66. : (
  67. <FileItem
  68. name={c.title}
  69. type={c.type}
  70. icon={(app[c.type] || {icon: ''}).icon}
  71. status={c.status}
  72. onClickItem={() => this.handleClickContentItem(c)}
  73. isLast={i === workspace.content.length - 1}
  74. key={c.id}
  75. />
  76. )
  77. )}
  78. </div>
  79. <DropdownCreateButton customClass='workspace__content__button mb-5' />
  80. <div id='appContainer' />
  81. </PageContent>
  82. </PageWrapper>
  83. )
  84. }
  85. }
  86. const mapStateToProps = ({ user, workspace, workspaceList, activeFileContent, app }) => ({ user, workspace, workspaceList, activeFileContent, app })
  87. export default connect(mapStateToProps)(WorkspaceContent)