From ffb474e5eb9deaf181e40ec5e5c771d5760c7d29 Mon Sep 17 00:00:00 2001 From: DziyanaDzeraviankina Date: Wed, 2 Feb 2022 15:55:23 +0300 Subject: [PATCH] TSVB needs to display better UX message when default index pattern is non-time based --- src/plugins/vis_types/timeseries/common/errors.ts | 10 ++++++++++ .../server/lib/vis_data/get_interval_and_timefield.ts | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/plugins/vis_types/timeseries/common/errors.ts b/src/plugins/vis_types/timeseries/common/errors.ts index 8acb8f201a780..d3836fd0cd2a7 100644 --- a/src/plugins/vis_types/timeseries/common/errors.ts +++ b/src/plugins/vis_types/timeseries/common/errors.ts @@ -58,6 +58,16 @@ export class AggNotSupportedError extends UIError { } } +export class TimeFieldNotSpecifiedError extends UIError { + constructor() { + super( + i18n.translate('visTypeTimeseries.errors.timeFieldNotSpecifiedError', { + defaultMessage: 'Time field is required to visualize the data', + }) + ); + } +} + export const filterCannotBeAppliedErrorMessage = i18n.translate( 'visTypeTimeseries.filterCannotBeAppliedError', { diff --git a/src/plugins/vis_types/timeseries/server/lib/vis_data/get_interval_and_timefield.ts b/src/plugins/vis_types/timeseries/server/lib/vis_data/get_interval_and_timefield.ts index 7c17f003dfbab..af6eb44affabc 100644 --- a/src/plugins/vis_types/timeseries/server/lib/vis_data/get_interval_and_timefield.ts +++ b/src/plugins/vis_types/timeseries/server/lib/vis_data/get_interval_and_timefield.ts @@ -9,6 +9,7 @@ import moment from 'moment'; import { AUTO_INTERVAL } from '../../../common/constants'; import { validateField } from '../../../common/fields_utils'; import { validateInterval } from '../../../common/validate_interval'; +import { TimeFieldNotSpecifiedError } from '../../../common/errors'; import type { FetchedIndexPattern, Panel, Series } from '../../../common/types'; @@ -34,7 +35,11 @@ export function getIntervalAndTimefield( } if (panel.use_kibana_indexes) { - validateField(timeField!, index); + if (timeField) { + validateField(timeField, index); + } else { + throw new TimeFieldNotSpecifiedError(); + } } let interval = panel.interval;