Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Jan 25, 2022
1 parent 38ef298 commit bddaf04
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class FilterEditorUI extends Component<Props, State> {

private renderParamsEditor() {
const indexPattern = this.state.selectedIndexPattern;
if (!indexPattern || !this.state.selectedOperator) {
if (!indexPattern || !this.state.selectedOperator || !this.state.selectedField) {
return '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { UI_SETTINGS } from '../../../../common';
export interface PhraseSuggestorProps {
kibana: KibanaReactContextValue<IDataPluginServices>;
indexPattern: IIndexPattern;
field?: IFieldType;
field: IFieldType;
timeRangeForSuggestionsOverride?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class PhraseValueInputUI extends PhraseSuggestorUI<Props> {
})}
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}
/>
)}
</EuiFormRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface RangeParams {
type RangeParamsPartial = Partial<RangeParams>;

interface Props {
field?: IFieldType;
field: IFieldType;
value?: RangeParams;
onChange: (params: RangeParamsPartial) => void;
intl: InjectedIntl;
Expand All @@ -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) => {
Expand Down Expand Up @@ -69,8 +68,7 @@ function RangeValueInputUI(props: Props) {
startControl={
<ValueInputType
controlOnly
type={type}
esTypes={props.field?.esTypes}
field={props.field}
value={props.value ? props.value.from : undefined}
onChange={onFromChange}
onBlur={(value) => {
Expand All @@ -85,8 +83,7 @@ function RangeValueInputUI(props: Props) {
endControl={
<ValueInputType
controlOnly
type={type}
esTypes={props.field?.esTypes}
field={props.field}
value={props.value ? props.value.to : undefined}
onChange={onToChange}
onBlur={(value) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,16 +28,17 @@ interface Props {
class ValueInputTypeUI extends Component<Props> {
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 = (
<EuiFieldText
fullWidth={this.props.fullWidth}
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}
/>
Expand Down Expand Up @@ -65,9 +66,7 @@ class ValueInputTypeUI extends Component<Props> {
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}
/>
Expand All @@ -81,9 +80,7 @@ class ValueInputTypeUI extends Component<Props> {
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}
/>
Expand Down

0 comments on commit bddaf04

Please sign in to comment.