BBTreeBrowser.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2015 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import React from 'react'
  19. import PropTypes from 'prop-types'
  20. import ReactDOM from 'react-dom'
  21. import customPropTypes from 'compiled/react_files/modules/customPropTypes'
  22. import I18n from 'i18n!react_files'
  23. import BBTreeBrowserView from 'compiled/react_files/modules/BBTreeBrowserView'
  24. import RootFoldersFinder from 'compiled/views/RootFoldersFinder'
  25. var BBTreeBrowser = React.createClass({
  26. displayName: "BBTreeBrowser",
  27. propTypes: {
  28. rootFoldersToShow: PropTypes.arrayOf(customPropTypes.folder).isRequired,
  29. onSelectFolder: PropTypes.func.isRequired
  30. },
  31. componentDidMount(){
  32. var rootFoldersFinder = new RootFoldersFinder({
  33. rootFoldersToShow: this.props.rootFoldersToShow
  34. })
  35. this.treeBrowserViewId = BBTreeBrowserView.create({
  36. onlyShowSubtrees: true,
  37. rootModelsFinder: rootFoldersFinder,
  38. rootFoldersToShow: this.props.rootFoldersToShow,
  39. onClick: this.props.onSelectFolder,
  40. focusStyleClass: 'MoveDialog__folderItem--focused',
  41. selectedStyleClass: 'MoveDialog__folderItem--selected'
  42. },
  43. {
  44. element: ReactDOM.findDOMNode(this.refs.FolderTreeHolder)
  45. }).index
  46. window.setTimeout(function(){
  47. BBTreeBrowserView.getView(this.treeBrowserViewId).render().$el.appendTo(ReactDOM.findDOMNode(this.refs.FolderTreeHolder)).find(':tabbable:first').focus()
  48. }.bind(this), 0);
  49. },
  50. componentWillUnmount(){
  51. BBTreeBrowserView.remove(this.treeBrowserViewId)
  52. },
  53. render(){
  54. return(
  55. <aside role='region' aria-label={I18n.t('folder_browsing_tree', 'Folder Browsing Tree')}>
  56. <div ref="FolderTreeHolder"></div>
  57. </aside>
  58. );
  59. }
  60. });
  61. export default BBTreeBrowser