Skip to content

Commit

Permalink
[Synthetics] Fix default date range on errors page (elastic#155661)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored and nikitaindik committed Apr 25, 2023
1 parent ea75de4 commit 2fd0b4d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ describe('SyntheticsDatePicker component', () => {
expect(await findByText('Refresh')).toBeInTheDocument();
});

it('uses shared date range state when there is no url date range state', async () => {
const customHistory = createMemoryHistory({
initialEntries: ['/?dateRangeStart=now-24h&dateRangeEnd=now'],
});

jest.spyOn(customHistory, 'push');

const { findByText } = render(<SyntheticsDatePicker />, {
history: customHistory,
core: startPlugins,
});

expect(await findByText('~ 30 minutes ago')).toBeInTheDocument();

expect(customHistory.push).toHaveBeenCalledWith({
pathname: '/',
search: 'dateRangeEnd=now-15m&dateRangeStart=now-30m',
});
});

it('should use url date range even if shared date range is present', async () => {
const customHistory = createMemoryHistory({
initialEntries: ['/?g=%22%22&dateRangeStart=now-10m&dateRangeEnd=now'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import React, { useContext, useEffect } from 'react';
import { EuiSuperDatePicker } from '@elastic/eui';
import { CLIENT_DEFAULTS_SYNTHETICS } from '../../../../../../common/constants/synthetics/client_defaults';
import { useUrlParams } from '../../../hooks';
import { CLIENT_DEFAULTS } from '../../../../../../common/constants';
import {
Expand All @@ -16,12 +15,6 @@ import {
SyntheticsRefreshContext,
} from '../../../contexts';

const isSyntheticsDefaultDateRange = (dateRangeStart: string, dateRangeEnd: string) => {
const { DATE_RANGE_START, DATE_RANGE_END } = CLIENT_DEFAULTS_SYNTHETICS;

return dateRangeStart === DATE_RANGE_START && dateRangeEnd === DATE_RANGE_END;
};

export const SyntheticsDatePicker = ({ fullWidth }: { fullWidth?: boolean }) => {
const [getUrlParams, updateUrl] = useUrlParams();
const { commonlyUsedRanges } = useContext(SyntheticsSettingsContext);
Expand All @@ -36,10 +29,7 @@ export const SyntheticsDatePicker = ({ fullWidth }: { fullWidth?: boolean }) =>

useEffect(() => {
const { from, to } = sharedTimeState ?? {};
// if it's synthetics default range, and we have shared state from kibana, let's use that
if (isSyntheticsDefaultDateRange(start, end) && (from !== start || to !== end)) {
updateUrl({ dateRangeStart: from, dateRangeEnd: to });
} else if (from !== start || to !== end) {
if (from !== start || to !== end) {
// if it's coming url. let's update shared state
data?.query.timefilter.timefilter.setTime({ from: start, to: end });
}
Expand Down

0 comments on commit 2fd0b4d

Please sign in to comment.