From bddaf04efab32c38a8313666d55101f08fa5aed7 Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Tue, 25 Jan 2022 17:52:54 +0100 Subject: [PATCH] wip --- .../ui/filter_bar/filter_editor/index.tsx | 2 +- .../filter_editor/lib/filter_editor_utils.ts | 14 +++++++------- .../filter_editor/phrase_suggestor.tsx | 2 +- .../filter_editor/phrase_value_input.tsx | 3 +-- .../filter_editor/range_value_input.tsx | 9 +++------ .../filter_editor/value_input_type.tsx | 17 +++++++---------- 6 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/index.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/index.tsx index 726a4bf29a43c..35ac8f386946e 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/index.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/index.tsx @@ -345,7 +345,7 @@ class FilterEditorUI extends Component { private renderParamsEditor() { const indexPattern = this.state.selectedIndexPattern; - if (!indexPattern || !this.state.selectedOperator) { + if (!indexPattern || !this.state.selectedOperator || !this.state.selectedField) { return ''; } diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts index 9be3f155e285b..7d433bb1f273b 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts @@ -35,8 +35,8 @@ export function getOperatorOptions(field: IFieldType) { }); } -export function validateParams(params: any, type: string, esTypes?: string[]) { - switch (type) { +export function validateParams(params: any, field: IFieldType) { + switch (field.type) { case 'date': const moment = typeof params === 'string' ? dateMath.parse(params) : null; return Boolean(typeof params === 'string' && moment && moment.isValid()); @@ -47,7 +47,7 @@ export function validateParams(params: any, type: string, esTypes?: string[]) { return false; } case 'string': - if (esTypes?.includes(ES_FIELD_TYPES.VERSION)) { + if (field.esTypes?.includes(ES_FIELD_TYPES.VERSION)) { return isSemverValid(params); } return true; @@ -67,19 +67,19 @@ export function isFilterValid( } switch (operator.type) { case 'phrase': - return validateParams(params, field.type); + return validateParams(params, field); case 'phrases': if (!Array.isArray(params) || !params.length) { return false; } - return params.every((phrase) => validateParams(phrase, field.type, field.esTypes)); + return params.every((phrase) => validateParams(phrase, field)); case 'range': if (typeof params !== 'object') { return false; } return ( - (!params.from || validateParams(params.from, field.type, field.esTypes)) && - (!params.to || validateParams(params.to, field.type, field.esTypes)) + (!params.from || validateParams(params.from, field)) && + (!params.to || validateParams(params.to, field)) ); case 'exists': return true; diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx index fb3106e6a8f06..2dff5acedb24a 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx @@ -16,7 +16,7 @@ import { UI_SETTINGS } from '../../../../common'; export interface PhraseSuggestorProps { kibana: KibanaReactContextValue; indexPattern: IIndexPattern; - field?: IFieldType; + field: IFieldType; timeRangeForSuggestionsOverride?: boolean; } diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_value_input.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_value_input.tsx index ecb3aef12e0ab..32a713361dbd1 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_value_input.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_value_input.tsx @@ -43,8 +43,7 @@ class PhraseValueInputUI extends PhraseSuggestorUI { })} value={this.props.value} onChange={this.props.onChange} - type={this.props.field ? this.props.field.type : 'string'} - esTypes={this.props.field?.esTypes} + field={this.props.field} /> )} diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/range_value_input.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/range_value_input.tsx index 6febf3d35f7d0..6561761dc623b 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/range_value_input.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/range_value_input.tsx @@ -23,7 +23,7 @@ interface RangeParams { type RangeParamsPartial = Partial; interface Props { - field?: IFieldType; + field: IFieldType; value?: RangeParams; onChange: (params: RangeParamsPartial) => void; intl: InjectedIntl; @@ -32,7 +32,6 @@ interface Props { function RangeValueInputUI(props: Props) { const kibana = useKibana(); - const type = props.field ? props.field.type : 'string'; const tzConfig = kibana.services.uiSettings!.get('dateFormat:tz'); const formatDateChange = (value: string | number | boolean) => { @@ -69,8 +68,7 @@ function RangeValueInputUI(props: Props) { startControl={ { @@ -85,8 +83,7 @@ function RangeValueInputUI(props: Props) { endControl={ { diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/value_input_type.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/value_input_type.tsx index c896eb8c7aeb3..9b00c71472f37 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/value_input_type.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/value_input_type.tsx @@ -11,11 +11,11 @@ import { InjectedIntl, injectI18n } from '@kbn/i18n-react'; import { isEmpty } from 'lodash'; import React, { Component } from 'react'; import { validateParams } from './lib/filter_editor_utils'; +import { IFieldType } from '../../../../../data_views/common'; interface Props { value?: string | number; - type: string; - esTypes?: string[]; + field: IFieldType; onChange: (value: string | number | boolean) => void; onBlur?: (value: string | number | boolean) => void; placeholder: string; @@ -28,8 +28,9 @@ interface Props { class ValueInputTypeUI extends Component { public render() { const value = this.props.value; + const type = this.props.field.type; let inputElement: React.ReactNode; - switch (this.props.type) { + switch (type) { case 'string': inputElement = ( { placeholder={this.props.placeholder} value={value} onChange={this.onChange} - isInvalid={!validateParams(value, this.props.type, this.props.esTypes)} + isInvalid={!validateParams(value, this.props.field)} controlOnly={this.props.controlOnly} className={this.props.className} /> @@ -65,9 +66,7 @@ class ValueInputTypeUI extends Component { value={value} onChange={this.onChange} onBlur={this.onBlur} - isInvalid={ - !isEmpty(value) && !validateParams(value, this.props.type, this.props.esTypes) - } + isInvalid={!isEmpty(value) && !validateParams(value, this.props.field)} controlOnly={this.props.controlOnly} className={this.props.className} /> @@ -81,9 +80,7 @@ class ValueInputTypeUI extends Component { placeholder={this.props.placeholder} value={value} onChange={this.onChange} - isInvalid={ - !isEmpty(value) && !validateParams(value, this.props.type, this.props.esTypes) - } + isInvalid={!isEmpty(value) && !validateParams(value, this.props.field)} controlOnly={this.props.controlOnly} className={this.props.className} />