From 11cf90ee6b6c8a77cc32c1a734eec09333a20187 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 22 Feb 2023 08:32:00 -0800 Subject: [PATCH] Add indexPatterns to map embeddable output for dashboard filters (#272) (#278) Signed-off-by: Junqiu Lei (cherry picked from commit 8697636bc6753eb7c40c1dbc169ff02fc37e3980) Co-authored-by: Junqiu Lei --- public/embeddable/map_embeddable.tsx | 29 ++++++++++++++++---- public/embeddable/map_embeddable_factory.tsx | 22 ++++++++++++--- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/public/embeddable/map_embeddable.tsx b/public/embeddable/map_embeddable.tsx index 72e03d0b..6d593520 100644 --- a/public/embeddable/map_embeddable.tsx +++ b/public/embeddable/map_embeddable.tsx @@ -16,7 +16,7 @@ import { import { MapEmbeddableComponent } from './map_component'; import { ConfigSchema } from '../../common/config'; import { MapSavedObjectAttributes } from '../../common/map_saved_object_attributes'; -import { RefreshInterval } from '../../../../src/plugins/data/public'; +import { IndexPattern, RefreshInterval } from '../../../../src/plugins/data/public'; export const MAP_EMBEDDABLE = MAP_SAVED_OBJECT_TYPE; @@ -25,15 +25,28 @@ export interface MapInput extends EmbeddableInput { refreshConfig?: RefreshInterval; } -export type MapOutput = EmbeddableOutput; +export interface MapOutput extends EmbeddableOutput { + editable: boolean; + editUrl: string; + defaultTitle: string; + editApp: string; + editPath: string; + indexPatterns: IndexPattern[]; +} -function getOutput(input: MapInput, editUrl: string, tittle: string): MapOutput { +function getOutput( + input: MapInput, + editUrl: string, + tittle: string, + indexPatterns: IndexPattern[] +): MapOutput { return { editable: true, editUrl, defaultTitle: tittle, editApp: MAPS_APP_ID, editPath: input.savedObjectId, + indexPatterns, }; } @@ -51,19 +64,25 @@ export class MapEmbeddable extends Embeddable { mapConfig, editUrl, savedMapAttributes, + indexPatterns, }: { parent?: IContainer; services: any; mapConfig: ConfigSchema; editUrl: string; savedMapAttributes: MapSavedObjectAttributes; + indexPatterns: IndexPattern[]; } ) { - super(initialInput, getOutput(initialInput, editUrl, savedMapAttributes.title), parent); + super( + initialInput, + getOutput(initialInput, editUrl, savedMapAttributes.title, indexPatterns), + parent + ); this.mapConfig = mapConfig; this.services = services; this.subscription = this.getInput$().subscribe(() => { - this.updateOutput(getOutput(this.input, editUrl, savedMapAttributes.title)); + this.updateOutput(getOutput(this.input, editUrl, savedMapAttributes.title, indexPatterns)); }); } diff --git a/public/embeddable/map_embeddable_factory.tsx b/public/embeddable/map_embeddable_factory.tsx index b1534687..ce5ccc78 100644 --- a/public/embeddable/map_embeddable_factory.tsx +++ b/public/embeddable/map_embeddable_factory.tsx @@ -11,11 +11,12 @@ import { SavedObjectEmbeddableInput, } from '../../../../src/plugins/embeddable/public'; import { MAP_EMBEDDABLE, MapInput, MapOutput, MapEmbeddable } from './map_embeddable'; -import { MAPS_APP_ICON, MAPS_APP_ID } from '../../common'; +import { DASHBOARDS_MAPS_LAYER_TYPE, MAPS_APP_ICON, MAPS_APP_ID } from '../../common'; import { ConfigSchema } from '../../common/config'; import { MapSavedObjectAttributes } from '../../common/map_saved_object_attributes'; import { MAPS_APP_DISPLAY_NAME } from '../../common/constants/shared'; -import { getTimeFilter } from '../services'; +import { MapLayerSpecification } from '../model/mapLayerType'; +import { IndexPattern } from '../../../../src/plugins/data/common'; interface StartServices { services: { @@ -28,6 +29,11 @@ interface StartServices { get: (type: string, id: string) => Promise; }; }; + data: { + indexPatterns: { + get: (id: string) => Promise; + }; + }; }; mapConfig: ConfigSchema; } @@ -64,9 +70,17 @@ export class MapEmbeddableFactoryDefinition const url = services.application.getUrlForApp(MAPS_APP_ID, { path: savedObjectId, }); - const timeFilter = getTimeFilter(); const savedMap = await services.savedObjects.client.get(MAP_EMBEDDABLE, savedObjectId); const savedMapAttributes = savedMap.attributes as MapSavedObjectAttributes; + const layerList: MapLayerSpecification[] = JSON.parse(savedMapAttributes.layerList as string); + const indexPatterns: IndexPattern[] = []; + for (const layer of layerList) { + if (layer.type === DASHBOARDS_MAPS_LAYER_TYPE.DOCUMENTS) { + const indexPatternId = layer.source.indexPatternId; + const indexPattern = await services.data.indexPatterns.get(indexPatternId); + indexPatterns.push(indexPattern); + } + } return new MapEmbeddable( { ...input, @@ -74,12 +88,12 @@ export class MapEmbeddableFactoryDefinition title: savedMapAttributes.title, }, { + indexPatterns, parent, services, mapConfig, editUrl: url, savedMapAttributes, - timeFilter, } ); } catch (error) {