[Lens] Make Lens plugin registry signatures consistent (#51839)
This commit is contained in:
parent
529dcbbe30
commit
8cae172f02
|
@ -73,7 +73,7 @@ export class AppPlugin {
|
|||
editorFrameSetupInterface.registerVisualization(xyVisualization);
|
||||
editorFrameSetupInterface.registerVisualization(datatableVisualization);
|
||||
editorFrameSetupInterface.registerVisualization(metricVisualization);
|
||||
editorFrameSetupInterface.registerDatasource('indexpattern', indexPattern);
|
||||
editorFrameSetupInterface.registerDatasource(indexPattern);
|
||||
|
||||
kibana_legacy.registerLegacyApp({
|
||||
id: 'lens',
|
||||
|
|
|
@ -51,6 +51,7 @@ export function createMockDatasource(): DatasourceMock {
|
|||
};
|
||||
|
||||
return {
|
||||
id: 'mockindexpattern',
|
||||
getDatasourceSuggestionsForField: jest.fn((_state, item) => []),
|
||||
getDatasourceSuggestionsFromCurrentState: jest.fn(_state => []),
|
||||
getPersistableState: jest.fn(),
|
||||
|
|
|
@ -57,8 +57,8 @@ export class EditorFramePlugin {
|
|||
plugins.expressions.registerFunction(() => mergeTables);
|
||||
|
||||
return {
|
||||
registerDatasource: (name, datasource) => {
|
||||
this.datasources[name] = datasource as Datasource<unknown, unknown>;
|
||||
registerDatasource: datasource => {
|
||||
this.datasources[datasource.id] = datasource as Datasource<unknown, unknown>;
|
||||
},
|
||||
registerVisualization: visualization => {
|
||||
this.visualizations[visualization.id] = visualization as Visualization<unknown, unknown>;
|
||||
|
|
|
@ -113,6 +113,8 @@ export function getIndexPatternDatasource({
|
|||
|
||||
// Not stateful. State is persisted to the frame
|
||||
const indexPatternDatasource: Datasource<IndexPatternPrivateState, IndexPatternPersistedState> = {
|
||||
id: 'indexpattern',
|
||||
|
||||
initialize(state?: IndexPatternPersistedState) {
|
||||
return loadInitialState({ state, savedObjectsClient });
|
||||
},
|
||||
|
|
|
@ -47,7 +47,7 @@ export interface EditorFrameInstance {
|
|||
|
||||
export interface EditorFrameSetup {
|
||||
// generic type on the API functions to pull the "unknown vs. specific type" error into the implementation
|
||||
registerDatasource: <T, P>(name: string, datasource: Datasource<T, P>) => void;
|
||||
registerDatasource: <T, P>(datasource: Datasource<T, P>) => void;
|
||||
registerVisualization: <T, P>(visualization: Visualization<T, P>) => void;
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,8 @@ export type StateSetter<T> = (newState: T | ((prevState: T) => T)) => void;
|
|||
* Interface for the datasource registry
|
||||
*/
|
||||
export interface Datasource<T = unknown, P = unknown> {
|
||||
id: string;
|
||||
|
||||
// For initializing, either from an empty state or from persisted state
|
||||
// Because this will be called at runtime, state might have a type of `any` and
|
||||
// datasources should validate their arguments
|
||||
|
|
Loading…
Reference in a new issue