index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 ReactTabs from 'react-tabs'
  21. import permissionFilter from 'jsx/shared/helpers/permissionFilter'
  22. import CoursesStore from './CoursesStore'
  23. import TermsStore from './TermsStore'
  24. import AccountsTreeStore from './AccountsTreeStore'
  25. import UsersStore from './UsersStore'
  26. const { Tab, Tabs, TabList, TabPanel } = ReactTabs
  27. const { string, bool, shape } = PropTypes
  28. const stores = [CoursesStore, TermsStore, AccountsTreeStore, UsersStore]
  29. class AccountCourseUserSearch extends React.Component {
  30. static propTypes = {
  31. accountId: string.isRequired,
  32. permissions: shape({
  33. theme_editor: bool.isRequired,
  34. analytics: bool.isRequired
  35. }).isRequired
  36. }
  37. componentWillMount () {
  38. stores.forEach((s) => {
  39. s.reset({ accountId: this.props.accountId });
  40. });
  41. }
  42. render () {
  43. const { timezones, permissions, store } = this.props
  44. const tabList = store.getState().tabList;
  45. const tabs = permissionFilter(tabList.tabs, permissions);
  46. const headers = tabs.map((tab, index) => {
  47. return (
  48. <Tab key={index}>
  49. <a href={tabList.basePath + tab.path} title={tab.title}>{tab.title}</a>
  50. </Tab>
  51. );
  52. });
  53. const panels = tabs.map((tab, index) => {
  54. const Pane = tab.pane;
  55. return (
  56. <TabPanel key={index}>
  57. <Pane {...this.props} />
  58. </TabPanel>
  59. );
  60. });
  61. return (
  62. <Tabs selectedIndex={tabList.selected}>
  63. <TabList>
  64. {headers}
  65. </TabList>
  66. {panels}
  67. </Tabs>
  68. );
  69. }
  70. }
  71. export default AccountCourseUserSearch