mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Synthetics] Fix default date range on errors page (#155661)
This commit is contained in:
parent
8d8c2aab81
commit
1ae38df15d
2 changed files with 1 additions and 31 deletions
|
@ -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'],
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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 });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue