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.

SettingsButton.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // @flow
  2. import { createToolbarEvent, sendAnalytics } from '../../../analytics';
  3. import { translate } from '../../../base/i18n';
  4. import { IconSettings } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  7. import { openDeviceSelectionPopup } from '../../../device-selection';
  8. import { openSettingsDialog } from '../../actions';
  9. import { SETTINGS_TABS } from '../../constants';
  10. declare var interfaceConfig: Object;
  11. /**
  12. * The type of the React {@code Component} props of {@link SettingsButton}.
  13. */
  14. type Props = AbstractButtonProps & {
  15. /**
  16. * Whether we are in filmstrip only mode or not.
  17. */
  18. _filmstripOnly: boolean,
  19. /**
  20. * The default tab at which the settings dialog will be opened.
  21. */
  22. defaultTab: string,
  23. /**
  24. * The redux {@code dispatch} function.
  25. */
  26. dispatch: Function
  27. };
  28. /**
  29. * An abstract implementation of a button for accessing settings.
  30. */
  31. class SettingsButton extends AbstractButton<Props, *> {
  32. accessibilityLabel = 'toolbar.accessibilityLabel.Settings';
  33. icon = IconSettings;
  34. label = 'toolbar.Settings';
  35. tooltip = 'toolbar.Settings';
  36. /**
  37. * Handles clicking / pressing the button, and opens the appropriate dialog.
  38. *
  39. * @protected
  40. * @returns {void}
  41. */
  42. _handleClick() {
  43. const {
  44. _filmstripOnly,
  45. defaultTab = SETTINGS_TABS.DEVICES,
  46. dispatch } = this.props;
  47. sendAnalytics(createToolbarEvent('settings'));
  48. if (_filmstripOnly) {
  49. dispatch(openDeviceSelectionPopup());
  50. } else {
  51. dispatch(openSettingsDialog(defaultTab));
  52. }
  53. }
  54. }
  55. /**
  56. * Maps (parts of) the redux state to the associated props for the
  57. * {@code SettingsButton} component.
  58. *
  59. * @param {Object} state - The Redux state.
  60. * @private
  61. * @returns {{
  62. * _filmstripOnly: boolean
  63. * }}
  64. */
  65. function _mapStateToProps(state): Object { // eslint-disable-line no-unused-vars
  66. // XXX: We are not currently using state here, but in the future, when
  67. // interfaceConfig is part of redux we will.
  68. return {
  69. _filmstripOnly: Boolean(interfaceConfig.filmStripOnly)
  70. };
  71. }
  72. export default translate(connect(_mapStateToProps)(SettingsButton));