OrgPreferences.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'react-redux';
  3. import { Label } from '../../core/components/Label/Label';
  4. import SimplePicker from '../../core/components/Picker/SimplePicker';
  5. import { DashboardSearchHit, OrganizationPreferences } from 'app/types';
  6. import {
  7. setOrganizationHomeDashboard,
  8. setOrganizationTheme,
  9. setOrganizationTimezone,
  10. updateOrganizationPreferences,
  11. } from './state/actions';
  12. export interface Props {
  13. preferences: OrganizationPreferences;
  14. starredDashboards: DashboardSearchHit[];
  15. setOrganizationHomeDashboard: typeof setOrganizationHomeDashboard;
  16. setOrganizationTheme: typeof setOrganizationTheme;
  17. setOrganizationTimezone: typeof setOrganizationTimezone;
  18. updateOrganizationPreferences: typeof updateOrganizationPreferences;
  19. }
  20. const themes = [{ value: '', text: 'Default' }, { value: 'dark', text: 'Dark' }, { value: 'light', text: 'Light' }];
  21. const timezones = [
  22. { value: '', text: 'Default' },
  23. { value: 'browser', text: 'Local browser time' },
  24. { value: 'utc', text: 'UTC' },
  25. ];
  26. export class OrgPreferences extends PureComponent<Props> {
  27. onSubmitForm = event => {
  28. event.preventDefault();
  29. this.props.updateOrganizationPreferences();
  30. };
  31. render() {
  32. const {
  33. preferences,
  34. starredDashboards,
  35. setOrganizationHomeDashboard,
  36. setOrganizationTimezone,
  37. setOrganizationTheme,
  38. } = this.props;
  39. starredDashboards.unshift({ id: 0, title: 'Default', tags: [], type: '', uid: '', uri: '', url: '' });
  40. return (
  41. <form className="section gf-form-group" onSubmit={this.onSubmitForm}>
  42. <h3 className="page-heading">Preferences</h3>
  43. <div className="gf-form">
  44. <span className="gf-form-label width-11">UI Theme</span>
  45. <SimplePicker
  46. defaultValue={themes.find(theme => theme.value === preferences.theme)}
  47. options={themes}
  48. getOptionValue={i => i.value}
  49. getOptionLabel={i => i.text}
  50. onSelected={theme => setOrganizationTheme(theme.value)}
  51. width={20}
  52. />
  53. </div>
  54. <div className="gf-form">
  55. <Label
  56. width={11}
  57. tooltip="Not finding dashboard you want? Star it first, then it should appear in this select box."
  58. >
  59. Home Dashboard
  60. </Label>
  61. <SimplePicker
  62. defaultValue={starredDashboards.find(dashboard => dashboard.id === preferences.homeDashboardId)}
  63. getOptionValue={i => i.id}
  64. getOptionLabel={i => i.title}
  65. onSelected={(dashboard: DashboardSearchHit) => setOrganizationHomeDashboard(dashboard.id)}
  66. options={starredDashboards}
  67. placeholder="Chose default dashboard"
  68. width={20}
  69. />
  70. </div>
  71. <div className="gf-form">
  72. <label className="gf-form-label width-11">Timezone</label>
  73. <SimplePicker
  74. defaultValue={timezones.find(timezone => timezone.value === preferences.timezone)}
  75. getOptionValue={i => i.value}
  76. getOptionLabel={i => i.text}
  77. onSelected={timezone => setOrganizationTimezone(timezone.value)}
  78. options={timezones}
  79. width={20}
  80. />
  81. </div>
  82. <div className="gf-form-button-row">
  83. <button type="submit" className="btn btn-success">
  84. Save
  85. </button>
  86. </div>
  87. </form>
  88. );
  89. }
  90. }
  91. function mapStateToProps(state) {
  92. return {
  93. preferences: state.organization.preferences,
  94. starredDashboards: state.user.starredDashboards,
  95. };
  96. }
  97. const mapDispatchToProps = {
  98. setOrganizationHomeDashboard,
  99. setOrganizationTimezone,
  100. setOrganizationTheme,
  101. updateOrganizationPreferences,
  102. };
  103. export default connect(mapStateToProps, mapDispatchToProps)(OrgPreferences);