diff --git a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimePickerFooter.tsx b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimePickerFooter.tsx index 4802a79a713..467944c0f8f 100644 --- a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimePickerFooter.tsx +++ b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimePickerFooter.tsx @@ -103,6 +103,7 @@ export const TimePickerFooter = (props: Props) => { } }} onBlur={onToggleChangeTimeSettings} + menuShouldPortal={false} /> ) : ( diff --git a/packages/grafana-ui/src/components/DateTimePickers/TimeZonePicker.tsx b/packages/grafana-ui/src/components/DateTimePickers/TimeZonePicker.tsx index 093a2ebde95..03cd1495315 100644 --- a/packages/grafana-ui/src/components/DateTimePickers/TimeZonePicker.tsx +++ b/packages/grafana-ui/src/components/DateTimePickers/TimeZonePicker.tsx @@ -41,7 +41,7 @@ export const TimeZonePicker = (props: Props) => { includeInternal = false, disabled = false, inputId, - menuShouldPortal = false, + menuShouldPortal = true, openMenuOnFocus = true, } = props; const groupedTimeZones = useTimeZones(includeInternal); diff --git a/public/app/core/components/SharedPreferences/SharedPreferences.test.tsx b/public/app/core/components/SharedPreferences/SharedPreferences.test.tsx index 1e692fae541..c2e3cc7c8c8 100644 --- a/public/app/core/components/SharedPreferences/SharedPreferences.test.tsx +++ b/public/app/core/components/SharedPreferences/SharedPreferences.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react'; +import { render, screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import React from 'react'; import { getSelectParent, selectOptionInTest } from 'test/helpers/selectOptionInTest'; @@ -84,6 +84,17 @@ const mockPreferences: UserPreferencesDTO = { language: '', }; +const defaultPreferences: UserPreferencesDTO = { + timezone: '', + weekStart: '', + theme: '', + homeDashboardUID: '', + queryHistory: { + homeTab: '', + }, + language: '', +}; + const mockPrefsPatch = jest.fn(); const mockPrefsUpdate = jest.fn(); const mockPrefsLoad = jest.fn().mockResolvedValue(mockPreferences); @@ -154,7 +165,7 @@ describe('SharedPreferences', () => { expect(weekSelect).toHaveTextContent('Default'); }); - it("saves the user's new preferences", async () => { + it('saves the users new preferences', async () => { await selectOptionInTest(screen.getByLabelText('Interface theme'), 'Dark'); await selectOptionInTest(screen.getByLabelText('Timezone'), 'Australia/Sydney'); await selectOptionInTest(screen.getByLabelText('Week start'), 'Saturday'); @@ -174,24 +185,20 @@ describe('SharedPreferences', () => { }); }); - it("saves the user's default preferences", async () => { + it('saves the users default preferences', async () => { await selectOptionInTest(screen.getByLabelText('Interface theme'), 'Default'); - await selectOptionInTest(screen.getByLabelText('Home Dashboard'), 'Default'); + + // there's no default option in this dropdown - there's a clear selection button + // get the parent container, and find the "select-clear-value" button + const dashboardSelect = screen.getByTestId('User preferences home dashboard drop down'); + await userEvent.click(within(dashboardSelect).getByRole('button', { name: 'select-clear-value' })); + await selectOptionInTest(screen.getByLabelText('Timezone'), 'Default'); await selectOptionInTest(screen.getByLabelText('Week start'), 'Default'); await selectOptionInTest(screen.getByLabelText(/language/i), 'Default'); await userEvent.click(screen.getByText('Save')); - expect(mockPrefsUpdate).toHaveBeenCalledWith({ - timezone: 'browser', - weekStart: '', - theme: '', - homeDashboardUID: 'myDash', - queryHistory: { - homeTab: '', - }, - language: '', - }); + expect(mockPrefsUpdate).toHaveBeenCalledWith(defaultPreferences); }); it('refreshes the page after saving preferences', async () => { diff --git a/public/app/core/components/SharedPreferences/SharedPreferences.tsx b/public/app/core/components/SharedPreferences/SharedPreferences.tsx index 71165a6bd2d..d7113e85888 100644 --- a/public/app/core/components/SharedPreferences/SharedPreferences.tsx +++ b/public/app/core/components/SharedPreferences/SharedPreferences.tsx @@ -108,7 +108,7 @@ export class SharedPreferences extends PureComponent { }; onTimeZoneChanged = (timezone?: string) => { - if (!timezone) { + if (typeof timezone !== 'string') { return; } this.setState({ timezone: timezone }); diff --git a/public/app/plugins/datasource/grafana/components/TimeRegionEditor.tsx b/public/app/plugins/datasource/grafana/components/TimeRegionEditor.tsx index 932609afecb..3fad458f37b 100644 --- a/public/app/plugins/datasource/grafana/components/TimeRegionEditor.tsx +++ b/public/app/plugins/datasource/grafana/components/TimeRegionEditor.tsx @@ -105,7 +105,6 @@ export const TimeRegionEditor = ({ value, onChange }: Props) => { includeInternal={true} onChange={(v) => onTimezoneChange(v)} onBlur={() => setEditing(false)} - menuShouldPortal={true} openMenuOnFocus={false} width={100} autoFocus