[ML] Add error toast to Data visualizer when using unpopulated time field (#127196)

* Add error toast when using unpopulated time field

* [ML] Fix toast message to warning

* [ML] Fix translation

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Quynh Nguyen 2022-03-18 14:53:59 -05:00 committed by GitHub
parent 07cacbe799
commit c47a7c80f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 7 deletions

View file

@ -63,7 +63,7 @@ export const FullTimeRangeSelector: FC<Props> = ({
const setRange = useCallback(
async (i: DataView, q?: QueryDslQueryContainer, excludeFrozenData?: boolean) => {
try {
const fullTimeRange = await setFullTimeRange(timefilter, i, q, excludeFrozenData);
const fullTimeRange = await setFullTimeRange(timefilter, i, q, excludeFrozenData, toasts);
if (typeof callback === 'function') {
callback(fullTimeRange);
}

View file

@ -9,10 +9,12 @@ import moment from 'moment';
import { TimefilterContract } from 'src/plugins/data/public';
import dateMath from '@elastic/datemath';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { i18n } from '@kbn/i18n';
import type { ToastsStart } from 'kibana/public';
import { DataView } from '../../../../../../../../src/plugins/data_views/public';
import { isPopulatedObject } from '../../../../../common/utils/object_utils';
import { getTimeFieldRange } from '../../services/time_field_range';
import { GetTimeFieldRangeResponse } from '../../../../../common/types/time_field_request';
import type { GetTimeFieldRangeResponse } from '../../../../../common/types/time_field_request';
import { addExcludeFrozenToQuery } from '../../utils/query_utils';
export interface TimeRange {
@ -24,7 +26,8 @@ export async function setFullTimeRange(
timefilter: TimefilterContract,
dataView: DataView,
query?: QueryDslQueryContainer,
excludeFrozenData?: boolean
excludeFrozenData?: boolean,
toasts?: ToastsStart
): Promise<GetTimeFieldRangeResponse> {
const runtimeMappings = dataView.getRuntimeMappings();
const resp = await getTimeFieldRange({
@ -33,10 +36,19 @@ export async function setFullTimeRange(
query: excludeFrozenData ? addExcludeFrozenToQuery(query) : query,
...(isPopulatedObject(runtimeMappings) ? { runtimeMappings } : {}),
});
timefilter.setTime({
from: moment(resp.start.epoch).toISOString(),
to: moment(resp.end.epoch).toISOString(),
});
if (resp.start.epoch && resp.end.epoch) {
timefilter.setTime({
from: moment(resp.start.epoch).toISOString(),
to: moment(resp.end.epoch).toISOString(),
});
} else {
toasts?.addWarning({
title: i18n.translate('xpack.dataVisualizer.index.fullTimeRangeSelector.noResults', {
defaultMessage: 'No results match your search criteria',
}),
});
}
return resp;
}