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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import { createToolbarEvent, sendAnalytics } from '../../../../analytics';
  4. import { translate } from '../../../../base/i18n';
  5. import { openDeviceSelectionDialog } from '../../../../device-selection';
  6. import { toggleSettings } from '../../../../side-panel';
  7. import AbstractButton from '../AbstractButton';
  8. import type { Props as AbstractButtonProps } from '../AbstractButton';
  9. declare var interfaceConfig: Object;
  10. type Props = AbstractButtonProps & {
  11. /**
  12. * Whether we are in filmstrip only mode or not.
  13. */
  14. _filmstripOnly: boolean,
  15. /**
  16. * Array containing the enabled settings sections.
  17. */
  18. _sections: Array<string>,
  19. /**
  20. * The redux {@code dispatch} function.
  21. */
  22. dispatch: Function
  23. }
  24. /**
  25. * An abstract implementation of a button for accessing settings.
  26. */
  27. class SettingsButton extends AbstractButton<Props, *> {
  28. accessibilityLabel = 'Settings';
  29. iconName = 'icon-settings';
  30. label = 'toolbar.Settings';
  31. tooltip = 'toolbar.Settings';
  32. /**
  33. * Handles clicking / pressing the button, and opens the appropriate dialog.
  34. *
  35. * @private
  36. * @returns {void}
  37. */
  38. _handleClick() {
  39. const { _filmstripOnly, _sections, dispatch } = this.props;
  40. sendAnalytics(createToolbarEvent('settings'));
  41. if (_filmstripOnly
  42. || (_sections.length === 1 && _sections.includes('devices'))) {
  43. dispatch(openDeviceSelectionDialog());
  44. } else {
  45. dispatch(toggleSettings());
  46. }
  47. }
  48. /**
  49. * Indicates whether this button is disabled or not.
  50. *
  51. * @override
  52. * @private
  53. * @returns {boolean}
  54. */
  55. _isDisabled() {
  56. return false;
  57. }
  58. }
  59. /**
  60. * Maps (parts of) the redux state to the associated props for the
  61. * {@code SettingsButton} component.
  62. *
  63. * @param {Object} state - The Redux state.
  64. * @private
  65. * @returns {{
  66. * _filmstripOnly: boolean
  67. * }}
  68. */
  69. function _mapStateToProps(state): Object { // eslint-disable-line no-unused-vars
  70. // XXX: We are not currently using state here, but in the future, when
  71. // interfaceConfig is part of redux we will.
  72. return {
  73. _filmstripOnly: Boolean(interfaceConfig.filmStripOnly),
  74. _sections: interfaceConfig.SETTINGS_SECTIONS || []
  75. };
  76. }
  77. export default translate(connect(_mapStateToProps)(SettingsButton));