2023-03-21 09:47:52 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
2023-03-30 11:27:53 +03:00
|
|
|
import { createToolbarEvent } from '../../analytics/AnalyticsEvents';
|
|
|
|
|
import { sendAnalytics } from '../../analytics/functions';
|
|
|
|
|
import { IReduxState } from '../../app/types';
|
|
|
|
|
import { HELP_BUTTON_ENABLED } from '../../base/flags/constants';
|
|
|
|
|
import { getFeatureFlag } from '../../base/flags/functions';
|
|
|
|
|
import { translate } from '../../base/i18n/functions';
|
|
|
|
|
import { IconHelp } from '../../base/icons/svg';
|
|
|
|
|
import AbstractButton, { IProps as AbstractButtonProps } from '../../base/toolbox/components/AbstractButton';
|
|
|
|
|
import { openURLInBrowser } from '../../base/util/openURLInBrowser';
|
2019-10-11 19:09:50 +01:00
|
|
|
|
2023-03-30 11:27:53 +03:00
|
|
|
interface IProps extends AbstractButtonProps {
|
2019-10-11 19:09:50 +01:00
|
|
|
|
|
|
|
|
/**
|
2021-03-16 11:59:33 -04:00
|
|
|
* The URL to the user documentation.
|
2019-10-11 19:09:50 +01:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
_userDocumentationURL: string;
|
|
|
|
|
}
|
2019-10-11 19:09:50 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implements an {@link AbstractButton} to open the user documentation in a new window.
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
class HelpButton extends AbstractButton<IProps> {
|
2019-10-11 19:09:50 +01:00
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.help';
|
|
|
|
|
icon = IconHelp;
|
|
|
|
|
label = 'toolbar.help';
|
2021-07-08 16:42:07 +03:00
|
|
|
tooltip = 'toolbar.help';
|
2019-10-11 19:09:50 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles clicking / pressing the button, and opens a new window with the user documentation.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
_handleClick() {
|
2022-01-04 13:21:00 +02:00
|
|
|
const { _userDocumentationURL } = this.props;
|
2021-09-14 10:07:20 +03:00
|
|
|
|
2019-10-11 19:09:50 +01:00
|
|
|
sendAnalytics(createToolbarEvent('help.pressed'));
|
2021-09-14 10:07:20 +03:00
|
|
|
openURLInBrowser(_userDocumentationURL);
|
2019-10-11 19:09:50 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maps part of the redux state to the component's props.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} state - The redux store/state.
|
|
|
|
|
* @returns {Object}
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
function _mapStateToProps(state: IReduxState) {
|
2019-10-16 19:36:39 +01:00
|
|
|
const { userDocumentationURL } = state['features/base/config'].deploymentUrls || {};
|
2021-02-10 22:34:13 +01:00
|
|
|
const enabled = getFeatureFlag(state, HELP_BUTTON_ENABLED, true);
|
2022-06-09 16:00:41 +03:00
|
|
|
const visible = typeof userDocumentationURL === 'string' && enabled;
|
2019-10-11 19:09:50 +01:00
|
|
|
|
|
|
|
|
return {
|
2023-03-30 11:27:53 +03:00
|
|
|
_userDocumentationURL: userDocumentationURL ?? '',
|
2019-10-11 19:09:50 +01:00
|
|
|
visible
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(HelpButton));
|