You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HelpButton.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // @flow
  2. import { createToolbarEvent, sendAnalytics } from '../../analytics';
  3. import { HELP_BUTTON_ENABLED, getFeatureFlag } from '../../base/flags';
  4. import { translate } from '../../base/i18n';
  5. import { IconHelp } from '../../base/icons';
  6. import { connect } from '../../base/redux';
  7. import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox/components';
  8. import { openURLInBrowser } from '../../base/util';
  9. type Props = AbstractButtonProps & {
  10. /**
  11. * The URL to the user documentation.
  12. */
  13. _userDocumentationURL: string
  14. };
  15. /**
  16. * Implements an {@link AbstractButton} to open the user documentation in a new window.
  17. */
  18. class HelpButton extends AbstractButton<Props, *> {
  19. accessibilityLabel = 'toolbar.accessibilityLabel.help';
  20. icon = IconHelp;
  21. label = 'toolbar.help';
  22. tooltip = 'toolbar.help';
  23. /**
  24. * Handles clicking / pressing the button, and opens a new window with the user documentation.
  25. *
  26. * @private
  27. * @returns {void}
  28. */
  29. _handleClick() {
  30. const { _userDocumentationURL } = this.props;
  31. sendAnalytics(createToolbarEvent('help.pressed'));
  32. openURLInBrowser(_userDocumentationURL);
  33. }
  34. }
  35. /**
  36. * Maps part of the redux state to the component's props.
  37. *
  38. * @param {Object} state - The redux store/state.
  39. * @returns {Object}
  40. */
  41. function _mapStateToProps(state: Object) {
  42. const { userDocumentationURL } = state['features/base/config'].deploymentUrls || {};
  43. const enabled = getFeatureFlag(state, HELP_BUTTON_ENABLED, true);
  44. const visible = typeof userDocumentationURL === 'string' && enabled;
  45. return {
  46. _userDocumentationURL: userDocumentationURL,
  47. visible
  48. };
  49. }
  50. export default translate(connect(_mapStateToProps)(HelpButton));