| 
									
										
										
										
											2021-04-01 20:15:23 +08:00
										 |  |  | import { css } from '@emotion/css'; | 
					
						
							| 
									
										
										
										
											2024-06-25 19:43:47 +08:00
										 |  |  | import { PureComponent } from 'react'; | 
					
						
							|  |  |  | import * as React from 'react'; | 
					
						
							| 
									
										
										
										
											2020-06-08 23:19:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 22:28:00 +08:00
										 |  |  | import { FeatureState, getBuiltInThemes, ThemeRegistryItem } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | import { selectors } from '@grafana/e2e-selectors'; | 
					
						
							| 
									
										
										
										
											2022-11-28 20:11:55 +08:00
										 |  |  | import { config, reportInteraction } from '@grafana/runtime'; | 
					
						
							| 
									
										
										
										
											2023-01-26 03:00:32 +08:00
										 |  |  | import { Preferences as UserPreferencesDTO } from '@grafana/schema/src/raw/preferences/x/preferences_types.gen'; | 
					
						
							| 
									
										
										
										
											2020-06-08 23:19:00 +08:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2021-05-25 20:48:16 +08:00
										 |  |  |   Button, | 
					
						
							| 
									
										
										
										
											2020-06-08 23:19:00 +08:00
										 |  |  |   Field, | 
					
						
							| 
									
										
										
										
											2021-05-25 20:48:16 +08:00
										 |  |  |   FieldSet, | 
					
						
							| 
									
										
										
										
											2020-06-08 23:19:00 +08:00
										 |  |  |   Label, | 
					
						
							| 
									
										
										
										
											2021-05-25 20:48:16 +08:00
										 |  |  |   stylesFactory, | 
					
						
							| 
									
										
										
										
											2020-06-26 15:08:15 +08:00
										 |  |  |   TimeZonePicker, | 
					
						
							| 
									
										
										
										
											2021-11-17 21:45:45 +08:00
										 |  |  |   WeekStartPicker, | 
					
						
							| 
									
										
										
										
											2022-06-23 16:20:31 +08:00
										 |  |  |   FeatureBadge, | 
					
						
							| 
									
										
										
										
											2024-10-31 00:59:28 +08:00
										 |  |  |   Combobox, | 
					
						
							|  |  |  |   ComboboxOption, | 
					
						
							| 
									
										
										
										
											2025-02-06 19:08:04 +08:00
										 |  |  |   TextLink, | 
					
						
							| 
									
										
										
										
											2020-06-08 23:19:00 +08:00
										 |  |  | } from '@grafana/ui'; | 
					
						
							| 
									
										
										
										
											2022-08-27 00:40:40 +08:00
										 |  |  | import { DashboardPicker } from 'app/core/components/Select/DashboardPicker'; | 
					
						
							| 
									
										
										
										
											2022-10-06 23:34:04 +08:00
										 |  |  | import { t, Trans } from 'app/core/internationalization'; | 
					
						
							| 
									
										
										
										
											2024-03-21 19:51:30 +08:00
										 |  |  | import { LANGUAGES, PSEUDO_LOCALE } from 'app/core/internationalization/constants'; | 
					
						
							| 
									
										
										
										
											2021-03-22 15:48:53 +08:00
										 |  |  | import { PreferencesService } from 'app/core/services/PreferencesService'; | 
					
						
							| 
									
										
										
										
											2023-05-10 21:37:04 +08:00
										 |  |  | import { changeTheme } from 'app/core/services/theme'; | 
					
						
							| 
									
										
										
										
											2022-05-23 19:42:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  | export interface Props { | 
					
						
							|  |  |  |   resourceUri: string; | 
					
						
							| 
									
										
										
										
											2021-11-18 21:10:38 +08:00
										 |  |  |   disabled?: boolean; | 
					
						
							| 
									
										
										
										
											2022-11-28 20:11:55 +08:00
										 |  |  |   preferenceType: 'org' | 'team' | 'user'; | 
					
						
							| 
									
										
										
										
											2022-11-22 23:47:42 +08:00
										 |  |  |   onConfirm?: () => Promise<boolean>; | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  | export type State = UserPreferencesDTO & { | 
					
						
							|  |  |  |   isLoading: boolean; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 22:28:00 +08:00
										 |  |  | function getLanguageOptions(): ComboboxOption[] { | 
					
						
							| 
									
										
										
										
											2022-11-22 20:18:34 +08:00
										 |  |  |   const languageOptions = LANGUAGES.map((v) => ({ | 
					
						
							| 
									
										
										
										
											2022-10-21 17:29:03 +08:00
										 |  |  |     value: v.code, | 
					
						
							|  |  |  |     label: v.name, | 
					
						
							| 
									
										
										
										
											2024-03-21 19:51:30 +08:00
										 |  |  |   })).sort((a, b) => { | 
					
						
							|  |  |  |     if (a.value === PSEUDO_LOCALE) { | 
					
						
							|  |  |  |       return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (b.value === PSEUDO_LOCALE) { | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return a.label.localeCompare(b.label); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-10-21 17:29:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-12 19:51:16 +08:00
										 |  |  |   const options = [ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       value: '', | 
					
						
							|  |  |  |       label: t('common.locale.default', 'Default'), | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2022-10-21 17:29:03 +08:00
										 |  |  |     ...languageOptions, | 
					
						
							| 
									
										
										
										
											2022-10-12 19:51:16 +08:00
										 |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return options; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-23 16:20:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  | export class SharedPreferences extends PureComponent<Props, State> { | 
					
						
							| 
									
										
										
										
											2021-03-22 15:48:53 +08:00
										 |  |  |   service: PreferencesService; | 
					
						
							| 
									
										
										
										
											2024-09-10 22:28:00 +08:00
										 |  |  |   themeOptions: ComboboxOption[]; | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-12 20:15:23 +08:00
										 |  |  |   constructor(props: Props) { | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |     super(props); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 15:48:53 +08:00
										 |  |  |     this.service = new PreferencesService(props.resourceUri); | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |     this.state = { | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |       isLoading: false, | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |       theme: '', | 
					
						
							|  |  |  |       timezone: '', | 
					
						
							| 
									
										
										
										
											2021-10-18 21:27:14 +08:00
										 |  |  |       weekStart: '', | 
					
						
							| 
									
										
										
										
											2022-11-22 20:18:34 +08:00
										 |  |  |       language: '', | 
					
						
							| 
									
										
										
										
											2022-05-23 19:42:12 +08:00
										 |  |  |       queryHistory: { homeTab: '' }, | 
					
						
							| 
									
										
										
										
											2024-07-31 20:56:39 +08:00
										 |  |  |       navbar: { bookmarkUrls: [] }, | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2022-11-28 20:11:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-06 19:08:04 +08:00
										 |  |  |     const allowedExtraThemes = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (config.featureToggles.extraThemes) { | 
					
						
							|  |  |  |       allowedExtraThemes.push('debug'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (config.featureToggles.grafanaconThemes) { | 
					
						
							|  |  |  |       allowedExtraThemes.push('desertbloom'); | 
					
						
							|  |  |  |       allowedExtraThemes.push('gildedgrove'); | 
					
						
							|  |  |  |       allowedExtraThemes.push('sapphiredusk'); | 
					
						
							|  |  |  |       allowedExtraThemes.push('tron'); | 
					
						
							| 
									
										
										
										
											2025-02-07 22:27:56 +08:00
										 |  |  |       allowedExtraThemes.push('gloom'); | 
					
						
							| 
									
										
										
										
											2025-02-06 19:08:04 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.themeOptions = getBuiltInThemes(allowedExtraThemes).map((theme) => ({ | 
					
						
							| 
									
										
										
										
											2023-05-10 21:37:04 +08:00
										 |  |  |       value: theme.id, | 
					
						
							|  |  |  |       label: getTranslatedThemeName(theme), | 
					
						
							|  |  |  |     })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Add default option
 | 
					
						
							|  |  |  |     this.themeOptions.unshift({ value: '', label: t('shared-preferences.theme.default-label', 'Default') }); | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async componentDidMount() { | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |     this.setState({ | 
					
						
							|  |  |  |       isLoading: true, | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-03-22 15:48:53 +08:00
										 |  |  |     const prefs = await this.service.load(); | 
					
						
							| 
									
										
										
										
											2018-11-15 21:43:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |     this.setState({ | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |       isLoading: false, | 
					
						
							| 
									
										
										
										
											2022-07-22 16:44:22 +08:00
										 |  |  |       homeDashboardUID: prefs.homeDashboardUID, | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |       theme: prefs.theme, | 
					
						
							|  |  |  |       timezone: prefs.timezone, | 
					
						
							| 
									
										
										
										
											2021-10-18 21:27:14 +08:00
										 |  |  |       weekStart: prefs.weekStart, | 
					
						
							| 
									
										
										
										
											2022-11-22 20:18:34 +08:00
										 |  |  |       language: prefs.language, | 
					
						
							| 
									
										
										
										
											2022-05-23 19:42:12 +08:00
										 |  |  |       queryHistory: prefs.queryHistory, | 
					
						
							| 
									
										
										
										
											2024-07-31 18:07:08 +08:00
										 |  |  |       navbar: prefs.navbar, | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |   onSubmitForm = async (event: React.FormEvent<HTMLFormElement>) => { | 
					
						
							|  |  |  |     event.preventDefault(); | 
					
						
							| 
									
										
										
										
											2022-11-22 23:47:42 +08:00
										 |  |  |     const confirmationResult = this.props.onConfirm ? await this.props.onConfirm() : true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (confirmationResult) { | 
					
						
							| 
									
										
										
										
											2024-07-31 18:07:08 +08:00
										 |  |  |       const { homeDashboardUID, theme, timezone, weekStart, language, queryHistory, navbar } = this.state; | 
					
						
							|  |  |  |       await this.service.update({ homeDashboardUID, theme, timezone, weekStart, language, queryHistory, navbar }); | 
					
						
							| 
									
										
										
										
											2022-11-22 23:47:42 +08:00
										 |  |  |       window.location.reload(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-19 18:52:52 +08:00
										 |  |  |   onThemeChanged = (value: ComboboxOption<string>) => { | 
					
						
							| 
									
										
										
										
											2023-05-10 21:37:04 +08:00
										 |  |  |     this.setState({ theme: value.value }); | 
					
						
							| 
									
										
										
										
											2025-01-29 00:00:54 +08:00
										 |  |  |     reportInteraction('grafana_preferences_theme_changed', { | 
					
						
							|  |  |  |       toTheme: value.value, | 
					
						
							|  |  |  |       preferenceType: this.props.preferenceType, | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2023-05-10 21:37:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (value.value) { | 
					
						
							|  |  |  |       changeTheme(value.value, true); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 22:13:48 +08:00
										 |  |  |   onTimeZoneChanged = (timezone?: string) => { | 
					
						
							| 
									
										
										
										
											2023-05-24 16:28:14 +08:00
										 |  |  |     if (typeof timezone !== 'string') { | 
					
						
							| 
									
										
										
										
											2020-04-27 21:28:06 +08:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-26 15:08:15 +08:00
										 |  |  |     this.setState({ timezone: timezone }); | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 21:27:14 +08:00
										 |  |  |   onWeekStartChanged = (weekStart: string) => { | 
					
						
							|  |  |  |     this.setState({ weekStart: weekStart }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 16:44:22 +08:00
										 |  |  |   onHomeDashboardChanged = (dashboardUID: string) => { | 
					
						
							|  |  |  |     this.setState({ homeDashboardUID: dashboardUID }); | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-22 20:18:34 +08:00
										 |  |  |   onLanguageChanged = (language: string) => { | 
					
						
							|  |  |  |     this.setState({ language }); | 
					
						
							| 
									
										
										
										
											2022-11-28 20:11:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     reportInteraction('grafana_preferences_language_changed', { | 
					
						
							|  |  |  |       toLanguage: language, | 
					
						
							|  |  |  |       preferenceType: this.props.preferenceType, | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2022-06-23 16:20:31 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |   render() { | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |     const { theme, timezone, weekStart, homeDashboardUID, language, isLoading } = this.state; | 
					
						
							| 
									
										
										
										
											2021-11-18 21:10:38 +08:00
										 |  |  |     const { disabled } = this.props; | 
					
						
							| 
									
										
										
										
											2020-06-08 23:19:00 +08:00
										 |  |  |     const styles = getStyles(); | 
					
						
							| 
									
										
										
										
											2022-10-12 19:51:16 +08:00
										 |  |  |     const languages = getLanguageOptions(); | 
					
						
							| 
									
										
										
										
											2023-05-10 21:37:04 +08:00
										 |  |  |     const currentThemeOption = this.themeOptions.find((x) => x.value === theme) ?? this.themeOptions[0]; | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return ( | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |       <form onSubmit={this.onSubmitForm} className={styles.form}> | 
					
						
							|  |  |  |         <FieldSet label={<Trans i18nKey="shared-preferences.title">Preferences</Trans>} disabled={disabled}> | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |           <Field | 
					
						
							|  |  |  |             loading={isLoading} | 
					
						
							|  |  |  |             disabled={isLoading} | 
					
						
							|  |  |  |             label={t('shared-preferences.fields.theme-label', 'Interface theme')} | 
					
						
							| 
									
										
										
										
											2025-02-06 19:08:04 +08:00
										 |  |  |             description={ | 
					
						
							|  |  |  |               config.featureToggles.grafanaconThemes ? ( | 
					
						
							|  |  |  |                 <Trans i18nKey="shared-preferences.fields.theme-description"> | 
					
						
							|  |  |  |                   Enjoying the limited edition themes? Tell us what you'd like to see{' '} | 
					
						
							|  |  |  |                   <TextLink | 
					
						
							|  |  |  |                     variant="bodySmall" | 
					
						
							|  |  |  |                     external | 
					
						
							|  |  |  |                     href="https://docs.google.com/forms/d/e/1FAIpQLSeRKAY8nUMEVIKSYJ99uOO-dimF6Y69_If1Q1jTLOZRWqK1cw/viewform?usp=dialog" | 
					
						
							|  |  |  |                   > | 
					
						
							|  |  |  |                     here. | 
					
						
							|  |  |  |                   </TextLink> | 
					
						
							|  |  |  |                 </Trans> | 
					
						
							|  |  |  |               ) : undefined | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |           > | 
					
						
							| 
									
										
										
										
											2024-09-10 22:28:00 +08:00
										 |  |  |             <Combobox | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |               options={this.themeOptions} | 
					
						
							| 
									
										
										
										
											2024-09-10 22:28:00 +08:00
										 |  |  |               value={currentThemeOption.value} | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |               onChange={this.onThemeChanged} | 
					
						
							| 
									
										
										
										
											2024-09-10 22:28:00 +08:00
										 |  |  |               id="shared-preferences-theme-select" | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |             /> | 
					
						
							|  |  |  |           </Field> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           <Field | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |             loading={isLoading} | 
					
						
							|  |  |  |             disabled={isLoading} | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |             label={ | 
					
						
							|  |  |  |               <Label htmlFor="home-dashboard-select"> | 
					
						
							|  |  |  |                 <span className={styles.labelText}> | 
					
						
							|  |  |  |                   <Trans i18nKey="shared-preferences.fields.home-dashboard-label">Home Dashboard</Trans> | 
					
						
							|  |  |  |                 </span> | 
					
						
							|  |  |  |               </Label> | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             data-testid="User preferences home dashboard drop down" | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <DashboardPicker | 
					
						
							|  |  |  |               value={homeDashboardUID} | 
					
						
							|  |  |  |               onChange={(v) => this.onHomeDashboardChanged(v?.uid ?? '')} | 
					
						
							|  |  |  |               defaultOptions={true} | 
					
						
							|  |  |  |               isClearable={true} | 
					
						
							|  |  |  |               placeholder={t('shared-preferences.fields.home-dashboard-placeholder', 'Default dashboard')} | 
					
						
							|  |  |  |               inputId="home-dashboard-select" | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           </Field> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           <Field | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |             loading={isLoading} | 
					
						
							|  |  |  |             disabled={isLoading} | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |             label={t('shared-dashboard.fields.timezone-label', 'Timezone')} | 
					
						
							|  |  |  |             data-testid={selectors.components.TimeZonePicker.containerV2} | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <TimeZonePicker | 
					
						
							|  |  |  |               includeInternal={true} | 
					
						
							|  |  |  |               value={timezone} | 
					
						
							|  |  |  |               onChange={this.onTimeZoneChanged} | 
					
						
							|  |  |  |               inputId="shared-preferences-timezone-picker" | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           </Field> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           <Field | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |             loading={isLoading} | 
					
						
							|  |  |  |             disabled={isLoading} | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |             label={t('shared-preferences.fields.week-start-label', 'Week start')} | 
					
						
							|  |  |  |             data-testid={selectors.components.WeekStartPicker.containerV2} | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <WeekStartPicker | 
					
						
							|  |  |  |               value={weekStart || ''} | 
					
						
							|  |  |  |               onChange={this.onWeekStartChanged} | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |               inputId="shared-preferences-week-start-picker" | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |             /> | 
					
						
							|  |  |  |           </Field> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           <Field | 
					
						
							| 
									
										
										
										
											2024-11-19 23:07:14 +08:00
										 |  |  |             loading={isLoading} | 
					
						
							|  |  |  |             disabled={isLoading} | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |             label={ | 
					
						
							|  |  |  |               <Label htmlFor="locale-select"> | 
					
						
							|  |  |  |                 <span className={styles.labelText}> | 
					
						
							|  |  |  |                   <Trans i18nKey="shared-preferences.fields.locale-label">Language</Trans> | 
					
						
							|  |  |  |                 </span> | 
					
						
							|  |  |  |                 <FeatureBadge featureState={FeatureState.beta} /> | 
					
						
							|  |  |  |               </Label> | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             data-testid="User preferences language drop down" | 
					
						
							|  |  |  |           > | 
					
						
							| 
									
										
										
										
											2024-09-10 22:28:00 +08:00
										 |  |  |             <Combobox | 
					
						
							|  |  |  |               value={languages.find((lang) => lang.value === language)?.value || ''} | 
					
						
							|  |  |  |               onChange={(lang: ComboboxOption | null) => this.onLanguageChanged(lang?.value ?? '')} | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |               options={languages} | 
					
						
							|  |  |  |               placeholder={t('shared-preferences.fields.locale-placeholder', 'Choose language')} | 
					
						
							| 
									
										
										
										
											2024-09-10 22:28:00 +08:00
										 |  |  |               id="locale-select" | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |             /> | 
					
						
							|  |  |  |           </Field> | 
					
						
							|  |  |  |         </FieldSet> | 
					
						
							|  |  |  |         <Button type="submit" variant="primary" data-testid={selectors.components.UserProfile.preferencesSaveButton}> | 
					
						
							|  |  |  |           <Trans i18nKey="common.save">Save</Trans> | 
					
						
							|  |  |  |         </Button> | 
					
						
							|  |  |  |       </form> | 
					
						
							| 
									
										
										
										
											2018-11-15 20:37:29 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default SharedPreferences; | 
					
						
							| 
									
										
										
										
											2020-06-08 23:19:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const getStyles = stylesFactory(() => { | 
					
						
							|  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2024-02-01 01:33:17 +08:00
										 |  |  |     labelText: css({ | 
					
						
							|  |  |  |       marginRight: '6px', | 
					
						
							|  |  |  |     }), | 
					
						
							|  |  |  |     form: css({ | 
					
						
							|  |  |  |       width: '100%', | 
					
						
							|  |  |  |       maxWidth: '600px', | 
					
						
							|  |  |  |     }), | 
					
						
							| 
									
										
										
										
											2020-06-08 23:19:00 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-05-10 21:37:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function getTranslatedThemeName(theme: ThemeRegistryItem) { | 
					
						
							|  |  |  |   switch (theme.id) { | 
					
						
							|  |  |  |     case 'dark': | 
					
						
							|  |  |  |       return t('shared.preferences.theme.dark-label', 'Dark'); | 
					
						
							|  |  |  |     case 'light': | 
					
						
							|  |  |  |       return t('shared.preferences.theme.light-label', 'Light'); | 
					
						
							|  |  |  |     case 'system': | 
					
						
							|  |  |  |       return t('shared.preferences.theme.system-label', 'System preference'); | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       return theme.name; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |