From d4da64a6724b5c8553063e1a825ef2bab3a4fb96 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 16 Sep 2021 09:50:10 -0600 Subject: [PATCH] [Maps] remove VectorSourceSyncMeta type (#112333) * [Maps] remove VectorSourceSyncMeta type * add comment to getSyncMeta * document join.getSyncMeta Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../data_request_descriptor_types.ts | 32 +------------------ .../es_geo_grid_source/es_geo_grid_source.tsx | 5 +-- .../es_geo_line_source/es_geo_line_source.tsx | 4 ++- .../es_search_source/es_search_source.tsx | 13 ++++++-- .../sources/es_term_source/es_term_source.ts | 7 ++-- .../mvt_single_layer_vector_source.tsx | 3 +- .../sources/table_source/table_source.test.ts | 13 ++------ .../sources/table_source/table_source.ts | 14 ++------ .../term_join_source/term_join_source.ts | 13 +++++--- .../sources/vector_source/vector_source.tsx | 11 +++++-- .../toc_entry_actions_popover.tsx | 9 ++---- 11 files changed, 47 insertions(+), 77 deletions(-) diff --git a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts index f2c13a81045ee..2412dd12199a3 100644 --- a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts +++ b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts @@ -8,11 +8,8 @@ /* eslint-disable @typescript-eslint/consistent-type-definitions */ import type { Query } from 'src/plugins/data/common'; -import { SortDirection } from 'src/plugins/data/common/search'; -import { RENDER_AS, SCALING_TYPES } from '../constants'; import { MapExtent } from './map_descriptor'; import { Filter, TimeRange } from '../../../../../src/plugins/data/common'; -import { ESTermSourceDescriptor } from './source_descriptor_types'; export type Timeslice = { from: number; @@ -32,33 +29,6 @@ export type DataFilters = { isReadOnly: boolean; }; -export type ESSearchSourceSyncMeta = { - filterByMapBounds: boolean; - sortField: string; - sortOrder: SortDirection; - scalingType: SCALING_TYPES; - topHitsSplitField: string; - topHitsSize: number; -}; - -type ESGeoGridSourceSyncMeta = { - requestType: RENDER_AS; -}; - -type ESGeoLineSourceSyncMeta = { - splitField: string; - sortField: string; -}; - -export type ESTermSourceSyncMeta = Pick; - -export type VectorSourceSyncMeta = - | ESSearchSourceSyncMeta - | ESGeoGridSourceSyncMeta - | ESGeoLineSourceSyncMeta - | ESTermSourceSyncMeta - | null; - export type VectorSourceRequestMeta = DataFilters & { applyGlobalQuery: boolean; applyGlobalTime: boolean; @@ -67,7 +37,7 @@ export type VectorSourceRequestMeta = DataFilters & { geogridPrecision?: number; timesliceMaskField?: string; sourceQuery?: Query; - sourceMeta: VectorSourceSyncMeta; + sourceMeta: object | null; isForceRefresh: boolean; }; diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx index e65e6ff4c463b..8a02066343914 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx @@ -45,7 +45,6 @@ import { ESGeoGridSourceDescriptor, MapExtent, VectorSourceRequestMeta, - VectorSourceSyncMeta, } from '../../../../common/descriptor_types'; import { ImmutableSourceProperty, SourceEditorArgs } from '../source'; import { ISearchSource } from '../../../../../../../src/plugins/data/common/search/search_source'; @@ -54,6 +53,8 @@ import { Adapters } from '../../../../../../../src/plugins/inspector/common/adap import { isValidStringConfig } from '../../util/valid_string_config'; import { ITiledSingleLayerMvtParams } from '../tiled_single_layer_vector_source/tiled_single_layer_vector_source'; +type ESGeoGridSourceSyncMeta = Pick; + export const MAX_GEOTILE_LEVEL = 29; export const clustersTitle = i18n.translate('xpack.maps.source.esGridClustersTitle', { @@ -106,7 +107,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements ITiledSingle ); } - getSyncMeta(): VectorSourceSyncMeta { + getSyncMeta(): ESGeoGridSourceSyncMeta { return { requestType: this._descriptor.requestType, }; diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx index 4755781147e5b..c9f99be886990 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx @@ -40,6 +40,8 @@ import { esFilters } from '../../../../../../../src/plugins/data/public'; import { getIsGoldPlus } from '../../../licensed_features'; import { LICENSED_FEATURES } from '../../../licensed_features'; +type ESGeoLineSourceSyncMeta = Pick; + const MAX_TRACKS = 250; export const geoLineTitle = i18n.translate('xpack.maps.source.esGeoLineTitle', { @@ -99,7 +101,7 @@ export class ESGeoLineSource extends AbstractESAggSource { ); } - getSyncMeta() { + getSyncMeta(): ESGeoLineSourceSyncMeta { return { splitField: this._descriptor.splitField, sortField: this._descriptor.sortField, diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx index 2b847d218434d..0b15e2a2e5399 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx @@ -52,7 +52,6 @@ import { ESSearchSourceDescriptor, Timeslice, VectorSourceRequestMeta, - VectorSourceSyncMeta, } from '../../../../common/descriptor_types'; import { Adapters } from '../../../../../../../src/plugins/inspector/common/adapters'; import { TimeRange } from '../../../../../../../src/plugins/data/common'; @@ -74,6 +73,16 @@ import { getMatchingIndexes, } from './util/feature_edit'; +type ESSearchSourceSyncMeta = Pick< + ESSearchSourceDescriptor, + | 'filterByMapBounds' + | 'sortField' + | 'sortOrder' + | 'scalingType' + | 'topHitsSplitField' + | 'topHitsSize' +>; + export function timerangeToTimeextent(timerange: TimeRange): Timeslice | undefined { const timeRangeBounds = getTimeFilter().calculateBounds(timerange); return timeRangeBounds.min !== undefined && timeRangeBounds.max !== undefined @@ -714,7 +723,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye }; } - getSyncMeta(): VectorSourceSyncMeta | null { + getSyncMeta(): ESSearchSourceSyncMeta { return { filterByMapBounds: this._descriptor.filterByMapBounds, sortField: this._descriptor.sortField, diff --git a/x-pack/plugins/maps/public/classes/sources/es_term_source/es_term_source.ts b/x-pack/plugins/maps/public/classes/sources/es_term_source/es_term_source.ts index 93342d1167aeb..f7fc863eabb4a 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_term_source/es_term_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_term_source/es_term_source.ts @@ -25,18 +25,19 @@ import { } from '../../../../common/elasticsearch_util'; import { ESTermSourceDescriptor, - ESTermSourceSyncMeta, VectorJoinSourceRequestMeta, } from '../../../../common/descriptor_types'; import { Adapters } from '../../../../../../../src/plugins/inspector/common/adapters'; import { PropertiesMap } from '../../../../common/elasticsearch_util'; import { isValidStringConfig } from '../../util/valid_string_config'; -import { ITermJoinSource } from '../term_join_source/term_join_source'; +import { ITermJoinSource } from '../term_join_source'; import { IField } from '../../fields/field'; const TERMS_AGG_NAME = 'join'; const TERMS_BUCKET_KEYS_TO_IGNORE = ['key', 'doc_count']; +type ESTermSourceSyncMeta = Pick; + export function extractPropertiesMap(rawEsData: any, countPropertyName: string): PropertiesMap { const propertiesMap: PropertiesMap = new Map(); const buckets: any[] = _.get(rawEsData, ['aggregations', TERMS_AGG_NAME, 'buckets'], []); @@ -171,7 +172,7 @@ export class ESTermSource extends AbstractESAggSource implements ITermJoinSource return this.getMetricFields().map((esAggMetricField) => esAggMetricField.getName()); } - getSyncMeta(): ESTermSourceSyncMeta | null { + getSyncMeta(): ESTermSourceSyncMeta { return { indexPatternId: this._descriptor.indexPatternId, size: this._descriptor.size, diff --git a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx index d041e0d3ad5de..8a25fca6292cc 100644 --- a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx @@ -25,7 +25,6 @@ import { MapExtent, MVTFieldDescriptor, TiledSingleLayerVectorSourceDescriptor, - VectorSourceSyncMeta, } from '../../../../common/descriptor_types'; import { MVTField } from '../../fields/mvt_field'; import { UpdateSourceEditor } from './update_source_editor'; @@ -196,7 +195,7 @@ export class MVTSingleLayerVectorSource return null; } - getSyncMeta(): VectorSourceSyncMeta { + getSyncMeta(): null { return null; } diff --git a/x-pack/plugins/maps/public/classes/sources/table_source/table_source.test.ts b/x-pack/plugins/maps/public/classes/sources/table_source/table_source.test.ts index 62404cbe942e3..03476e30e7e41 100644 --- a/x-pack/plugins/maps/public/classes/sources/table_source/table_source.test.ts +++ b/x-pack/plugins/maps/public/classes/sources/table_source/table_source.test.ts @@ -5,13 +5,11 @@ * 2.0. */ -import type { Query } from 'src/plugins/data/common'; import { TableSource } from './table_source'; import { FIELD_ORIGIN } from '../../../../common/constants'; import { - DataFilters, VectorJoinSourceRequestMeta, - VectorSourceSyncMeta, + VectorSourceRequestMeta, } from '../../../../common/descriptor_types'; describe('TableSource', () => { @@ -178,14 +176,7 @@ describe('TableSource', () => { try { await tableSource.getGeoJsonWithMeta( 'foobar', - ({} as unknown) as DataFilters & { - applyGlobalQuery: boolean; - applyGlobalTime: boolean; - fieldNames: string[]; - geogridPrecision?: number; - sourceQuery?: Query; - sourceMeta: VectorSourceSyncMeta; - }, + ({} as unknown) as VectorSourceRequestMeta, () => {}, () => { return false; diff --git a/x-pack/plugins/maps/public/classes/sources/table_source/table_source.ts b/x-pack/plugins/maps/public/classes/sources/table_source/table_source.ts index 8730ea7e3d02b..bb2b670ae9249 100644 --- a/x-pack/plugins/maps/public/classes/sources/table_source/table_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/table_source/table_source.ts @@ -10,10 +10,9 @@ import type { Query } from 'src/plugins/data/common'; import { FIELD_ORIGIN, SOURCE_TYPES, VECTOR_SHAPE_TYPE } from '../../../../common/constants'; import { MapExtent, - DataFilters, TableSourceDescriptor, VectorJoinSourceRequestMeta, - VectorSourceSyncMeta, + VectorSourceRequestMeta, } from '../../../../common/descriptor_types'; import { Adapters } from '../../../../../../../src/plugins/inspector/common/adapters'; import { ITermJoinSource } from '../term_join_source'; @@ -55,7 +54,7 @@ export class TableSource extends AbstractVectorSource implements ITermJoinSource return `table source ${uuid()}`; } - getSyncMeta(): VectorSourceSyncMeta | null { + getSyncMeta(): null { return null; } @@ -186,14 +185,7 @@ export class TableSource extends AbstractVectorSource implements ITermJoinSource // Could be useful to implement, e.g. to preview raw csv data async getGeoJsonWithMeta( layerName: string, - searchFilters: DataFilters & { - applyGlobalQuery: boolean; - applyGlobalTime: boolean; - fieldNames: string[]; - geogridPrecision?: number; - sourceQuery?: Query; - sourceMeta: VectorSourceSyncMeta; - }, + searchFilters: VectorSourceRequestMeta, registerCancelCallback: (callback: () => void) => void, isRequestStillActive: () => boolean ): Promise { diff --git a/x-pack/plugins/maps/public/classes/sources/term_join_source/term_join_source.ts b/x-pack/plugins/maps/public/classes/sources/term_join_source/term_join_source.ts index b9cd572cd8a19..8cf1a631bf223 100644 --- a/x-pack/plugins/maps/public/classes/sources/term_join_source/term_join_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/term_join_source/term_join_source.ts @@ -8,10 +8,7 @@ import { GeoJsonProperties } from 'geojson'; import { IField } from '../../fields/field'; import { Query } from '../../../../../../../src/plugins/data/common/query'; -import { - VectorJoinSourceRequestMeta, - VectorSourceSyncMeta, -} from '../../../../common/descriptor_types'; +import { VectorJoinSourceRequestMeta } from '../../../../common/descriptor_types'; import { PropertiesMap } from '../../../../common/elasticsearch_util'; import { ITooltipProperty } from '../../tooltips/tooltip_property'; import { ISource } from '../source'; @@ -26,7 +23,13 @@ export interface ITermJoinSource extends ISource { leftFieldName: string, registerCancelCallback: (callback: () => void) => void ): Promise; - getSyncMeta(): VectorSourceSyncMeta | null; + + /* + * Vector layer avoids unnecessarily re-fetching join data. + * Use getSyncMeta to expose fields that require join data re-fetch when changed. + */ + getSyncMeta(): object | null; + getId(): string; getRightFields(): IField[]; getTooltipProperties(properties: GeoJsonProperties): Promise; diff --git a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx index bf0752d54c426..bc3807a8247b1 100644 --- a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx @@ -17,7 +17,6 @@ import { MapExtent, Timeslice, VectorSourceRequestMeta, - VectorSourceSyncMeta, } from '../../../../common/descriptor_types'; import { DataRequest } from '../../util/data_request'; @@ -60,7 +59,13 @@ export interface IVectorSource extends ISource { getFields(): Promise; getFieldByName(fieldName: string): IField | null; getLeftJoinFields(): Promise; - getSyncMeta(): VectorSourceSyncMeta | null; + + /* + * Vector layer avoids unnecessarily re-fetching source data. + * Use getSyncMeta to expose fields that require source data re-fetch when changed. + */ + getSyncMeta(): object | null; + getFieldNames(): string[]; createField({ fieldName }: { fieldName: string }): IField; hasTooltipProperties(): boolean; @@ -159,7 +164,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc return { tooltipContent: null, areResultsTrimmed: false }; } - getSyncMeta(): VectorSourceSyncMeta | null { + getSyncMeta(): object | null { return null; } diff --git a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx index 33b95f4ca5816..cf138e0aadc60 100644 --- a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx +++ b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx @@ -20,7 +20,6 @@ import { import { ESSearchSource } from '../../../../../../classes/sources/es_search_source'; import { VectorLayer } from '../../../../../../classes/layers/vector_layer'; import { SCALING_TYPES, VECTOR_SHAPE_TYPE } from '../../../../../../../common/constants'; -import { ESSearchSourceSyncMeta } from '../../../../../../../common/descriptor_types'; export interface Props { cloneLayer: (layerId: string) => void; @@ -85,15 +84,13 @@ export class TOCEntryActionsPopover extends Component { async _getIsFeatureEditingEnabled(): Promise { const vectorLayer = this.props.layer as VectorLayer; - const layerSource = await this.props.layer.getSource(); + const layerSource = this.props.layer.getSource(); if (!(layerSource instanceof ESSearchSource)) { return false; } - const isClustered = - (layerSource?.getSyncMeta() as ESSearchSourceSyncMeta)?.scalingType === - SCALING_TYPES.CLUSTERS; + if ( - isClustered || + (layerSource as ESSearchSource).getSyncMeta().scalingType === SCALING_TYPES.CLUSTERS || (await vectorLayer.isFilteredByGlobalTime()) || vectorLayer.isPreviewLayer() || !vectorLayer.isVisible() ||