diff --git a/x-pack/examples/third_party_maps_source_example/public/classes/custom_raster_source.tsx b/x-pack/examples/third_party_maps_source_example/public/classes/custom_raster_source.tsx index 881b721e03a3c..9903232054392 100644 --- a/x-pack/examples/third_party_maps_source_example/public/classes/custom_raster_source.tsx +++ b/x-pack/examples/third_party_maps_source_example/public/classes/custom_raster_source.tsx @@ -122,14 +122,6 @@ export class CustomRasterSource implements IRasterSource { return false; } - getIndexPatternIds(): string[] { - return []; - } - - getQueryableIndexPatternIds(): string[] { - return []; - } - // Returns function used to format value async createFieldFormatter(field: IField): Promise { return null; diff --git a/x-pack/plugins/maps/public/classes/joins/inner_join.ts b/x-pack/plugins/maps/public/classes/joins/inner_join.ts index a80ddd7c26e4f..bb66f1f6636fa 100644 --- a/x-pack/plugins/maps/public/classes/joins/inner_join.ts +++ b/x-pack/plugins/maps/public/classes/joins/inner_join.ts @@ -153,14 +153,6 @@ export class InnerJoin { return await this.getRightJoinSource().getTooltipProperties(properties, executionContext); } - getIndexPatternIds() { - return this.getRightJoinSource().getIndexPatternIds(); - } - - getQueryableIndexPatternIds() { - return this.getRightJoinSource().getQueryableIndexPatternIds(); - } - getWhereQuery(): Query | undefined { return this.getRightJoinSource().getWhereQuery(); } diff --git a/x-pack/plugins/maps/public/classes/layers/heatmap_layer/heatmap_layer.ts b/x-pack/plugins/maps/public/classes/layers/heatmap_layer/heatmap_layer.ts index 7615bc74a7329..50884c30020b4 100644 --- a/x-pack/plugins/maps/public/classes/layers/heatmap_layer/heatmap_layer.ts +++ b/x-pack/plugins/maps/public/classes/layers/heatmap_layer/heatmap_layer.ts @@ -11,6 +11,7 @@ import { HeatmapStyle } from '../../styles/heatmap/heatmap_style'; import { LAYER_TYPE } from '../../../../common/constants'; import { HeatmapLayerDescriptor } from '../../../../common/descriptor_types'; import { ESGeoGridSource } from '../../sources/es_geo_grid_source'; +import { hasESSourceMethod } from '../../sources/es_source'; import { NO_RESULTS_ICON_AND_TOOLTIPCONTENT, syncBoundsData, @@ -236,11 +237,15 @@ export class HeatmapLayer extends AbstractLayer { } getIndexPatternIds() { - return this.getSource().getIndexPatternIds(); + const source = this.getSource(); + return hasESSourceMethod(source, 'getIndexPatternId') ? [source.getIndexPatternId()] : []; } getQueryableIndexPatternIds() { - return this.getSource().getQueryableIndexPatternIds(); + const source = this.getSource(); + return source.getApplyGlobalQuery() && hasESSourceMethod(source, 'getIndexPatternId') + ? [source.getIndexPatternId()] + : []; } async getLicensedFeatures() { diff --git a/x-pack/plugins/maps/public/classes/layers/layer.tsx b/x-pack/plugins/maps/public/classes/layers/layer.tsx index 66fee3e3455be..1fccaf7f6d0a5 100644 --- a/x-pack/plugins/maps/public/classes/layers/layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/layer.tsx @@ -109,7 +109,14 @@ export interface ILayer { ownsMbSourceId(mbSourceId: string): boolean; syncLayerWithMB(mbMap: MbMap, timeslice?: Timeslice): void; getLayerTypeIconName(): string; + /* + * ILayer.getIndexPatternIds returns data view ids used to populate layer data. + */ getIndexPatternIds(): string[]; + /* + * ILayer.getQueryableIndexPatternIds returns ILayer.getIndexPatternIds or a subset of ILayer.getIndexPatternIds. + * Data view ids are excluded when the global query is not applied to layer data. + */ getQueryableIndexPatternIds(): string[]; getType(): LAYER_TYPE; isVisible(): boolean; diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx index 15a18bb9a0bca..2069c668a391f 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx @@ -362,17 +362,36 @@ export class AbstractVectorLayer extends AbstractLayer implements IVectorLayer { } getIndexPatternIds() { - const indexPatternIds = this.getSource().getIndexPatternIds(); + const indexPatternIds = []; + const source = this.getSource(); + if (hasESSourceMethod(source, 'getIndexPatternId')) { + indexPatternIds.push(source.getIndexPatternId()); + } + this.getValidJoins().forEach((join) => { - indexPatternIds.push(...join.getIndexPatternIds()); + const rightSource = join.getRightJoinSource(); + if (hasESSourceMethod(rightSource, 'getIndexPatternId')) { + indexPatternIds.push(rightSource.getIndexPatternId()); + } }); return indexPatternIds; } getQueryableIndexPatternIds() { - const indexPatternIds = this.getSource().getQueryableIndexPatternIds(); + const indexPatternIds = []; + const source = this.getSource(); + if (source.getApplyGlobalQuery() && hasESSourceMethod(source, 'getIndexPatternId')) { + indexPatternIds.push(source.getIndexPatternId()); + } + this.getValidJoins().forEach((join) => { - indexPatternIds.push(...join.getQueryableIndexPatternIds()); + const rightSource = join.getRightJoinSource(); + if ( + rightSource.getApplyGlobalQuery() && + hasESSourceMethod(rightSource, 'getIndexPatternId') + ) { + indexPatternIds.push(rightSource.getIndexPatternId()); + } }); return indexPatternIds; } diff --git a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts index 4dfdbe92a194a..d982bfaf09f5d 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts @@ -105,17 +105,6 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource return true; } - getIndexPatternIds(): string[] { - return [this.getIndexPatternId()]; - } - - getQueryableIndexPatternIds(): string[] { - if (this.getApplyGlobalQuery()) { - return [this.getIndexPatternId()]; - } - return []; - } - cloneDescriptor(): AbstractSourceDescriptor { const clonedDescriptor = copyPersistentState(this._descriptor); // id used as uuid to track requests in inspector diff --git a/x-pack/plugins/maps/public/classes/sources/source.ts b/x-pack/plugins/maps/public/classes/sources/source.ts index c40388349f229..4c8b65c46b47c 100644 --- a/x-pack/plugins/maps/public/classes/sources/source.ts +++ b/x-pack/plugins/maps/public/classes/sources/source.ts @@ -65,8 +65,6 @@ export interface ISource { getApplyGlobalQuery(): boolean; getApplyGlobalTime(): boolean; getApplyForceRefresh(): boolean; - getIndexPatternIds(): string[]; - getQueryableIndexPatternIds(): string[]; createFieldFormatter(field: IField): Promise; getValueSuggestions(field: IField, query: string): Promise; getMinZoom(): number; @@ -134,14 +132,6 @@ export class AbstractSource implements ISource { return false; } - getIndexPatternIds(): string[] { - return []; - } - - getQueryableIndexPatternIds(): string[] { - return []; - } - // Returns function used to format value async createFieldFormatter(field: IField): Promise { return null; diff --git a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/filter_editor/filter_editor.tsx b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/filter_editor/filter_editor.tsx index 9e3edeb1fc255..64d7d81b5edd9 100644 --- a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/filter_editor/filter_editor.tsx +++ b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/filter_editor/filter_editor.tsx @@ -25,10 +25,11 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; import type { DataView, Query } from '@kbn/data-plugin/common'; import { APP_ID } from '../../../../common/constants'; -import { getIndexPatternService, getData, getSearchBar } from '../../../kibana_services'; +import { getData, getSearchBar } from '../../../kibana_services'; import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox'; import { GlobalTimeCheckbox } from '../../../components/global_time_checkbox'; import { ILayer } from '../../../classes/layers/layer'; +import { hasESSourceMethod } from '../../../classes/sources/es_source'; import { ForceRefreshCheckbox } from '../../../components/force_refresh_checkbox'; export interface Props { @@ -40,7 +41,7 @@ export interface Props { interface State { isPopoverOpen: boolean; - indexPatterns: DataView[]; + dataView?: DataView; isSourceTimeAware: boolean; } @@ -48,13 +49,12 @@ export class FilterEditor extends Component { private _isMounted = false; state: State = { isPopoverOpen: false, - indexPatterns: [], isSourceTimeAware: false, }; componentDidMount() { this._isMounted = true; - this._loadIndexPatterns(); + this._loadDataView(); this._loadSourceTimeAware(); } @@ -62,26 +62,19 @@ export class FilterEditor extends Component { this._isMounted = false; } - async _loadIndexPatterns() { - // Filter only effects source so only load source indices. - const indexPatternIds = this.props.layer.getSource().getIndexPatternIds(); - const indexPatterns: DataView[] = []; - const getIndexPatternPromises = indexPatternIds.map(async (indexPatternId) => { - try { - const indexPattern = await getIndexPatternService().get(indexPatternId); - indexPatterns.push(indexPattern); - } catch (err) { - // unable to fetch index pattern - } - }); - - await Promise.all(getIndexPatternPromises); + async _loadDataView() { + const source = this.props.layer.getSource(); + if (!hasESSourceMethod(source, 'getIndexPattern')) { + return; + } + + const dataView = await source.getIndexPattern(); if (!this._isMounted) { return; } - this.setState({ indexPatterns }); + this.setState({ dataView }); } async _loadSourceTimeAware() { @@ -142,7 +135,7 @@ export class FilterEditor extends Component { showQueryInput={true} query={layerQuery ? layerQuery : getData().query.queryString.getDefaultQuery()} onQuerySubmit={this._onQueryChange} - indexPatterns={this.state.indexPatterns} + indexPatterns={this.state.dataView ? [this.state.dataView] : []} customSubmitButton={