| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import React, { PureComponent } from 'react';
- import { connect } from 'react-redux';
- import { Label } from '../../core/components/Label/Label';
- import SimplePicker from '../../core/components/Picker/SimplePicker';
- import { DashboardSearchHit, OrganizationPreferences } from 'app/types';
- import {
- setOrganizationHomeDashboard,
- setOrganizationTheme,
- setOrganizationTimezone,
- updateOrganizationPreferences,
- } from './state/actions';
- export interface Props {
- preferences: OrganizationPreferences;
- starredDashboards: DashboardSearchHit[];
- setOrganizationHomeDashboard: typeof setOrganizationHomeDashboard;
- setOrganizationTheme: typeof setOrganizationTheme;
- setOrganizationTimezone: typeof setOrganizationTimezone;
- updateOrganizationPreferences: typeof updateOrganizationPreferences;
- }
- const themes = [{ value: '', text: 'Default' }, { value: 'dark', text: 'Dark' }, { value: 'light', text: 'Light' }];
- const timezones = [
- { value: '', text: 'Default' },
- { value: 'browser', text: 'Local browser time' },
- { value: 'utc', text: 'UTC' },
- ];
- export class OrgPreferences extends PureComponent<Props> {
- onSubmitForm = event => {
- event.preventDefault();
- this.props.updateOrganizationPreferences();
- };
- render() {
- const {
- preferences,
- starredDashboards,
- setOrganizationHomeDashboard,
- setOrganizationTimezone,
- setOrganizationTheme,
- } = this.props;
- starredDashboards.unshift({ id: 0, title: 'Default', tags: [], type: '', uid: '', uri: '', url: '' });
- return (
- <form className="section gf-form-group" onSubmit={this.onSubmitForm}>
- <h3 className="page-heading">Preferences</h3>
- <div className="gf-form">
- <span className="gf-form-label width-11">UI Theme</span>
- <SimplePicker
- defaultValue={themes.find(theme => theme.value === preferences.theme)}
- options={themes}
- getOptionValue={i => i.value}
- getOptionLabel={i => i.text}
- onSelected={theme => setOrganizationTheme(theme.value)}
- width={20}
- />
- </div>
- <div className="gf-form">
- <Label
- width={11}
- tooltip="Not finding dashboard you want? Star it first, then it should appear in this select box."
- >
- Home Dashboard
- </Label>
- <SimplePicker
- defaultValue={starredDashboards.find(dashboard => dashboard.id === preferences.homeDashboardId)}
- getOptionValue={i => i.id}
- getOptionLabel={i => i.title}
- onSelected={(dashboard: DashboardSearchHit) => setOrganizationHomeDashboard(dashboard.id)}
- options={starredDashboards}
- placeholder="Chose default dashboard"
- width={20}
- />
- </div>
- <div className="gf-form">
- <label className="gf-form-label width-11">Timezone</label>
- <SimplePicker
- defaultValue={timezones.find(timezone => timezone.value === preferences.timezone)}
- getOptionValue={i => i.value}
- getOptionLabel={i => i.text}
- onSelected={timezone => setOrganizationTimezone(timezone.value)}
- options={timezones}
- width={20}
- />
- </div>
- <div className="gf-form-button-row">
- <button type="submit" className="btn btn-success">
- Save
- </button>
- </div>
- </form>
- );
- }
- }
- function mapStateToProps(state) {
- return {
- preferences: state.organization.preferences,
- starredDashboards: state.user.starredDashboards,
- };
- }
- const mapDispatchToProps = {
- setOrganizationHomeDashboard,
- setOrganizationTimezone,
- setOrganizationTheme,
- updateOrganizationPreferences,
- };
- export default connect(mapStateToProps, mapDispatchToProps)(OrgPreferences);
|