diff --git a/src/plugins/ui_actions/public/actions/action_definition.ts b/src/plugins/ui_actions/public/actions/action_definition.ts index c590cf8f34ee0..b3456a09879a2 100644 --- a/src/plugins/ui_actions/public/actions/action_definition.ts +++ b/src/plugins/ui_actions/public/actions/action_definition.ts @@ -17,53 +17,16 @@ * under the License. */ -import { UiComponent } from 'src/plugins/kibana_utils/common'; import { ActionType, ActionContextMapping } from '../types'; +import { Presentable } from '../util/presentable'; -export interface ActionDefinition { +export interface ActionDefinition + extends Partial> { /** - * Determined the order when there is more than one action matched to a trigger. - * Higher numbers are displayed first. + * ID of the action factory for this action. Action factories are registered + * int X-Pack `ui_actions` plugin. */ - order?: number; - - /** - * A unique identifier for this action instance. - */ - id?: string; - - /** - * The action type is what determines the context shape. - */ - readonly type: T; - - /** - * Optional EUI icon type that can be displayed along with the title. - */ - getIconType?(context: ActionContextMapping[T]): string; - - /** - * Returns a title to be displayed to the user. - * @param context - */ - getDisplayName?(context: ActionContextMapping[T]): string; - - /** - * `UiComponent` to render when displaying this action as a context menu item. - * If not provided, `getDisplayName` will be used instead. - */ - MenuItem?: UiComponent<{ context: ActionContextMapping[T] }>; - - /** - * Returns a promise that resolves to true if this action is compatible given the context, - * otherwise resolves to false. - */ - isCompatible?(context: ActionContextMapping[T]): Promise; - - /** - * If this returns something truthy, this is used in addition to the `execute` method when clicked. - */ - getHref?(context: ActionContextMapping[T]): string | undefined; + readonly type?: T; /** * Executes the action. diff --git a/src/plugins/ui_actions/public/actions/create_action.ts b/src/plugins/ui_actions/public/actions/create_action.ts index 90a9415c0b497..462ba966f4715 100644 --- a/src/plugins/ui_actions/public/actions/create_action.ts +++ b/src/plugins/ui_actions/public/actions/create_action.ts @@ -30,5 +30,5 @@ export function createAction(action: ActionDefinition): getDisplayName: () => '', getHref: () => undefined, ...action, - }; + } as ActionByType; } diff --git a/src/plugins/ui_actions/public/util/presentable.ts b/src/plugins/ui_actions/public/util/presentable.ts index adf2035940d80..945fd2065ce78 100644 --- a/src/plugins/ui_actions/public/util/presentable.ts +++ b/src/plugins/ui_actions/public/util/presentable.ts @@ -19,12 +19,10 @@ import { UiComponent } from 'src/plugins/kibana_utils/common'; -export type PresentableBaseContext = object; - /** * Represents something that can be displayed to user in UI. */ -export interface Presentable { +export interface Presentable { /** * ID that uniquely identifies this object. */ diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 53628ea970fb6..39fcfe6ddb096 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -9,6 +9,7 @@ "xpack.beatsManagement": "legacy/plugins/beats_management", "xpack.canvas": "legacy/plugins/canvas", "xpack.crossClusterReplication": "legacy/plugins/cross_cluster_replication", + "xpack.dashboard": "plugins/dashboard_enhanced", "xpack.dashboardMode": "legacy/plugins/dashboard_mode", "xpack.data": "plugins/data_enhanced", "xpack.drilldowns": "plugins/drilldowns", diff --git a/x-pack/plugins/advanced_ui_actions/public/index.ts b/x-pack/plugins/advanced_ui_actions/public/index.ts index 582a5917d2d4a..62b8ef00f2950 100644 --- a/x-pack/plugins/advanced_ui_actions/public/index.ts +++ b/x-pack/plugins/advanced_ui_actions/public/index.ts @@ -17,6 +17,7 @@ export { AdvancedUiActionsSetup, AdvancedUiActionsStart } from './plugin'; export { ActionWizard } from './components'; export { ActionFactoryDefinition as AdvancedUiActionsActionFactoryDefinition, + AnyActionFactoryDefinition as AdvancedUiActionsAnyActionFactoryDefinition, ActionFactory as AdvancedUiActionsActionFactory, AnyActionFactory as AdvancedUiActionsAnyActionFactory, } from './services/action_factory_service'; diff --git a/x-pack/plugins/advanced_ui_actions/public/services/action_factory_service/action_factory.ts b/x-pack/plugins/advanced_ui_actions/public/services/action_factory_service/action_factory.ts index 5e41c6d3a7fce..2e9dfa03e5a3d 100644 --- a/x-pack/plugins/advanced_ui_actions/public/services/action_factory_service/action_factory.ts +++ b/x-pack/plugins/advanced_ui_actions/public/services/action_factory_service/action_factory.ts @@ -6,19 +6,19 @@ import { uiToReactComponent } from '../../../../../../src/plugins/kibana_react/public'; import { - UiActionsPresentable, - UiActionsActionDefinition, + UiActionsPresentable as Presentable, + UiActionsActionDefinition as ActionDefinition, } from '../../../../../../src/plugins/ui_actions/public'; import { AnyActionFactoryDefinition, - AFDConfig, - AFDFactoryContext, - AFDActionContext, + AFDConfig as Config, + AFDFactoryContext as FactoryContext, + AFDActionContext as ActionContext, } from './action_factory_definition'; import { Configurable } from '../../util'; export class ActionFactory - implements UiActionsPresentable>, Configurable> { + implements Presentable>, Configurable> { constructor(public readonly definition: D) {} public readonly id = this.definition.id; @@ -31,28 +31,28 @@ export class ActionFactory public readonly createConfig = this.definition.createConfig; public readonly isConfigValid = this.definition.isConfigValid; - public getIconType(context: AFDFactoryContext): string | undefined { + public getIconType(context: FactoryContext): string | undefined { if (!this.definition.getIconType) return undefined; return this.definition.getIconType(context); } - public getDisplayName(context: AFDFactoryContext): string { + public getDisplayName(context: FactoryContext): string { if (!this.definition.getDisplayName) return ''; return this.definition.getDisplayName(context); } - public async isCompatible(context: AFDFactoryContext): Promise { + public async isCompatible(context: FactoryContext): Promise { if (!this.definition.isCompatible) return true; return await this.definition.isCompatible(context); } - public getHref(context: AFDFactoryContext): string | undefined { + public getHref(context: FactoryContext): string | undefined { if (!this.definition.getHref) return undefined; return this.definition.getHref(context); } - public create(): UiActionsActionDefinition> { - throw new Error('not implemented'); + public create(config: Config): ActionDefinition> { + return this.definition.create(config); } } diff --git a/x-pack/plugins/advanced_ui_actions/public/services/action_factory_service/action_factory_definition.ts b/x-pack/plugins/advanced_ui_actions/public/services/action_factory_service/action_factory_definition.ts index ee03e599a2452..655e457b5412a 100644 --- a/x-pack/plugins/advanced_ui_actions/public/services/action_factory_service/action_factory_definition.ts +++ b/x-pack/plugins/advanced_ui_actions/public/services/action_factory_service/action_factory_definition.ts @@ -5,8 +5,8 @@ */ import { - UiActionsPresentable, - UiActionsActionDefinition, + UiActionsPresentable as Presentable, + UiActionsActionDefinition as ActionDefinition, } from '../../../../../../src/plugins/ui_actions/public'; import { Configurable } from '../../util'; @@ -17,7 +17,7 @@ export interface ActionFactoryDefinition< Config extends object = object, FactoryContext extends object = object, ActionContext extends object = object -> extends Partial>, Configurable { +> extends Partial>, Configurable { /** * Unique ID of the action factory. This ID is used to identify this action * factory in the registry as well as to construct actions of this ID and @@ -29,7 +29,7 @@ export interface ActionFactoryDefinition< * This method should return a definition of a new action, normally used to * register it in `ui_actions` registry. */ - create(): UiActionsActionDefinition; + create(config: Config): ActionDefinition; } export type AnyActionFactoryDefinition = ActionFactoryDefinition; diff --git a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_create_drilldown/index.tsx b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_create_drilldown/index.tsx index 459f7f568ea78..94c4830fb8638 100644 --- a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_create_drilldown/index.tsx +++ b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_create_drilldown/index.tsx @@ -31,7 +31,7 @@ export class FlyoutCreateDrilldownAction implements ActionByType Promise; } -const displayName = i18n.translate('xpack.drilldowns.panel.openFlyoutEditDrilldown.displayName', { +const displayName = i18n.translate('xpack.dashboard.panel.openFlyoutEditDrilldown.displayName', { defaultMessage: 'Manage drilldowns', }); diff --git a/x-pack/plugins/drilldowns/public/plugin.ts b/x-pack/plugins/drilldowns/public/plugin.ts index d2fa88bd21745..ee6f591c1325b 100644 --- a/x-pack/plugins/drilldowns/public/plugin.ts +++ b/x-pack/plugins/drilldowns/public/plugin.ts @@ -7,7 +7,7 @@ import { CoreStart, CoreSetup, Plugin } from 'src/core/public'; import { UiActionsSetup, UiActionsStart } from '../../../../src/plugins/ui_actions/public'; import { AdvancedUiActionsSetup, AdvancedUiActionsStart } from '../../advanced_ui_actions/public'; -import { DrilldownService, DrilldownServiceSetupContract } from './service'; +import { DrilldownService, DrilldownServiceSetupContract } from './services'; import { createFlyoutManageDrilldowns } from './components/connected_flyout_manage_drilldowns'; import { Storage } from '../../../../src/plugins/kibana_utils/public'; diff --git a/x-pack/plugins/drilldowns/public/service/drilldown_service.ts b/x-pack/plugins/drilldowns/public/services/drilldown_service.ts similarity index 51% rename from x-pack/plugins/drilldowns/public/service/drilldown_service.ts rename to x-pack/plugins/drilldowns/public/services/drilldown_service.ts index f9667e0baab60..8f7ff48270d81 100644 --- a/x-pack/plugins/drilldowns/public/service/drilldown_service.ts +++ b/x-pack/plugins/drilldowns/public/services/drilldown_service.ts @@ -5,10 +5,8 @@ */ import { CoreSetup } from 'src/core/public'; -import { - AdvancedUiActionsSetup, - AdvancedUiActionsActionFactoryDefinition, -} from '../../../advanced_ui_actions/public'; +import { AdvancedUiActionsSetup } from '../../../advanced_ui_actions/public'; +import { Drilldown } from '../types'; // TODO: MOCK DATA import { @@ -25,7 +23,7 @@ export interface DrilldownServiceSetupContract { /** * Convenience method to register a drilldown. */ - registerDrilldown: (drilldownFactory: AdvancedUiActionsActionFactoryDefinition) => void; + registerDrilldown: (drilldown: Drilldown) => void; } export class DrilldownService { @@ -33,12 +31,34 @@ export class DrilldownService { core: CoreSetup, { advancedUiActions }: DrilldownServiceSetupDeps ): DrilldownServiceSetupContract { - const registerDrilldown: DrilldownServiceSetupContract['registerDrilldown'] = drilldownFactory => { - advancedUiActions.actionFactory.register(drilldownFactory); + const registerDrilldown: DrilldownServiceSetupContract['registerDrilldown'] = ({ + id, + places, + CollectConfig, + createConfig, + isConfigValid, + getDisplayName, + getIconType, + execute, + }) => { + advancedUiActions.actionFactory.register({ + id, + CollectConfig, + createConfig, + isConfigValid, + getDisplayName, + getIconType, + isCompatible: async ({ place }: any) => (!places ? true : places.indexOf(place) > -1), + create: config => ({ + id: '', + type: id as any, + execute: async context => await execute(config, context), + }), + }); }; - registerDrilldown(dashboardDrilldownActionFactory); - registerDrilldown(urlDrilldownActionFactory); + registerDrilldown({ ...dashboardDrilldownActionFactory, execute: () => {} } as any); + registerDrilldown({ ...urlDrilldownActionFactory, execute: () => {} } as any); return { registerDrilldown, diff --git a/x-pack/plugins/drilldowns/public/service/index.ts b/x-pack/plugins/drilldowns/public/services/index.ts similarity index 100% rename from x-pack/plugins/drilldowns/public/service/index.ts rename to x-pack/plugins/drilldowns/public/services/index.ts diff --git a/x-pack/plugins/drilldowns/public/types.ts b/x-pack/plugins/drilldowns/public/types.ts new file mode 100644 index 0000000000000..fe54bcf8a34d8 --- /dev/null +++ b/x-pack/plugins/drilldowns/public/types.ts @@ -0,0 +1,33 @@ +/* + * 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 { AdvancedUiActionsActionFactoryDefinition as ActionFactoryDefinition } from '../../advanced_ui_actions/public'; + +export interface Drilldown< + Config extends object = object, + FactoryContext extends object = object, + ExecutionContext extends object = object +> + extends Pick< + ActionFactoryDefinition, + 'id' | 'createConfig' | 'CollectConfig' | 'isConfigValid' | 'getIconType' | 'getDisplayName' + > { + /** + * List of places where this drilldown should be available, e.g "dashboard". + * If omitted, the drilldown will be show in all places. + */ + places?: string[]; + + /** + * Implements the "navigation" action when user clicks something in the UI and + * instance of this drilldown is triggered. + * + * @param config Config object that user configured this drilldown with. + * @param context Object that represents context in which the underlying + * `UIAction` of this drilldown is being executed in. + */ + execute(config: Config, context: ExecutionContext): void; +}