Skip to content

Commit

Permalink
Add indexPatterns to map embeddable output for dashboard filters (ope…
Browse files Browse the repository at this point in the history
…nsearch-project#272) (opensearch-project#278)

Signed-off-by: Junqiu Lei <junqiu@amazon.com>
(cherry picked from commit 8697636)

Co-authored-by: Junqiu Lei <junqiu@amazon.com>
  • Loading branch information
opensearch-trigger-bot[bot] and junqiu-lei committed Feb 22, 2023
1 parent 5809f19 commit 11cf90e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
29 changes: 24 additions & 5 deletions public/embeddable/map_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
};
}

Expand All @@ -51,19 +64,25 @@ export class MapEmbeddable extends Embeddable<MapInput, MapOutput> {
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));
});
}

Expand Down
22 changes: 18 additions & 4 deletions public/embeddable/map_embeddable_factory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -28,6 +29,11 @@ interface StartServices {
get: (type: string, id: string) => Promise<any>;
};
};
data: {
indexPatterns: {
get: (id: string) => Promise<IndexPattern>;
};
};
};
mapConfig: ConfigSchema;
}
Expand Down Expand Up @@ -64,22 +70,30 @@ 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,
savedObjectId,
title: savedMapAttributes.title,
},
{
indexPatterns,
parent,
services,
mapConfig,
editUrl: url,
savedMapAttributes,
timeFilter,
}
);
} catch (error) {
Expand Down

0 comments on commit 11cf90e

Please sign in to comment.