diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_time_range.test.tsx b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_time_range.test.tsx index 38534b1c79e3e..edac44cf22e38 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_time_range.test.tsx +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_time_range.test.tsx @@ -12,7 +12,10 @@ import { renderHook } from '@testing-library/react-hooks'; import { useExpViewTimeRange } from './use_time_range'; import { ReportTypes } from '../configurations/constants'; import { createKbnUrlStateStorage } from '../../../../../../../../src/plugins/kibana_utils/public'; -import { TRANSACTION_DURATION } from '../configurations/constants/elasticsearch_fieldnames'; +import { + TRANSACTION_DURATION, + METRIC_SYSTEM_MEMORY_USAGE, +} from '../configurations/constants/elasticsearch_fieldnames'; const mockSingleSeries = [ { @@ -85,6 +88,31 @@ describe('useExpViewTimeRange', function () { }); }); + it("should correctly parse dates when last series doesn't have a report definition", async function () { + const mockSeriesWithoutDefinitions = [ + ...mockSingleSeries, + { + dataType: 'mobile', + name: 'mobile-series-1', + reportDefinitions: undefined, + selectedMetricField: METRIC_SYSTEM_MEMORY_USAGE, + time: { from: 'now-30m', to: 'now' }, + }, + ]; + + await storage.set(allSeriesKey, mockSeriesWithoutDefinitions); + await storage.set(reportTypeKey, ReportTypes.DISTRIBUTION); + + const { result } = renderHook(() => useExpViewTimeRange(), { + wrapper: Wrapper, + }); + + expect(result.current).toEqual({ + from: 'now-30m', + to: 'now', + }); + }); + it('should return expected result when there are multiple distribution series with absolute dates', async function () { // from:'2021-10-11T09:55:39.551Z',to:'2021-10-11T10:55:41.516Z'))) mockMultipleSeries[0].time.from = '2021-10-11T09:55:39.551Z'; diff --git a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_time_range.ts b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_time_range.ts index 60087cfd0330c..7d6203bef2df8 100644 --- a/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_time_range.ts +++ b/x-pack/plugins/observability/public/components/shared/exploratory_view/hooks/use_time_range.ts @@ -5,7 +5,6 @@ * 2.0. */ -import { isEmpty } from 'lodash'; import { useMemo } from 'react'; import { AllSeries, @@ -31,12 +30,7 @@ export const combineTimeRanges = ( } allSeries.forEach((series) => { - if ( - series.dataType && - series.selectedMetricField && - !isEmpty(series.reportDefinitions) && - series.time - ) { + if (series.dataType && series.selectedMetricField && series.time) { const seriesFrom = parseRelativeDate(series.time.from)!; const seriesTo = parseRelativeDate(series.time.to, { roundUp: true })!;