Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Synthetics] Fix default date range on errors page #155661

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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