diff --git a/public/app/core/components/SharedPreferences/SharedPreferences.test.tsx b/public/app/core/components/SharedPreferences/SharedPreferences.test.tsx index d2a02b59252..aa6a1217338 100644 --- a/public/app/core/components/SharedPreferences/SharedPreferences.test.tsx +++ b/public/app/core/components/SharedPreferences/SharedPreferences.test.tsx @@ -93,8 +93,8 @@ const defaultPreferences: UserPreferencesDTO = { language: '', }; -const mockPrefsPatch = jest.fn(); -const mockPrefsUpdate = jest.fn(); +const mockPrefsPatch = jest.fn().mockResolvedValue(undefined); +const mockPrefsUpdate = jest.fn().mockResolvedValue(undefined); const mockPrefsLoad = jest.fn().mockResolvedValue(mockPreferences); jest.mock('app/core/services/PreferencesService', () => ({ @@ -129,9 +129,6 @@ describe('SharedPreferences', () => { }); beforeEach(async () => { - mockReload.mockReset(); - mockPrefsUpdate.mockReset(); - render(); await waitFor(() => expect(mockPrefsLoad).toHaveBeenCalled()); diff --git a/public/app/core/components/SharedPreferences/SharedPreferences.tsx b/public/app/core/components/SharedPreferences/SharedPreferences.tsx index a600b05adad..c03db158aa3 100644 --- a/public/app/core/components/SharedPreferences/SharedPreferences.tsx +++ b/public/app/core/components/SharedPreferences/SharedPreferences.tsx @@ -40,6 +40,7 @@ export interface Props { export type State = UserPreferencesDTO & { isLoading: boolean; + isSubmitting: boolean; }; function getLanguageOptions(): ComboboxOption[] { const languageOptions = LANGUAGES.map((v) => ({ @@ -98,6 +99,7 @@ export class SharedPreferences extends PureComponent { this.service = new PreferencesService(props.resourceUri); this.state = { isLoading: false, + isSubmitting: false, theme: '', timezone: '', weekStart: '', @@ -153,16 +155,21 @@ export class SharedPreferences extends PureComponent { theme, language, }); - await this.service.update({ - homeDashboardUID, - theme, - timezone, - weekStart, - language, - locale, - queryHistory, - navbar, - }); + this.setState({ isSubmitting: true }); + await this.service + .update({ + homeDashboardUID, + theme, + timezone, + weekStart, + language, + locale, + queryHistory, + navbar, + }) + .finally(() => { + this.setState({ isSubmitting: false }); + }); window.location.reload(); } }; @@ -213,7 +220,7 @@ export class SharedPreferences extends PureComponent { }; render() { - const { theme, timezone, weekStart, homeDashboardUID, language, isLoading, locale } = this.state; + const { theme, timezone, weekStart, homeDashboardUID, language, isLoading, isSubmitting, locale } = this.state; const { disabled } = this.props; const styles = getStyles(); const currentThemeOption = this.themeOptions.find((x) => x.value === theme) ?? this.themeOptions[0]; @@ -346,7 +353,12 @@ export class SharedPreferences extends PureComponent { )} -