Skip to content

Commit

Permalink
type check
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Sep 14, 2020
1 parent c70e99c commit 4d45113
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/public/classes/fields/es_agg_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import { IndexPattern } from 'src/plugins/data/public';
import { IField, getMbPropertyName } from './field';
import { IField } from './field';
import { AggDescriptor } from '../../../common/descriptor_types';
import { IESAggSource } from '../sources/es_agg_source';
import { IVectorSource } from '../sources/vector_source';
import { ESDocField } from './es_doc_field';
import { AGG_TYPE, FIELD_ORIGIN, VECTOR_STYLES } from '../../../common/constants';
import { AGG_TYPE, FIELD_ORIGIN } from '../../../common/constants';
import { isMetricCountable } from '../util/is_metric_countable';
import { getField, addFieldToDSL } from '../util/es_agg_utils';
import { TopTermPercentageField } from './top_term_percentage_field';
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/maps/public/classes/fields/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { FIELD_ORIGIN, VECTOR_STYLES } from '../../../common/constants';
import { FIELD_ORIGIN } from '../../../common/constants';
import { IVectorSource } from '../sources/vector_source';
import { ITooltipProperty, TooltipProperty } from '../tooltips/tooltip_property';
import { getComputedFieldName } from '../styles/vector/style_util';

export interface IField {
getName(): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/

import { IESAggField } from './es_agg_field';
import { getMbPropertyName } from './field';
import { IVectorSource } from '../sources/vector_source';
// @ts-ignore
import { ITooltipProperty, TooltipProperty } from '../tooltips/tooltip_property';
import { TOP_TERM_PERCENTAGE_SUFFIX, VECTOR_STYLES } from '../../../common/constants';
import { TOP_TERM_PERCENTAGE_SUFFIX } from '../../../common/constants';
import { FIELD_ORIGIN } from '../../../common/constants';

export class TopTermPercentageField implements IESAggField {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export class DynamicOrientationProperty extends DynamicStyleProperty<Orientation
}
}

supportsMbFeatureState() {
supportsMbFeatureState(): boolean {
return false;
}

getMbPropertyValue(rawValue) {
getMbPropertyValue(
rawValue: string | number | null | undefined
): string | number | null | undefined {
return getNumericalMbFeatureStateValue(rawValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ export class DynamicStyleProperty<T>
};
}

formatField(value: string | number | undefined): string | number {
formatField(value: string | number | undefined | null): string | number {
if (this.getField()) {
const fieldName = this.getFieldName();
const fieldFormatter = this._getFieldFormatter(fieldName);
return fieldFormatter ? fieldFormatter(value) : super.formatField(value);
return fieldFormatter && value !== null ? fieldFormatter(value) : super.formatField(value);
} else {
return super.formatField(value);
}
Expand Down Expand Up @@ -388,7 +388,11 @@ export class DynamicStyleProperty<T>
}
}

export function getNumericalMbFeatureStateValue(value: string | number) {
export function getNumericalMbFeatureStateValue(value: string | number | null | undefined) {
if (typeof value !== 'string') {
return value;
}

const valueAsFloat = parseFloat(value);
return isNaN(valueAsFloat) ? null : valueAsFloat;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class DynamicTextProperty extends DynamicStyleProperty<LabelDynamicOption
return false;
}

getMbPropertyValue(rawValue) {
getMbPropertyValue(
rawValue: string | number | null | undefined
): string | number | null | undefined {
return this.formatField(rawValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type LegendProps = {
export interface IStyleProperty<T> {
isDynamic(): boolean;
isComplete(): boolean;
formatField(value: string | number | undefined): string | number;
formatField(value: string | number | undefined | null): string | number;
getStyleName(): VECTOR_STYLES;
getOptions(): T;
renderLegendDetailRow(legendProps: LegendProps): ReactElement<any> | null;
Expand Down Expand Up @@ -53,9 +53,8 @@ export class AbstractStyleProperty<T> implements IStyleProperty<T> {
return true;
}

formatField(value: string | number | undefined): string | number {
// eslint-disable-next-line eqeqeq
return value == undefined ? '' : value;
formatField(value: string | number | undefined | null): string | number {
return typeof value === 'undefined' || value === null ? '' : value;
}

getStyleName(): VECTOR_STYLES {
Expand Down

0 comments on commit 4d45113

Please sign in to comment.