[Unified Search] Hide 'Include time filter' checkbox when Data view has no time field (#131276)

* feat: add hide 'Include time filter' checkbox, if  index pattern has no time field

* feat: added checking DataView exists and has any element

* fix: added a check for the absence of a timeFieldName value for each dataViews

* feat: changed logic for check DataViews have value TimeFieldName

* refactor: shouldRenderTimeFilterInSavedQueryForm

* refact: minor

* refact: minor

* Update src/plugins/unified_search/public/search_bar/search_bar.tsx
This commit is contained in:
Nodir Latipov 2022-05-19 12:40:10 +05:00 committed by GitHub
parent 12509f78c6
commit 1660bd9013
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,8 +10,8 @@ import { compact } from 'lodash';
import { InjectedIntl, injectI18n } from '@kbn/i18n-react';
import classNames from 'classnames';
import React, { Component } from 'react';
import { get, isEqual } from 'lodash';
import { EuiIconProps, withEuiTheme, WithEuiThemeProps } from '@elastic/eui';
import { get, isEqual } from 'lodash';
import memoizeOne from 'memoize-one';
import { METRIC_TYPE } from '@kbn/analytics';
@ -213,11 +213,18 @@ class SearchBarUI extends Component<SearchBarProps & WithEuiThemeProps, State> {
* in case you the date range (from/to)
*/
private shouldRenderTimeFilterInSavedQueryForm() {
const { dateRangeFrom, dateRangeTo, showDatePicker } = this.props;
return (
showDatePicker ||
(!showDatePicker && dateRangeFrom !== undefined && dateRangeTo !== undefined)
);
const { dateRangeFrom, dateRangeTo, showDatePicker, indexPatterns } = this.props;
if (!showDatePicker && dateRangeFrom !== undefined && dateRangeTo !== undefined) {
return false;
}
if (indexPatterns?.length) {
// return true if at least one of the DateView has timeFieldName
return indexPatterns.some((dataView) => Boolean(dataView.timeFieldName));
}
return true;
}
public onSave = async (savedQueryMeta: SavedQueryMeta, saveAsNew = false) => {