OrgPreferences.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. const dashboards: DashboardSearchHit[] = [
  40. { id: 0, title: 'Default', tags: [], type: '', uid: '', uri: '', url: '' },
  41. ...starredDashboards,
  42. ];
  43. return (
  44. <form className="section gf-form-group" onSubmit={this.onSubmitForm}>
  45. <h3 className="page-heading">Preferences</h3>
  46. <div className="gf-form">
  47. <span className="gf-form-label width-11">UI Theme</span>
  48. <SimplePicker
  49. defaultValue={themes.find(theme => theme.value === preferences.theme)}
  50. options={themes}
  51. getOptionValue={i => i.value}
  52. getOptionLabel={i => i.text}
  53. onSelected={theme => setOrganizationTheme(theme.value)}
  54. width={20}
  55. />
  56. </div>
  57. <div className="gf-form">
  58. <Label
  59. width={11}
  60. tooltip="Not finding dashboard you want? Star it first, then it should appear in this select box."
  61. >
  62. Home Dashboard
  63. </Label>
  64. <SimplePicker
  65. defaultValue={dashboards.find(dashboard => dashboard.id === preferences.homeDashboardId)}
  66. getOptionValue={i => i.id}
  67. getOptionLabel={i => i.title}
  68. onSelected={(dashboard: DashboardSearchHit) => setOrganizationHomeDashboard(dashboard.id)}
  69. options={dashboards}
  70. placeholder="Chose default dashboard"
  71. width={20}
  72. />
  73. </div>
  74. <div className="gf-form">
  75. <label className="gf-form-label width-11">Timezone</label>
  76. <SimplePicker
  77. defaultValue={timezones.find(timezone => timezone.value === preferences.timezone)}
  78. getOptionValue={i => i.value}
  79. getOptionLabel={i => i.text}
  80. onSelected={timezone => setOrganizationTimezone(timezone.value)}
  81. options={timezones}
  82. width={20}
  83. />
  84. </div>
  85. <div className="gf-form-button-row">
  86. <button type="submit" className="btn btn-success">
  87. Save
  88. </button>
  89. </div>
  90. </form>
  91. );
  92. }
  93. }
  94. function mapStateToProps(state) {
  95. return {
  96. preferences: state.organization.preferences,
  97. starredDashboards: state.user.starredDashboards,
  98. };
  99. }
  100. const mapDispatchToProps = {
  101. setOrganizationHomeDashboard,
  102. setOrganizationTimezone,
  103. setOrganizationTheme,
  104. updateOrganizationPreferences,
  105. };
  106. export default connect(mapStateToProps, mapDispatchToProps)(OrgPreferences);