size-limit.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // Shortcuts
  7. const DOM = React.DOM;
  8. const PropTypes = React.PropTypes;
  9. /**
  10. * This template represents a size limit notification message
  11. * used e.g. in the Response tab when response body exceeds
  12. * size limit. The message contains a link allowing the user
  13. * to fetch the rest of the data from the backend (debugger server).
  14. */
  15. var SizeLimit = React.createClass({
  16. propTypes: {
  17. data: PropTypes.object.isRequired,
  18. message: PropTypes.string.isRequired,
  19. link: PropTypes.string.isRequired,
  20. actions: PropTypes.shape({
  21. resolveString: PropTypes.func.isRequired
  22. }),
  23. },
  24. displayName: "SizeLimit",
  25. // Event Handlers
  26. onClickLimit(event) {
  27. let actions = this.props.actions;
  28. let content = this.props.data;
  29. actions.resolveString(content, "text");
  30. },
  31. // Rendering
  32. render() {
  33. let message = this.props.message;
  34. let link = this.props.link;
  35. let reLink = /^(.*)\{\{link\}\}(.*$)/;
  36. let m = message.match(reLink);
  37. return (
  38. DOM.div({className: "netInfoSizeLimit"},
  39. DOM.span({}, m[1]),
  40. DOM.a({
  41. className: "objectLink",
  42. onClick: this.onClickLimit},
  43. link
  44. ),
  45. DOM.span({}, m[2])
  46. )
  47. );
  48. }
  49. });
  50. // Exports from this module
  51. module.exports = SizeLimit;