Skip to content

Commit

Permalink
fix: parse time range for series that don't have a report definition …
Browse files Browse the repository at this point in the history
…yet (#121671)
  • Loading branch information
lucasfcosta authored and kibanamachine committed Dec 22, 2021
1 parent eb02877 commit b5e9df0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { isEmpty } from 'lodash';
import { useMemo } from 'react';
import {
AllSeries,
Expand All @@ -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 })!;

Expand Down

0 comments on commit b5e9df0

Please sign in to comment.