Skip to content

Commit

Permalink
Support injecting of any dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof committed Aug 2, 2019
1 parent 26c278d commit 6c25782
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
*/

import React from 'react';
import { InjectedDependencies, VisOptionsProps } from 'ui/vis/editors/default';

const withServiceSettings = (Component: React.ComponentType, serviceSettings: any) => (
props: any
) => <Component {...props} serviceSettings={serviceSettings} />;
const withInjectedDependencies = (
Component: React.ComponentType<VisOptionsProps & InjectedDependencies>,
dependencies: InjectedDependencies
) => (props: VisOptionsProps) => <Component {...props} {...dependencies} />;

export { withServiceSettings };
export { withInjectedDependencies };
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/tile_map/public/tile_map_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { convertToGeoJson } from 'ui/vis/map/convert_to_geojson';
import { createTileMapVisualization } from './tile_map_visualization';
import { visFactory } from '../../visualizations/public';
import { TileMapOptions } from './components/tile_map_options';
import { withServiceSettings } from '../../kbn_vislib_vis_types/public/utils/with_service_settings';
import { withInjectedDependencies } from '../../kbn_vislib_vis_types/public/utils/with_service_settings';

export function createTileMapTypeDefinition(dependencies) {
const CoordinateMapsVisualization = createTileMapVisualization(dependencies);
Expand Down Expand Up @@ -113,7 +113,7 @@ export function createTileMapTypeDefinition(dependencies) {
],
tmsLayers: [],
},
optionsTemplate: withServiceSettings(TileMapOptions, serviceSettings),
optionsTemplate: withInjectedDependencies(TileMapOptions, { serviceSettings }),
schemas: new Schemas([
{
group: 'metrics',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
import { Vis, VisParams } from 'ui/vis';

export type VisOptionsSetValue = (paramName: string, value: unknown) => void;
export interface VisOptionsProps {
serviceSettings?: any;

export interface InjectedDependencies {
[key: string]: any;
}
export interface VisOptionsProps extends InjectedDependencies {
stateParams: VisParams;
vis: Vis;
setValue: VisOptionsSetValue;
Expand Down

0 comments on commit 6c25782

Please sign in to comment.