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.9KB

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