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 { 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 (

Preferences

UI Theme theme.value === preferences.theme)} options={themes} getOptionValue={i => i.value} getOptionLabel={i => i.text} onSelected={theme => setOrganizationTheme(theme.value)} width={20} />
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} />
timezone.value === preferences.timezone)} getOptionValue={i => i.value} getOptionLabel={i => i.text} onSelected={timezone => setOrganizationTimezone(timezone.value)} options={timezones} width={20} />
); } } function mapStateToProps(state) { return { preferences: state.organization.preferences, starredDashboards: state.user.starredDashboards, }; } const mapDispatchToProps = { setOrganizationHomeDashboard, setOrganizationTimezone, setOrganizationTheme, updateOrganizationPreferences, }; export default connect(mapStateToProps, mapDispatchToProps)(OrgPreferences);