net-info-group.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const React = require("devtools/client/shared/vendor/react");
  6. const NetInfoParams = React.createFactory(require("./net-info-params"));
  7. // Shortcuts
  8. const DOM = React.DOM;
  9. const PropTypes = React.PropTypes;
  10. /**
  11. * This template represents a group of data within a tab. For example,
  12. * Headers tab has two groups 'Request Headers' and 'Response Headers'
  13. * The Response tab can also have two groups 'Raw Data' and 'JSON'
  14. */
  15. var NetInfoGroup = React.createClass({
  16. propTypes: {
  17. type: PropTypes.string.isRequired,
  18. name: PropTypes.string.isRequired,
  19. params: PropTypes.array,
  20. content: PropTypes.element,
  21. open: PropTypes.bool
  22. },
  23. displayName: "NetInfoGroup",
  24. getDefaultProps() {
  25. return {
  26. open: true,
  27. };
  28. },
  29. getInitialState() {
  30. return {
  31. open: this.props.open,
  32. };
  33. },
  34. onToggle(event) {
  35. this.setState({
  36. open: !this.state.open
  37. });
  38. },
  39. render() {
  40. let content = this.props.content;
  41. if (!content && this.props.params) {
  42. content = NetInfoParams({
  43. params: this.props.params
  44. });
  45. }
  46. let open = this.state.open;
  47. let className = open ? "opened" : "";
  48. return (
  49. DOM.div({className: "netInfoGroup" + " " + className + " " +
  50. this.props.type},
  51. DOM.span({
  52. className: "netInfoGroupTwisty",
  53. onClick: this.onToggle
  54. }),
  55. DOM.span({
  56. className: "netInfoGroupTitle",
  57. onClick: this.onToggle},
  58. this.props.name
  59. ),
  60. DOM.div({className: "netInfoGroupContent"},
  61. content
  62. )
  63. )
  64. );
  65. }
  66. });
  67. // Exports from this module
  68. module.exports = NetInfoGroup;