mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[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:
parent
07cacbe799
commit
c47a7c80f3
2 changed files with 19 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue