Skip to content

Commit

Permalink
feat: 🎸 create dashboard_enhanced plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Apr 6, 2020
1 parent b655160 commit bd60130
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 37 deletions.
38 changes: 1 addition & 37 deletions x-pack/plugins/dashboard_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,8 @@
*/

import { CoreStart, CoreSetup, Plugin, PluginInitializerContext } from 'src/core/public';
import { SavedObjectAttributes } from 'kibana/public';
import { UiActionsSetup, UiActionsStart } from '../../../../src/plugins/ui_actions/public';
import {
EmbeddableFactory,
EmbeddableFactoryDefinition,
EmbeddableInput,
EmbeddableOutput,
EmbeddableSetup,
EmbeddableStart,
IEmbeddable,
defaultEmbeddableFactoryProvider,
} from '../../../../src/plugins/embeddable/public';
import { EmbeddableSetup, EmbeddableStart } from '../../../../src/plugins/embeddable/public';
import { DashboardDrilldownsService } from './services';
import { DrilldownsSetup, DrilldownsStart } from '../../drilldowns/public';

Expand Down Expand Up @@ -48,32 +38,6 @@ export class DashboardEnhancedPlugin
}

public setup(core: CoreSetup<StartDependencies>, plugins: SetupDependencies): SetupContract {
plugins.embeddable.setCustomEmbeddableFactoryProvider(
<
I extends EmbeddableInput = EmbeddableInput,
O extends EmbeddableOutput = EmbeddableOutput,
E extends IEmbeddable<I, O> = IEmbeddable<I, O>,
T extends SavedObjectAttributes = SavedObjectAttributes
>(
def: EmbeddableFactoryDefinition<I, O, E, T>
): EmbeddableFactory<I, O, E, T> => {
const factory: EmbeddableFactory<I, O, E, T> = defaultEmbeddableFactoryProvider<I, O, E, T>(
def
);
return {
...factory,
create: async (...args) => {
const embeddable = await factory.create(...args);
return embeddable;
},
createFromSavedObject: async (...args) => {
const embeddable = await factory.createFromSavedObject(...args);
return embeddable;
},
};
}
);

this.drilldowns.bootstrap(core, plugins, {
enableDrilldowns: true,
});
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/embeddable_enhanced/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# X-Pack part of `embeddable` plugin
7 changes: 7 additions & 0 deletions x-pack/plugins/embeddable_enhanced/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "embeddableEnhanced",
"version": "kibana",
"server": false,
"ui": true,
"requiredPlugins": ["uiActions", "embeddable"]
}
19 changes: 19 additions & 0 deletions x-pack/plugins/embeddable_enhanced/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginInitializerContext } from 'src/core/public';
import { EmbeddableEnhancedPlugin } from './plugin';

export {
SetupContract as EmbeddableEnhancedSetupContract,
SetupDependencies as EmbeddableEnhancedSetupDependencies,
StartContract as EmbeddableEnhancedStartContract,
StartDependencies as EmbeddableEnhancedStartDependencies,
} from './plugin';

export function plugin(context: PluginInitializerContext) {
return new EmbeddableEnhancedPlugin(context);
}
27 changes: 27 additions & 0 deletions x-pack/plugins/embeddable_enhanced/public/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { EmbeddableEnhancedSetupContract, EmbeddableEnhancedStartContract } from '.';

export type Setup = jest.Mocked<EmbeddableEnhancedSetupContract>;
export type Start = jest.Mocked<EmbeddableEnhancedStartContract>;

const createSetupContract = (): Setup => {
const setupContract: Setup = {};

return setupContract;
};

const createStartContract = (): Start => {
const startContract: Start = {};

return startContract;
};

export const embeddableEnhancedPluginMock = {
createSetupContract,
createStartContract,
};
76 changes: 76 additions & 0 deletions x-pack/plugins/embeddable_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreStart, CoreSetup, Plugin, PluginInitializerContext } from 'src/core/public';
import { SavedObjectAttributes } from 'kibana/public';
import { UiActionsSetup, UiActionsStart } from '../../../../src/plugins/ui_actions/public';
import {
EmbeddableFactory,
EmbeddableFactoryDefinition,
EmbeddableInput,
EmbeddableOutput,
EmbeddableSetup,
EmbeddableStart,
IEmbeddable,
defaultEmbeddableFactoryProvider,
} from '../../../../src/plugins/embeddable/public';

export interface SetupDependencies {
embeddable: EmbeddableSetup;
uiActions: UiActionsSetup;
}

export interface StartDependencies {
embeddable: EmbeddableStart;
uiActions: UiActionsStart;
}

// eslint-disable-next-line
export interface SetupContract {}

// eslint-disable-next-line
export interface StartContract {}

export class EmbeddableEnhancedPlugin
implements Plugin<SetupContract, StartContract, SetupDependencies, StartDependencies> {
constructor(protected readonly context: PluginInitializerContext) {}

public setup(core: CoreSetup<StartDependencies>, plugins: SetupDependencies): SetupContract {
plugins.embeddable.setCustomEmbeddableFactoryProvider(
<
I extends EmbeddableInput = EmbeddableInput,
O extends EmbeddableOutput = EmbeddableOutput,
E extends IEmbeddable<I, O> = IEmbeddable<I, O>,
T extends SavedObjectAttributes = SavedObjectAttributes
>(
def: EmbeddableFactoryDefinition<I, O, E, T>
): EmbeddableFactory<I, O, E, T> => {
const factory: EmbeddableFactory<I, O, E, T> = defaultEmbeddableFactoryProvider<I, O, E, T>(
def
);
return {
...factory,
create: async (...args) => {
const embeddable = await factory.create(...args);
return embeddable;
},
createFromSavedObject: async (...args) => {
const embeddable = await factory.createFromSavedObject(...args);
return embeddable;
},
};
}
);

return {};
}

public start(core: CoreStart, plugins: StartDependencies): StartContract {
return {};
}

public stop() {}
}

0 comments on commit bd60130

Please sign in to comment.