cloud-feature.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { connect } from 'react-redux';
  4. class CloudFeature extends React.Component {
  5. getChildContext() {
  6. return {
  7. store: this.context.serviceStore || this.context.store || {}
  8. };
  9. }
  10. render() {
  11. if (process.env.WEAVE_CLOUD) {
  12. return React.cloneElement(React.Children.only(this.props.children), {
  13. params: this.context.router.params,
  14. router: this.context.router
  15. });
  16. }
  17. // also show if not in weave cloud?
  18. if (this.props.alwaysShow) {
  19. return React.cloneElement(React.Children.only(this.props.children));
  20. }
  21. return null;
  22. }
  23. }
  24. /* eslint-disable react/forbid-prop-types */
  25. // TODO: Remove this component as part of https://github.com/weaveworks/scope/issues/3278.
  26. CloudFeature.contextTypes = {
  27. router: PropTypes.object,
  28. serviceStore: PropTypes.object,
  29. store: PropTypes.object.isRequired
  30. };
  31. CloudFeature.childContextTypes = {
  32. router: PropTypes.object,
  33. store: PropTypes.object
  34. };
  35. /* eslint-enable react/forbid-prop-types */
  36. export default connect()(CloudFeature);