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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // @flow
  2. import { createToolbarEvent, sendAnalytics } from '../../analytics';
  3. import { getFeatureFlag, HELP_BUTTON_ENABLED } 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 documenation.
  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. /**
  23. * Handles clicking / pressing the button, and opens a new window with the user documentation.
  24. *
  25. * @private
  26. * @returns {void}
  27. */
  28. _handleClick() {
  29. sendAnalytics(createToolbarEvent('help.pressed'));
  30. openURLInBrowser(this.props._userDocumentationURL);
  31. }
  32. }
  33. /**
  34. * Maps part of the redux state to the component's props.
  35. *
  36. * @param {Object} state - The redux store/state.
  37. * @returns {Object}
  38. */
  39. function _mapStateToProps(state: Object) {
  40. const { userDocumentationURL } = state['features/base/config'].deploymentUrls || {};
  41. const enabled = getFeatureFlag(state, HELP_BUTTON_ENABLED, true);
  42. const visible = typeof userDocumentationURL === 'string' && enabled;
  43. return {
  44. _userDocumentationURL: userDocumentationURL,
  45. visible
  46. };
  47. }
  48. export default translate(connect(_mapStateToProps)(HelpButton));