From abcb459882a4f535b8d625b43989b80cec31b824 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Tue, 23 Jun 2020 10:52:05 -0600 Subject: [PATCH] tslint --- .../choropleth_layer_wizard.tsx | 1 - .../create_choropleth_layer_descriptor.ts | 7 +-- .../layer_template.tsx | 52 ++++++++++++------- .../ems_file_source/create_source_editor.tsx | 8 +-- .../__snapshots__/scaling_form.test.tsx.snap | 1 + .../es_search_source/scaling_form.test.tsx | 1 + .../sources/es_search_source/scaling_form.tsx | 6 ++- .../public/components/ems_file_select.tsx | 5 +- .../components/geo_index_pattern_select.tsx | 2 +- .../public/components/single_field_select.tsx | 2 +- 10 files changed, 49 insertions(+), 36 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/choropleth_layer_wizard.tsx b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/choropleth_layer_wizard.tsx index fc20f125eb86d0..6e806f4530df25 100644 --- a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/choropleth_layer_wizard.tsx +++ b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/choropleth_layer_wizard.tsx @@ -9,7 +9,6 @@ import { i18n } from '@kbn/i18n'; import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants'; import { LayerWizard, RenderWizardArguments } from '../layer_wizard_registry'; import { LayerTemplate } from './layer_template'; -import { getIndexPatternService } from '../../../kibana_services'; export const choroplethLayerWizardConfig: LayerWizard = { categories: [LAYER_WIZARD_CATEGORY.ELASTICSEARCH], diff --git a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts index ad19cc9c8377f1..bc69b0b5c59d97 100644 --- a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts @@ -14,16 +14,17 @@ import { STYLE_TYPE, VECTOR_STYLES, } from '../../../../common/constants'; -import { getJoinAggKey, getSourceAggKey } from '../../../../common/get_agg_key'; +import { getJoinAggKey } from '../../../../common/get_agg_key'; import { + AggDescriptor, ColorDynamicOptions, EMSFileSourceDescriptor, ESSearchSourceDescriptor, - JoinDescriptor, } from '../../../../common/descriptor_types'; import { VectorStyle } from '../../styles/vector/vector_style'; import { VectorLayer } from '../vector_layer/vector_layer'; import { EMSFileSource } from '../../sources/ems_file_source'; +// @ts-ignore import { ESSearchSource } from '../../sources/es_search_source'; import { getDefaultDynamicProperties } from '../../styles/vector/vector_style_defaults'; @@ -42,7 +43,7 @@ function createChoroplethLayerDescriptor({ rightIndexPatternTitle: string; rightTermField: string; }) { - const metricsDescriptor = { type: AGG_TYPE.COUNT }; + const metricsDescriptor: AggDescriptor = { type: AGG_TYPE.COUNT }; const joinId = uuid(); const joinKey = getJoinAggKey({ aggType: metricsDescriptor.type, diff --git a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/layer_template.tsx b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/layer_template.tsx index 091352bb52173d..c10d0c57832f87 100644 --- a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/layer_template.tsx +++ b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/layer_template.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { Component, Fragment } from 'react'; +import React, { Component } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { FileLayer } from '@elastic/ems-client'; @@ -18,7 +18,7 @@ import { EuiTitle, } from '@elastic/eui'; import { IFieldType, IndexPattern } from 'src/plugins/data/public'; -import { RenderWizardArguments } from '../../layer_wizard_registry'; +import { RenderWizardArguments } from '../layer_wizard_registry'; import { EMSFileSelect } from '../../../components/ems_file_select'; import { GeoIndexPatternSelect } from '../../../components/geo_index_pattern_select'; import { SingleFieldSelect } from '../../../components/single_field_select'; @@ -91,7 +91,7 @@ export class LayerTemplate extends Component { this._isMounted = true; } - _loadRightFields = async (indexPatternId) => { + _loadRightFields = async (indexPatternId: string) => { this.setState({ rightTermsFields: [], rightIndexPatternTitle: null }); let indexPattern; @@ -140,7 +140,7 @@ export class LayerTemplate extends Component { _onLeftSourceChange = (optionId: string) => { this.setState( - { leftSource: optionId, leftJoinField: null, rightJoinField: null }, + { leftSource: optionId as BOUNDARIES_SOURCE, leftJoinField: null, rightJoinField: null }, this._previewLayer ); }; @@ -158,17 +158,24 @@ export class LayerTemplate extends Component { () => { // make default geo field selection if (this.state.leftGeoFields.length) { + // @ts-expect-error - avoid wrong "Property 'name' does not exist on type 'never'." compile error this._onLeftGeoFieldSelect(this.state.leftGeoFields[0].name); } } ); }; - _onLeftGeoFieldSelect = (geoField: string) => { + _onLeftGeoFieldSelect = (geoField?: string) => { + if (!geoField) { + return; + } this.setState({ leftGeoField: geoField }, this._previewLayer); }; - _onLeftJoinFieldSelect = (joinField: string) => { + _onLeftJoinFieldSelect = (joinField?: string) => { + if (!joinField) { + return; + } this.setState({ leftJoinField: joinField }, this._previewLayer); }; @@ -184,7 +191,7 @@ export class LayerTemplate extends Component { return; } - this.setState({ leftJoinField: selectedOptions[0].value }, this._previewLayer); + this.setState({ leftJoinField: selectedOptions[0].value! }, this._previewLayer); }; _onRightIndexPatternChange = (indexPatternId: string) => { @@ -204,7 +211,10 @@ export class LayerTemplate extends Component { ); }; - _onRightJoinFieldSelect = (joinField: string) => { + _onRightJoinFieldSelect = (joinField?: string) => { + if (!joinField) { + return; + } this.setState({ rightJoinField: joinField }, this._previewLayer); }; @@ -231,19 +241,20 @@ export class LayerTemplate extends Component { const layerDescriptor = this.state.leftSource === BOUNDARIES_SOURCE.ELASTICSEARCH ? createEsChoroplethLayerDescriptor({ - leftIndexPatternId: this.state.leftIndexPattern.id, - leftGeoField: this.state.leftGeoField, - leftJoinField: this.state.leftJoinField, - rightIndexPatternId: this.state.rightIndexPatternId, - rightIndexPatternTitle: this.state.rightIndexPatternTitle, - rightTermField: this.state.rightJoinField, + // @ts-expect-error - avoid wrong "Property 'id' does not exist on type 'never'." compile error + leftIndexPatternId: this.state.leftIndexPattern!.id, + leftGeoField: this.state.leftGeoField!, + leftJoinField: this.state.leftJoinField!, + rightIndexPatternId: this.state.rightIndexPatternId!, + rightIndexPatternTitle: this.state.rightIndexPatternTitle!, + rightTermField: this.state.rightJoinField!, }) : createEmsChoroplethLayerDescriptor({ - leftEmsFileId: this.state.leftEmsFileId, - leftEmsField: this.state.leftJoinField, - rightIndexPatternId: this.state.rightIndexPatternId, - rightIndexPatternTitle: this.state.rightIndexPatternTitle, - rightTermField: this.state.rightJoinField, + leftEmsFileId: this.state.leftEmsFileId!, + leftEmsField: this.state.leftJoinField!, + rightIndexPatternId: this.state.rightIndexPatternId!, + rightIndexPatternTitle: this.state.rightIndexPatternTitle!, + rightTermField: this.state.rightJoinField!, }); this.props.previewLayers([layerDescriptor]); @@ -294,7 +305,8 @@ export class LayerTemplate extends Component { return ( <> {geoFieldSelect} diff --git a/x-pack/plugins/maps/public/classes/sources/ems_file_source/create_source_editor.tsx b/x-pack/plugins/maps/public/classes/sources/ems_file_source/create_source_editor.tsx index 841c774479fcee..ef15a8d7866076 100644 --- a/x-pack/plugins/maps/public/classes/sources/ems_file_source/create_source_editor.tsx +++ b/x-pack/plugins/maps/public/classes/sources/ems_file_source/create_source_editor.tsx @@ -5,12 +5,7 @@ */ import React, { Component } from 'react'; -import { EuiComboBox, EuiComboBoxOptionOption, EuiFormRow, EuiPanel } from '@elastic/eui'; - -import { i18n } from '@kbn/i18n'; -import { FileLayer } from '@elastic/ems-client'; -import { getEmsFileLayers } from '../../../meta'; -import { getEmsUnavailableMessage } from '../ems_unavailable_message'; +import { EuiPanel } from '@elastic/eui'; import { EMSFileSourceDescriptor } from '../../../../common/descriptor_types'; import { EMSFileSelect } from '../../../components/ems_file_select'; @@ -28,6 +23,7 @@ export class EMSFileCreateSourceEditor extends Component { }; _onChange = (emsFileId: string) => { + this.setState({ emsFileId }); this.props.onSourceConfigChange({ id: emsFileId }); }; diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/__snapshots__/scaling_form.test.tsx.snap b/x-pack/plugins/maps/public/classes/sources/es_search_source/__snapshots__/scaling_form.test.tsx.snap index 2b04da92517561..956b9a1a663d91 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/__snapshots__/scaling_form.test.tsx.snap +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/__snapshots__/scaling_form.test.tsx.snap @@ -210,6 +210,7 @@ exports[`should render top hits form when scaling type is TOP_HITS 1`] = ` diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/scaling_form.test.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/scaling_form.test.tsx index 3ec746223c7cf3..6e56c179b4ead2 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/scaling_form.test.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/scaling_form.test.tsx @@ -25,6 +25,7 @@ const defaultProps = { scalingType: SCALING_TYPES.LIMIT, supportsClustering: true, termFields: [], + topHitsSplitField: null, topHitsSize: 1, }; diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/scaling_form.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/scaling_form.tsx index a998fe3569835c..816db6a98d593b 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/scaling_form.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/scaling_form.tsx @@ -40,7 +40,7 @@ interface Props { supportsClustering: boolean; clusteringDisabledReason?: string | null; termFields: IFieldType[]; - topHitsSplitField?: string; + topHitsSplitField: string | null; topHitsSize: number; } @@ -90,6 +90,9 @@ export class ScalingForm extends Component { }; _onTopHitsSplitFieldChange = (topHitsSplitField?: string) => { + if (!topHitsSplitField) { + return; + } this.props.onChange({ propName: 'topHitsSplitField', value: topHitsSplitField }); }; @@ -141,6 +144,7 @@ export class ScalingForm extends Component { value={this.props.topHitsSplitField} onChange={this._onTopHitsSplitFieldChange} fields={this.props.termFields} + isClearable={false} compressed /> diff --git a/x-pack/plugins/maps/public/components/ems_file_select.tsx b/x-pack/plugins/maps/public/components/ems_file_select.tsx index c82e06d3b9fd04..f66e813608ce19 100644 --- a/x-pack/plugins/maps/public/components/ems_file_select.tsx +++ b/x-pack/plugins/maps/public/components/ems_file_select.tsx @@ -11,11 +11,10 @@ import { i18n } from '@kbn/i18n'; import { FileLayer } from '@elastic/ems-client'; import { getEmsFileLayers } from '../meta'; import { getEmsUnavailableMessage } from './ems_unavailable_message'; -import { EMSFileSourceDescriptor } from '../../common/descriptor_types'; interface Props { onChange: (emsFileId: string) => void; - value: string; + value: string | null; } interface State { @@ -61,7 +60,7 @@ export class EMSFileSelect extends Component { return; } - this.props.onChange(selectedOptions[0].value); + this.props.onChange(selectedOptions[0].value!); }; _renderSelect() { diff --git a/x-pack/plugins/maps/public/components/geo_index_pattern_select.tsx b/x-pack/plugins/maps/public/components/geo_index_pattern_select.tsx index 2dbb85575f86db..ae23d9d97de86e 100644 --- a/x-pack/plugins/maps/public/components/geo_index_pattern_select.tsx +++ b/x-pack/plugins/maps/public/components/geo_index_pattern_select.tsx @@ -22,7 +22,7 @@ interface Props { } interface State { - noGeoIndexPatternsExist: Array>; + noGeoIndexPatternsExist: boolean; } export class GeoIndexPatternSelect extends Component { diff --git a/x-pack/plugins/maps/public/components/single_field_select.tsx b/x-pack/plugins/maps/public/components/single_field_select.tsx index eb3a28be0efc01..2895479c4fd0e7 100644 --- a/x-pack/plugins/maps/public/components/single_field_select.tsx +++ b/x-pack/plugins/maps/public/components/single_field_select.tsx @@ -49,7 +49,7 @@ type Props = Omit< > & { fields?: IFieldType[]; onChange: (fieldName?: string) => void; - value?: string; // index pattern field name + value: string | null; // index pattern field name isFieldDisabled?: (field: IFieldType) => boolean; getFieldDisabledReason?: (field: IFieldType) => string | null; };