Skip to content

Commit

Permalink
Logic to integrate dashboards-maps plugin with OSD for custom GeoJSON…
Browse files Browse the repository at this point in the history
… upload feature (opensearch-project#1632)

* adds logic to accommodate import custom map tab from dashboards-maps plugin

Signed-off-by: Shivam Dhar <[email protected]>

* adds type to http and notifications

Signed-off-by: Shivam Dhar <[email protected]>

Co-authored-by: Shivam Dhar <[email protected]>
  • Loading branch information
2 people authored and kavilla committed Jun 8, 2022
1 parent 3eaa817 commit 9f94a7c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/plugins/region_map/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ export interface RegionMapsConfigType {
export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin(initializerContext);
}

export { RegionMapPluginSetup, RegionMapVisualizationDependencies } from './plugin';
export { RegionMapOptionsProps } from './components/region_map_options';
19 changes: 18 additions & 1 deletion src/plugins/region_map/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ import { OpenSearchDashboardsLegacyStart } from '../../opensearch_dashboards_leg
import { SharePluginStart } from '../../share/public';

/** @private */
interface RegionMapVisualizationDependencies {
export interface RegionMapVisualizationDependencies {
http: CoreStart['http'];
notifications: CoreStart['notifications'];
uiSettings: IUiSettingsClient;
regionmapsConfig: RegionMapsConfig;
getServiceSettings: () => Promise<IServiceSettings>;
BaseMapsVisualization: any;
additionalOptions: AddImportMapTab[];
}

/** @internal */
Expand All @@ -88,16 +91,25 @@ export interface RegionMapsConfig {

export interface RegionMapPluginSetup {
config: any;
addOptionTab: (options: AddImportMapTab) => void;
}

export interface AddImportMapTab {
name: string;
title: string;
editor: (props: any) => JSX.Element;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RegionMapPluginStart {}

/** @internal */
export class RegionMapPlugin implements Plugin<RegionMapPluginSetup, RegionMapPluginStart> {
readonly _initializerContext: PluginInitializerContext<MapsLegacyConfig>;
private additionalOptions: AddImportMapTab[];

constructor(initializerContext: PluginInitializerContext) {
this._initializerContext = initializerContext;
this.additionalOptions = [];
}

public async setup(
Expand All @@ -112,10 +124,13 @@ export class RegionMapPlugin implements Plugin<RegionMapPluginSetup, RegionMapPl
...mapsLegacy.config.regionmap,
};
const visualizationDependencies: Readonly<RegionMapVisualizationDependencies> = {
http: core.http,
notifications: core.notifications,
uiSettings: core.uiSettings,
regionmapsConfig: config as RegionMapsConfig,
getServiceSettings: mapsLegacy.getServiceSettings,
BaseMapsVisualization: mapsLegacy.getBaseMapsVis(),
additionalOptions: this.additionalOptions,
};

expressions.registerFunction(createRegionMapFn);
Expand All @@ -126,6 +141,8 @@ export class RegionMapPlugin implements Plugin<RegionMapPluginSetup, RegionMapPl

return {
config,
addOptionTab: (importMapTabConfig: AddImportMapTab) =>
this.additionalOptions.push(importMapTabConfig),
};
}

Expand Down
22 changes: 18 additions & 4 deletions src/plugins/region_map/public/region_map_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { Schemas } from '../../vis_default_editor/public';
import { ORIGIN } from '../../maps_legacy/public';

export function createRegionMapTypeDefinition(dependencies) {
const { uiSettings, regionmapsConfig, getServiceSettings } = dependencies;
const { uiSettings, regionmapsConfig, getServiceSettings, additionalOptions } = dependencies;
const visualization = createRegionMapVisualization(dependencies);

return {
Expand Down Expand Up @@ -66,9 +66,23 @@ provided base maps, or add your own. Darker colors represent higher values.',
},
visualization,
editorConfig: {
optionsTemplate: (props) => (
<RegionMapOptions {...props} getServiceSettings={getServiceSettings} />
),
optionTabs: () => {
return [
{
name: 'options',
title: i18n.translate(
'regionMap.mapVis.regionMapEditorConfig.optionTabs.optionsTitle',
{
defaultMessage: 'Layer Options',
}
),
editor: (props) => (
<RegionMapOptions {...props} getServiceSettings={getServiceSettings} />
),
},
...additionalOptions,
];
},
collections: {
colorSchemas: truncatedColorSchemas,
vectorLayers: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export const useOptionTabs = ({ type: visType }: Vis): [OptionTab[], (name: stri
editor: visType.editorConfig.optionsTemplate,
},
]
: visType.editorConfig.optionTabs instanceof Function
? visType.editorConfig.optionTabs()
: visType.editorConfig.optionTabs),
];
// set up the first tab as selected
Expand Down

0 comments on commit 9f94a7c

Please sign in to comment.