|
|
|
@ -3,7 +3,7 @@ import React, { PureComponent } from 'react'; |
|
|
|
|
|
|
|
|
|
import { FeatureState, SelectableValue } from '@grafana/data'; |
|
|
|
|
import { selectors } from '@grafana/e2e-selectors'; |
|
|
|
|
import { config } from '@grafana/runtime'; |
|
|
|
|
import { config, reportInteraction } from '@grafana/runtime'; |
|
|
|
|
import { |
|
|
|
|
Button, |
|
|
|
|
Field, |
|
|
|
@ -26,17 +26,12 @@ import { UserPreferencesDTO } from 'app/types'; |
|
|
|
|
export interface Props { |
|
|
|
|
resourceUri: string; |
|
|
|
|
disabled?: boolean; |
|
|
|
|
preferenceType: 'org' | 'team' | 'user'; |
|
|
|
|
onConfirm?: () => Promise<boolean>; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export type State = UserPreferencesDTO; |
|
|
|
|
|
|
|
|
|
const themes: SelectableValue[] = [ |
|
|
|
|
{ value: '', label: t('shared-preferences.theme.default-label', 'Default') }, |
|
|
|
|
{ value: 'dark', label: t('shared-preferences.theme.dark-label', 'Dark') }, |
|
|
|
|
{ value: 'light', label: t('shared-preferences.theme.light-label', 'Light') }, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
function getLanguageOptions(): Array<SelectableValue<string>> { |
|
|
|
|
const languageOptions = LANGUAGES.map((v) => ({ |
|
|
|
|
value: v.code, |
|
|
|
@ -58,6 +53,7 @@ const i18nFlag = Boolean(config.featureToggles.internationalization); |
|
|
|
|
|
|
|
|
|
export class SharedPreferences extends PureComponent<Props, State> { |
|
|
|
|
service: PreferencesService; |
|
|
|
|
themeOptions: SelectableValue[]; |
|
|
|
|
|
|
|
|
|
constructor(props: Props) { |
|
|
|
|
super(props); |
|
|
|
@ -70,6 +66,12 @@ export class SharedPreferences extends PureComponent<Props, State> { |
|
|
|
|
language: '', |
|
|
|
|
queryHistory: { homeTab: '' }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.themeOptions = [ |
|
|
|
|
{ value: '', label: t('shared-preferences.theme.default-label', 'Default') }, |
|
|
|
|
{ value: 'dark', label: t('shared-preferences.theme.dark-label', 'Dark') }, |
|
|
|
|
{ value: 'light', label: t('shared-preferences.theme.light-label', 'Light') }, |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async componentDidMount() { |
|
|
|
@ -116,6 +118,11 @@ export class SharedPreferences extends PureComponent<Props, State> { |
|
|
|
|
|
|
|
|
|
onLanguageChanged = (language: string) => { |
|
|
|
|
this.setState({ language }); |
|
|
|
|
|
|
|
|
|
reportInteraction('grafana_preferences_language_changed', { |
|
|
|
|
toLanguage: language, |
|
|
|
|
preferenceType: this.props.preferenceType, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
@ -131,8 +138,8 @@ export class SharedPreferences extends PureComponent<Props, State> { |
|
|
|
|
<FieldSet label={<Trans i18nKey="shared-preferences.title">Preferences</Trans>} disabled={disabled}> |
|
|
|
|
<Field label={t('shared-preferences.fields.theme-label', 'UI Theme')}> |
|
|
|
|
<RadioButtonGroup |
|
|
|
|
options={themes} |
|
|
|
|
value={themes.find((item) => item.value === theme)?.value} |
|
|
|
|
options={this.themeOptions} |
|
|
|
|
value={this.themeOptions.find((item) => item.value === theme)?.value} |
|
|
|
|
onChange={this.onThemeChanged} |
|
|
|
|
/> |
|
|
|
|
</Field> |
|
|
|
|