WithSidebar.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React, { Component, PropTypes } from 'react';
  15. import withStyles from 'isomorphic-style-loader/lib/withStyles';
  16. import s from './WithSidebar.scss';
  17. import Location from '../../core/Location';
  18. class WithSidebar extends Component {
  19. static propTypes = {
  20. children: PropTypes.element.isRequired,
  21. route: PropTypes.string
  22. }
  23. constructor(props) {
  24. super(props)
  25. this.state = {
  26. menuItems: [
  27. {
  28. label: "Replicas",
  29. route: "/replicas"
  30. },
  31. {
  32. label: "Migrations",
  33. route: "/migrations"
  34. },
  35. {
  36. label: "Cloud Endpoints",
  37. route: "/cloud-endpoints"
  38. },
  39. {
  40. label: "Projects",
  41. route: "/projects"
  42. }
  43. ]
  44. }
  45. }
  46. goToMenu(item) {
  47. Location.push(item.route)
  48. }
  49. render() {
  50. let menuItems = this.state.menuItems.map((item, index) =>
  51. (
  52. <li
  53. key={"menu_" + index} className={item.route == this.props.route ? s.active : ""}
  54. onClick={() => this.goToMenu(item)}
  55. >
  56. {item.label}
  57. </li>
  58. ), this)
  59. return (
  60. <div className={s.root}>
  61. <div className={s.sidebar}>
  62. <div
  63. className={s.logo + " logo coriolis-white"}
  64. onClick={() => this.goToMenu({ route: "/migrations" })}
  65. ></div>
  66. <ul>
  67. {menuItems}
  68. </ul>
  69. </div>
  70. <div className={s.container}>
  71. {this.props.children}
  72. </div>
  73. </div>
  74. );
  75. }
  76. }
  77. export default withStyles(WithSidebar, s);