Skip to content

Commit

Permalink
[APM] Disable auto-refresh by default (#74068)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar authored and APM User committed Aug 3, 2020
1 parent 3dde98a commit e7cf68a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,33 @@ describe('DatePicker', () => {
});

beforeEach(() => {
jest.clearAllMocks();
jest.resetAllMocks();
});

it('should set default query params in the URL', () => {
it('sets default query params in the URL', () => {
mountDatePicker();
expect(mockHistoryPush).toHaveBeenCalledTimes(1);
expect(mockHistoryPush).toHaveBeenCalledWith(
expect.objectContaining({
search:
'rangeFrom=now-15m&rangeTo=now&refreshPaused=false&refreshInterval=10000',
search: 'rangeFrom=now-15m&rangeTo=now',
})
);
});

it('should add missing default value', () => {
it('adds missing default value', () => {
mountDatePicker({
rangeTo: 'now',
refreshInterval: 5000,
});
expect(mockHistoryPush).toHaveBeenCalledTimes(1);
expect(mockHistoryPush).toHaveBeenCalledWith(
expect.objectContaining({
search:
'rangeFrom=now-15m&rangeTo=now&refreshInterval=5000&refreshPaused=false',
search: 'rangeFrom=now-15m&rangeTo=now&refreshInterval=5000',
})
);
});

it('should not set default query params in the URL when values already defined', () => {
it('does not set default query params in the URL when values already defined', () => {
mountDatePicker({
rangeFrom: 'now-1d',
rangeTo: 'now',
Expand All @@ -102,7 +100,7 @@ describe('DatePicker', () => {
expect(mockHistoryPush).toHaveBeenCalledTimes(0);
});

it('should update the URL when the date range changes', () => {
it('updates the URL when the date range changes', () => {
const datePicker = mountDatePicker();
datePicker.find(EuiSuperDatePicker).props().onTimeChange({
start: 'updated-start',
Expand All @@ -113,13 +111,12 @@ describe('DatePicker', () => {
expect(mockHistoryPush).toHaveBeenCalledTimes(2);
expect(mockHistoryPush).toHaveBeenLastCalledWith(
expect.objectContaining({
search:
'rangeFrom=updated-start&rangeTo=updated-end&refreshInterval=5000&refreshPaused=false',
search: 'rangeFrom=updated-start&rangeTo=updated-end',
})
);
});

it('should auto-refresh when refreshPaused is false', async () => {
it('enables auto-refresh when refreshPaused is false', async () => {
jest.useFakeTimers();
const wrapper = mountDatePicker({
refreshPaused: false,
Expand All @@ -132,7 +129,7 @@ describe('DatePicker', () => {
wrapper.unmount();
});

it('should NOT auto-refresh when refreshPaused is true', async () => {
it('disables auto-refresh when refreshPaused is true', async () => {
jest.useFakeTimers();
mountDatePicker({ refreshPaused: true, refreshInterval: 1000 });
expect(mockRefreshTimeRange).not.toHaveBeenCalled();
Expand Down
16 changes: 1 addition & 15 deletions x-pack/plugins/apm/public/components/shared/DatePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import { useUrlParams } from '../../../hooks/useUrlParams';
import { clearCache } from '../../../services/rest/callApi';
import { useApmPluginContext } from '../../../hooks/useApmPluginContext';
import { UI_SETTINGS } from '../../../../../../../src/plugins/data/common';
import {
TimePickerQuickRange,
TimePickerTimeDefaults,
TimePickerRefreshInterval,
} from './typings';
import { TimePickerQuickRange, TimePickerTimeDefaults } from './typings';

function removeUndefinedAndEmptyProps<T extends object>(obj: T): Partial<T> {
return pickBy(obj, (value) => value !== undefined && !isEmpty(String(value)));
Expand All @@ -36,19 +32,9 @@ export function DatePicker() {
UI_SETTINGS.TIMEPICKER_TIME_DEFAULTS
);

const timePickerRefreshIntervalDefaults = core.uiSettings.get<
TimePickerRefreshInterval
>(UI_SETTINGS.TIMEPICKER_REFRESH_INTERVAL_DEFAULTS);

const DEFAULT_VALUES = {
rangeFrom: timePickerTimeDefaults.from,
rangeTo: timePickerTimeDefaults.to,
refreshPaused: timePickerRefreshIntervalDefaults.pause,
/*
* Must be replaced by timePickerRefreshIntervalDefaults.value when this issue is fixed.
* https://github.com/elastic/kibana/issues/70562
*/
refreshInterval: 10000,
};

const commonlyUsedRanges = timePickerQuickRanges.map(
Expand Down

0 comments on commit e7cf68a

Please sign in to comment.