Remove dynamic mapped types from UiActions (#87075) (#87274)

* Remove dynamic mapped types from UiActions

* Remove import between data <-> embeddables

* remove outdated comments, export action types from discover_enhanced

* fix notice.txt

Co-authored-by: restrry <restrry@gmail.com>

Co-authored-by: Josh Dover <me@joshdover.com>
This commit is contained in:
Mikhail Shustov 2021-01-05 13:27:11 +01:00 committed by GitHub
parent 23083b1404
commit 5bb0186c15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
167 changed files with 483 additions and 1149 deletions

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
contextMenuTrigger: Trigger<'CONTEXT_MENU_TRIGGER'>
contextMenuTrigger: Trigger
```

View file

@ -7,9 +7,9 @@
<b>Signature:</b>
```typescript
supportedTriggers(): Array<keyof TriggerContextMapping>;
supportedTriggers(): string[];
```
<b>Returns:</b>
`Array<keyof TriggerContextMapping>`
`string[]`

View file

@ -9,9 +9,9 @@ List of triggers that this embeddable will execute.
<b>Signature:</b>
```typescript
supportedTriggers(): Array<keyof TriggerContextMapping>;
supportedTriggers(): string[];
```
<b>Returns:</b>
`Array<keyof TriggerContextMapping>`
`string[]`

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
panelBadgeTrigger: Trigger<'PANEL_BADGE_TRIGGER'>
panelBadgeTrigger: Trigger
```

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
panelNotificationTrigger: Trigger<'PANEL_NOTIFICATION_TRIGGER'>
panelNotificationTrigger: Trigger
```

View file

@ -7,7 +7,7 @@
<b>Signature:</b>
```typescript
export interface Action<Context extends BaseContext = {}, T = ActionType> extends Partial<Presentable<ActionExecutionContext<Context>>>
export interface Action<Context extends object = object> extends Partial<Presentable<ActionExecutionContext<Context>>>
```
## Properties
@ -17,7 +17,7 @@ export interface Action<Context extends BaseContext = {}, T = ActionType> extend
| [id](./kibana-plugin-plugins-ui_actions-public.action.id.md) | <code>string</code> | A unique identifier for this action instance. |
| [MenuItem](./kibana-plugin-plugins-ui_actions-public.action.menuitem.md) | <code>UiComponent&lt;{</code><br/><code> context: ActionExecutionContext&lt;Context&gt;;</code><br/><code> }&gt;</code> | <code>UiComponent</code> to render when displaying this action as a context menu item. If not provided, <code>getDisplayName</code> will be used instead. |
| [order](./kibana-plugin-plugins-ui_actions-public.action.order.md) | <code>number</code> | Determined the order when there is more than one action matched to a trigger. Higher numbers are displayed first. |
| [type](./kibana-plugin-plugins-ui_actions-public.action.type.md) | <code>T</code> | The action type is what determines the context shape. |
| [type](./kibana-plugin-plugins-ui_actions-public.action.type.md) | <code>string</code> | The action type is what determines the context shape. |
## Methods

View file

@ -9,5 +9,5 @@ The action type is what determines the context shape.
<b>Signature:</b>
```typescript
readonly type: T;
readonly type: string;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [ActionByType](./kibana-plugin-plugins-ui_actions-public.actionbytype.md)
## ActionByType type
<b>Signature:</b>
```typescript
export declare type ActionByType<T extends ActionType> = Action<ActionContextMapping[T], T>;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [ActionContextMapping](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.md) &gt; [""](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.__.md)
## ActionContextMapping."" property
<b>Signature:</b>
```typescript
[DEFAULT_ACTION]: BaseContext;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [ActionContextMapping](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.md) &gt; [ACTION\_VISUALIZE\_FIELD](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.action_visualize_field.md)
## ActionContextMapping.ACTION\_VISUALIZE\_FIELD property
<b>Signature:</b>
```typescript
[ACTION_VISUALIZE_FIELD]: VisualizeFieldContext;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [ActionContextMapping](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.md) &gt; [ACTION\_VISUALIZE\_GEO\_FIELD](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.action_visualize_geo_field.md)
## ActionContextMapping.ACTION\_VISUALIZE\_GEO\_FIELD property
<b>Signature:</b>
```typescript
[ACTION_VISUALIZE_GEO_FIELD]: VisualizeFieldContext;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [ActionContextMapping](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.md) &gt; [ACTION\_VISUALIZE\_LENS\_FIELD](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.action_visualize_lens_field.md)
## ActionContextMapping.ACTION\_VISUALIZE\_LENS\_FIELD property
<b>Signature:</b>
```typescript
[ACTION_VISUALIZE_LENS_FIELD]: VisualizeFieldContext;
```

View file

@ -1,21 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [ActionContextMapping](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.md)
## ActionContextMapping interface
<b>Signature:</b>
```typescript
export interface ActionContextMapping
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [""](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.__.md) | <code>BaseContext</code> | |
| [ACTION\_VISUALIZE\_FIELD](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.action_visualize_field.md) | <code>VisualizeFieldContext</code> | |
| [ACTION\_VISUALIZE\_GEO\_FIELD](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.action_visualize_geo_field.md) | <code>VisualizeFieldContext</code> | |
| [ACTION\_VISUALIZE\_LENS\_FIELD](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.action_visualize_lens_field.md) | <code>VisualizeFieldContext</code> | |

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [ActionDefinitionByType](./kibana-plugin-plugins-ui_actions-public.actiondefinitionbytype.md)
## ActionDefinitionByType type
<b>Signature:</b>
```typescript
export declare type ActionDefinitionByType<T extends ActionType> = ActionDefinition<ActionContextMapping[T]>;
```

View file

@ -9,5 +9,5 @@ Action methods are executed with Context from trigger + [ActionExecutionMeta](./
<b>Signature:</b>
```typescript
export declare type ActionExecutionContext<Context extends BaseContext = BaseContext> = Context & ActionExecutionMeta;
export declare type ActionExecutionContext<Context extends object = object> = Context & ActionExecutionMeta;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [ActionType](./kibana-plugin-plugins-ui_actions-public.actiontype.md)
## ActionType type
<b>Signature:</b>
```typescript
export declare type ActionType = keyof ActionContextMapping;
```

View file

@ -7,16 +7,16 @@
<b>Signature:</b>
```typescript
export declare function createAction<T extends ActionType>(action: ActionDefinitionByType<T>): ActionByType<T>;
export declare function createAction<Context extends object = object>(action: ActionDefinition<Context>): Action<Context>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| action | <code>ActionDefinitionByType&lt;T&gt;</code> | |
| action | <code>ActionDefinition&lt;Context&gt;</code> | |
<b>Returns:</b>
`ActionByType<T>`
`Action<Context>`

View file

@ -24,11 +24,9 @@
| Interface | Description |
| --- | --- |
| [Action](./kibana-plugin-plugins-ui_actions-public.action.md) | |
| [ActionContextMapping](./kibana-plugin-plugins-ui_actions-public.actioncontextmapping.md) | |
| [ActionExecutionMeta](./kibana-plugin-plugins-ui_actions-public.actionexecutionmeta.md) | During action execution we can provide additional information, for example, trigger, that caused the action execution |
| [RowClickContext](./kibana-plugin-plugins-ui_actions-public.rowclickcontext.md) | |
| [Trigger](./kibana-plugin-plugins-ui_actions-public.trigger.md) | This is a convenience interface used to register a \*trigger\*.<code>Trigger</code> specifies a named anchor to which <code>Action</code> can be attached. When <code>Trigger</code> is being \*called\* it creates a <code>Context</code> object and passes it to the <code>execute</code> method of an <code>Action</code>.<!-- -->More than one action can be attached to a single trigger, in which case when trigger is \*called\* it first displays a context menu for user to pick a single action to execute. |
| [TriggerContextMapping](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.md) | |
| [UiActionsActionDefinition](./kibana-plugin-plugins-ui_actions-public.uiactionsactiondefinition.md) | A convenience interface used to register an action. |
| [UiActionsPresentable](./kibana-plugin-plugins-ui_actions-public.uiactionspresentable.md) | Represents something that can be displayed to user in UI. |
| [UiActionsServiceParams](./kibana-plugin-plugins-ui_actions-public.uiactionsserviceparams.md) | |
@ -52,12 +50,7 @@
| Type Alias | Description |
| --- | --- |
| [ActionByType](./kibana-plugin-plugins-ui_actions-public.actionbytype.md) | |
| [ActionDefinitionByType](./kibana-plugin-plugins-ui_actions-public.actiondefinitionbytype.md) | |
| [ActionExecutionContext](./kibana-plugin-plugins-ui_actions-public.actionexecutioncontext.md) | Action methods are executed with Context from trigger + [ActionExecutionMeta](./kibana-plugin-plugins-ui_actions-public.actionexecutionmeta.md) |
| [ActionType](./kibana-plugin-plugins-ui_actions-public.actiontype.md) | |
| [TriggerContext](./kibana-plugin-plugins-ui_actions-public.triggercontext.md) | |
| [TriggerId](./kibana-plugin-plugins-ui_actions-public.triggerid.md) | |
| [UiActionsPresentableGrouping](./kibana-plugin-plugins-ui_actions-public.uiactionspresentablegrouping.md) | |
| [UiActionsSetup](./kibana-plugin-plugins-ui_actions-public.uiactionssetup.md) | |
| [UiActionsStart](./kibana-plugin-plugins-ui_actions-public.uiactionsstart.md) | |

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
rowClickTrigger: Trigger<'ROW_CLICK_TRIGGER'>
rowClickTrigger: Trigger
```

View file

@ -9,5 +9,5 @@ Unique name of the trigger as identified in `ui_actions` plugin trigger registry
<b>Signature:</b>
```typescript
id: ID;
id: string;
```

View file

@ -13,7 +13,7 @@ More than one action can be attached to a single trigger, in which case when tri
<b>Signature:</b>
```typescript
export interface Trigger<ID extends TriggerId = TriggerId>
export interface Trigger
```
## Properties
@ -21,6 +21,6 @@ export interface Trigger<ID extends TriggerId = TriggerId>
| Property | Type | Description |
| --- | --- | --- |
| [description](./kibana-plugin-plugins-ui_actions-public.trigger.description.md) | <code>string</code> | A longer user friendly description of the trigger. |
| [id](./kibana-plugin-plugins-ui_actions-public.trigger.id.md) | <code>ID</code> | Unique name of the trigger as identified in <code>ui_actions</code> plugin trigger registry. |
| [id](./kibana-plugin-plugins-ui_actions-public.trigger.id.md) | <code>string</code> | Unique name of the trigger as identified in <code>ui_actions</code> plugin trigger registry. |
| [title](./kibana-plugin-plugins-ui_actions-public.trigger.title.md) | <code>string</code> | User friendly name of the trigger. |

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [TriggerContext](./kibana-plugin-plugins-ui_actions-public.triggercontext.md)
## TriggerContext type
<b>Signature:</b>
```typescript
export declare type TriggerContext<T> = T extends TriggerId ? TriggerContextMapping[T] : never;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [TriggerContextMapping](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.md) &gt; [""](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.__.md)
## TriggerContextMapping."" property
<b>Signature:</b>
```typescript
[DEFAULT_TRIGGER]: TriggerContext;
```

View file

@ -1,21 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [TriggerContextMapping](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.md)
## TriggerContextMapping interface
<b>Signature:</b>
```typescript
export interface TriggerContextMapping
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [""](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.__.md) | <code>TriggerContext</code> | |
| [ROW\_CLICK\_TRIGGER](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.row_click_trigger.md) | <code>RowClickContext</code> | |
| [VISUALIZE\_FIELD\_TRIGGER](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.visualize_field_trigger.md) | <code>VisualizeFieldContext</code> | |
| [VISUALIZE\_GEO\_FIELD\_TRIGGER](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.visualize_geo_field_trigger.md) | <code>VisualizeFieldContext</code> | |

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [TriggerContextMapping](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.md) &gt; [ROW\_CLICK\_TRIGGER](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.row_click_trigger.md)
## TriggerContextMapping.ROW\_CLICK\_TRIGGER property
<b>Signature:</b>
```typescript
[ROW_CLICK_TRIGGER]: RowClickContext;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [TriggerContextMapping](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.md) &gt; [VISUALIZE\_FIELD\_TRIGGER](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.visualize_field_trigger.md)
## TriggerContextMapping.VISUALIZE\_FIELD\_TRIGGER property
<b>Signature:</b>
```typescript
[VISUALIZE_FIELD_TRIGGER]: VisualizeFieldContext;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [TriggerContextMapping](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.md) &gt; [VISUALIZE\_GEO\_FIELD\_TRIGGER](./kibana-plugin-plugins-ui_actions-public.triggercontextmapping.visualize_geo_field_trigger.md)
## TriggerContextMapping.VISUALIZE\_GEO\_FIELD\_TRIGGER property
<b>Signature:</b>
```typescript
[VISUALIZE_GEO_FIELD_TRIGGER]: VisualizeFieldContext;
```

View file

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-plugins-ui\_actions-public](./kibana-plugin-plugins-ui_actions-public.md) &gt; [TriggerId](./kibana-plugin-plugins-ui_actions-public.triggerid.md)
## TriggerId type
<b>Signature:</b>
```typescript
export declare type TriggerId = keyof TriggerContextMapping;
```

View file

@ -9,7 +9,7 @@ A convenience interface used to register an action.
<b>Signature:</b>
```typescript
export interface ActionDefinition<Context extends BaseContext = {}> extends Partial<Presentable<ActionDefinitionContext<Context>>>
export interface ActionDefinition<Context extends object = object> extends Partial<Presentable<ActionDefinitionContext<Context>>>
```
## Properties
@ -17,7 +17,7 @@ export interface ActionDefinition<Context extends BaseContext = {}> extends Part
| Property | Type | Description |
| --- | --- | --- |
| [id](./kibana-plugin-plugins-ui_actions-public.uiactionsactiondefinition.id.md) | <code>string</code> | ID of the action that uniquely identifies this action in the actions registry. |
| [type](./kibana-plugin-plugins-ui_actions-public.uiactionsactiondefinition.type.md) | <code>ActionType</code> | ID of the factory for this action. Used to construct dynamic actions. |
| [type](./kibana-plugin-plugins-ui_actions-public.uiactionsactiondefinition.type.md) | <code>string</code> | ID of the factory for this action. Used to construct dynamic actions. |
## Methods

View file

@ -9,5 +9,5 @@ ID of the factory for this action. Used to construct dynamic actions.
<b>Signature:</b>
```typescript
readonly type?: ActionType;
readonly type?: string;
```

View file

@ -9,7 +9,7 @@ Represents something that can be displayed to user in UI.
<b>Signature:</b>
```typescript
export interface Presentable<Context extends object = object>
export interface Presentable<Context = unknown>
```
## Properties

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
export declare type PresentableGrouping<Context extends object = object> = Array<PresentableGroup<Context>>;
export declare type PresentableGrouping<Context = unknown> = Array<PresentableGroup<Context>>;
```

View file

@ -11,5 +11,5 @@
<b>Signature:</b>
```typescript
readonly addTriggerAction: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T, action: ActionDefinition<TriggerContextMapping[T]> | Action<TriggerContextMapping[T], "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">) => void;
readonly addTriggerAction: (triggerId: string, action: ActionDefinition) => void;
```

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
readonly attachAction: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T, actionId: string) => void;
readonly attachAction: (triggerId: string, actionId: string) => void;
```

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
readonly detachAction: (triggerId: TriggerId, actionId: string) => void;
readonly detachAction: (triggerId: string, actionId: string) => void;
```

View file

@ -12,5 +12,5 @@
<b>Signature:</b>
```typescript
readonly executeTriggerActions: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T, context: TriggerContext<T>) => Promise<void>;
readonly executeTriggerActions: (triggerId: string, context: object) => Promise<void>;
```

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
readonly getAction: <T extends ActionDefinition<{}>>(id: string) => Action<ActionContext<T>, "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">;
readonly getAction: <T extends ActionDefinition<object>>(id: string) => Action<ActionContext<T>>;
```

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
readonly getTrigger: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T) => TriggerContract<T>;
readonly getTrigger: (triggerId: string) => TriggerContract;
```

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
readonly getTriggerActions: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T) => Action<TriggerContextMapping[T], "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">[];
readonly getTriggerActions: (triggerId: string) => Action[];
```

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
readonly getTriggerCompatibleActions: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T, context: TriggerContextMapping[T]) => Promise<Action<TriggerContextMapping[T], "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">[]>;
readonly getTriggerCompatibleActions: (triggerId: string, context: object) => Promise<Action[]>;
```

View file

@ -21,19 +21,19 @@ export declare class UiActionsService
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [actions](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.actions.md) | | <code>ActionRegistry</code> | |
| [addTriggerAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.addtriggeraction.md) | | <code>&lt;T extends &quot;&quot; &#124; &quot;ROW_CLICK_TRIGGER&quot; &#124; &quot;VISUALIZE_FIELD_TRIGGER&quot; &#124; &quot;VISUALIZE_GEO_FIELD_TRIGGER&quot; &#124; &quot;FILTER_TRIGGER&quot; &#124; &quot;CONTEXT_MENU_TRIGGER&quot; &#124; &quot;PANEL_BADGE_TRIGGER&quot; &#124; &quot;PANEL_NOTIFICATION_TRIGGER&quot; &#124; &quot;SELECT_RANGE_TRIGGER&quot; &#124; &quot;VALUE_CLICK_TRIGGER&quot;&gt;(triggerId: T, action: ActionDefinition&lt;TriggerContextMapping[T]&gt; &#124; Action&lt;TriggerContextMapping[T], &quot;&quot; &#124; &quot;ACTION_VISUALIZE_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_GEO_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_LENS_FIELD&quot; &#124; &quot;ACTION_GLOBAL_APPLY_FILTER&quot; &#124; &quot;ACTION_SELECT_RANGE&quot; &#124; &quot;ACTION_VALUE_CLICK&quot; &#124; &quot;ACTION_CUSTOMIZE_PANEL&quot; &#124; &quot;ACTION_ADD_PANEL&quot; &#124; &quot;openInspector&quot; &#124; &quot;deletePanel&quot; &#124; &quot;editPanel&quot;&gt;) =&gt; void</code> | <code>addTriggerAction</code> is similar to <code>attachAction</code> as it attaches action to a trigger, but it also registers the action, if it has not been registered, yet.<code>addTriggerAction</code> also infers better typing of the <code>action</code> argument. |
| [attachAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.attachaction.md) | | <code>&lt;T extends &quot;&quot; &#124; &quot;ROW_CLICK_TRIGGER&quot; &#124; &quot;VISUALIZE_FIELD_TRIGGER&quot; &#124; &quot;VISUALIZE_GEO_FIELD_TRIGGER&quot; &#124; &quot;FILTER_TRIGGER&quot; &#124; &quot;CONTEXT_MENU_TRIGGER&quot; &#124; &quot;PANEL_BADGE_TRIGGER&quot; &#124; &quot;PANEL_NOTIFICATION_TRIGGER&quot; &#124; &quot;SELECT_RANGE_TRIGGER&quot; &#124; &quot;VALUE_CLICK_TRIGGER&quot;&gt;(triggerId: T, actionId: string) =&gt; void</code> | |
| [addTriggerAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.addtriggeraction.md) | | <code>(triggerId: string, action: ActionDefinition) =&gt; void</code> | <code>addTriggerAction</code> is similar to <code>attachAction</code> as it attaches action to a trigger, but it also registers the action, if it has not been registered, yet.<code>addTriggerAction</code> also infers better typing of the <code>action</code> argument. |
| [attachAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.attachaction.md) | | <code>(triggerId: string, actionId: string) =&gt; void</code> | |
| [clear](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.clear.md) | | <code>() =&gt; void</code> | Removes all registered triggers and actions. |
| [detachAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.detachaction.md) | | <code>(triggerId: TriggerId, actionId: string) =&gt; void</code> | |
| [executeTriggerActions](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.executetriggeractions.md) | | <code>&lt;T extends &quot;&quot; &#124; &quot;ROW_CLICK_TRIGGER&quot; &#124; &quot;VISUALIZE_FIELD_TRIGGER&quot; &#124; &quot;VISUALIZE_GEO_FIELD_TRIGGER&quot; &#124; &quot;FILTER_TRIGGER&quot; &#124; &quot;CONTEXT_MENU_TRIGGER&quot; &#124; &quot;PANEL_BADGE_TRIGGER&quot; &#124; &quot;PANEL_NOTIFICATION_TRIGGER&quot; &#124; &quot;SELECT_RANGE_TRIGGER&quot; &#124; &quot;VALUE_CLICK_TRIGGER&quot;&gt;(triggerId: T, context: TriggerContext&lt;T&gt;) =&gt; Promise&lt;void&gt;</code> | |
| [detachAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.detachaction.md) | | <code>(triggerId: string, actionId: string) =&gt; void</code> | |
| [executeTriggerActions](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.executetriggeractions.md) | | <code>(triggerId: string, context: object) =&gt; Promise&lt;void&gt;</code> | |
| [executionService](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.executionservice.md) | | <code>UiActionsExecutionService</code> | |
| [fork](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.fork.md) | | <code>() =&gt; UiActionsService</code> | "Fork" a separate instance of <code>UiActionsService</code> that inherits all existing triggers and actions, but going forward all new triggers and actions added to this instance of <code>UiActionsService</code> are only available within this instance. |
| [getAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.getaction.md) | | <code>&lt;T extends ActionDefinition&lt;{}&gt;&gt;(id: string) =&gt; Action&lt;ActionContext&lt;T&gt;, &quot;&quot; &#124; &quot;ACTION_VISUALIZE_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_GEO_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_LENS_FIELD&quot; &#124; &quot;ACTION_GLOBAL_APPLY_FILTER&quot; &#124; &quot;ACTION_SELECT_RANGE&quot; &#124; &quot;ACTION_VALUE_CLICK&quot; &#124; &quot;ACTION_CUSTOMIZE_PANEL&quot; &#124; &quot;ACTION_ADD_PANEL&quot; &#124; &quot;openInspector&quot; &#124; &quot;deletePanel&quot; &#124; &quot;editPanel&quot;&gt;</code> | |
| [getTrigger](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.gettrigger.md) | | <code>&lt;T extends &quot;&quot; &#124; &quot;ROW_CLICK_TRIGGER&quot; &#124; &quot;VISUALIZE_FIELD_TRIGGER&quot; &#124; &quot;VISUALIZE_GEO_FIELD_TRIGGER&quot; &#124; &quot;FILTER_TRIGGER&quot; &#124; &quot;CONTEXT_MENU_TRIGGER&quot; &#124; &quot;PANEL_BADGE_TRIGGER&quot; &#124; &quot;PANEL_NOTIFICATION_TRIGGER&quot; &#124; &quot;SELECT_RANGE_TRIGGER&quot; &#124; &quot;VALUE_CLICK_TRIGGER&quot;&gt;(triggerId: T) =&gt; TriggerContract&lt;T&gt;</code> | |
| [getTriggerActions](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.gettriggeractions.md) | | <code>&lt;T extends &quot;&quot; &#124; &quot;ROW_CLICK_TRIGGER&quot; &#124; &quot;VISUALIZE_FIELD_TRIGGER&quot; &#124; &quot;VISUALIZE_GEO_FIELD_TRIGGER&quot; &#124; &quot;FILTER_TRIGGER&quot; &#124; &quot;CONTEXT_MENU_TRIGGER&quot; &#124; &quot;PANEL_BADGE_TRIGGER&quot; &#124; &quot;PANEL_NOTIFICATION_TRIGGER&quot; &#124; &quot;SELECT_RANGE_TRIGGER&quot; &#124; &quot;VALUE_CLICK_TRIGGER&quot;&gt;(triggerId: T) =&gt; Action&lt;TriggerContextMapping[T], &quot;&quot; &#124; &quot;ACTION_VISUALIZE_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_GEO_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_LENS_FIELD&quot; &#124; &quot;ACTION_GLOBAL_APPLY_FILTER&quot; &#124; &quot;ACTION_SELECT_RANGE&quot; &#124; &quot;ACTION_VALUE_CLICK&quot; &#124; &quot;ACTION_CUSTOMIZE_PANEL&quot; &#124; &quot;ACTION_ADD_PANEL&quot; &#124; &quot;openInspector&quot; &#124; &quot;deletePanel&quot; &#124; &quot;editPanel&quot;&gt;[]</code> | |
| [getTriggerCompatibleActions](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.gettriggercompatibleactions.md) | | <code>&lt;T extends &quot;&quot; &#124; &quot;ROW_CLICK_TRIGGER&quot; &#124; &quot;VISUALIZE_FIELD_TRIGGER&quot; &#124; &quot;VISUALIZE_GEO_FIELD_TRIGGER&quot; &#124; &quot;FILTER_TRIGGER&quot; &#124; &quot;CONTEXT_MENU_TRIGGER&quot; &#124; &quot;PANEL_BADGE_TRIGGER&quot; &#124; &quot;PANEL_NOTIFICATION_TRIGGER&quot; &#124; &quot;SELECT_RANGE_TRIGGER&quot; &#124; &quot;VALUE_CLICK_TRIGGER&quot;&gt;(triggerId: T, context: TriggerContextMapping[T]) =&gt; Promise&lt;Action&lt;TriggerContextMapping[T], &quot;&quot; &#124; &quot;ACTION_VISUALIZE_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_GEO_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_LENS_FIELD&quot; &#124; &quot;ACTION_GLOBAL_APPLY_FILTER&quot; &#124; &quot;ACTION_SELECT_RANGE&quot; &#124; &quot;ACTION_VALUE_CLICK&quot; &#124; &quot;ACTION_CUSTOMIZE_PANEL&quot; &#124; &quot;ACTION_ADD_PANEL&quot; &#124; &quot;openInspector&quot; &#124; &quot;deletePanel&quot; &#124; &quot;editPanel&quot;&gt;[]&gt;</code> | |
| [getAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.getaction.md) | | <code>&lt;T extends ActionDefinition&lt;object&gt;&gt;(id: string) =&gt; Action&lt;ActionContext&lt;T&gt;&gt;</code> | |
| [getTrigger](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.gettrigger.md) | | <code>(triggerId: string) =&gt; TriggerContract</code> | |
| [getTriggerActions](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.gettriggeractions.md) | | <code>(triggerId: string) =&gt; Action[]</code> | |
| [getTriggerCompatibleActions](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.gettriggercompatibleactions.md) | | <code>(triggerId: string, context: object) =&gt; Promise&lt;Action[]&gt;</code> | |
| [hasAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.hasaction.md) | | <code>(actionId: string) =&gt; boolean</code> | |
| [registerAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.registeraction.md) | | <code>&lt;A extends ActionDefinition&lt;{}&gt;&gt;(definition: A) =&gt; Action&lt;ActionContext&lt;A&gt;, &quot;&quot; &#124; &quot;ACTION_VISUALIZE_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_GEO_FIELD&quot; &#124; &quot;ACTION_VISUALIZE_LENS_FIELD&quot; &#124; &quot;ACTION_GLOBAL_APPLY_FILTER&quot; &#124; &quot;ACTION_SELECT_RANGE&quot; &#124; &quot;ACTION_VALUE_CLICK&quot; &#124; &quot;ACTION_CUSTOMIZE_PANEL&quot; &#124; &quot;ACTION_ADD_PANEL&quot; &#124; &quot;openInspector&quot; &#124; &quot;deletePanel&quot; &#124; &quot;editPanel&quot;&gt;</code> | |
| [registerAction](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.registeraction.md) | | <code>&lt;A extends ActionDefinition&lt;object&gt;&gt;(definition: A) =&gt; Action&lt;ActionContext&lt;A&gt;&gt;</code> | |
| [registerTrigger](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.registertrigger.md) | | <code>(trigger: Trigger) =&gt; void</code> | |
| [triggers](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.triggers.md) | | <code>TriggerRegistry</code> | |
| [triggerToActions](./kibana-plugin-plugins-ui_actions-public.uiactionsservice.triggertoactions.md) | | <code>TriggerToActionsRegistry</code> | |

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
readonly registerAction: <A extends ActionDefinition<{}>>(definition: A) => Action<ActionContext<A>, "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">;
readonly registerAction: <A extends ActionDefinition<object>>(definition: A) => Action<ActionContext<A>>;
```

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
visualizeFieldTrigger: Trigger<'VISUALIZE_FIELD_TRIGGER'>
visualizeFieldTrigger: Trigger
```

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
visualizeGeoFieldTrigger: Trigger<'VISUALIZE_GEO_FIELD_TRIGGER'>
visualizeGeoFieldTrigger: Trigger
```

View file

@ -35,6 +35,7 @@ export const createAddBookToLibraryAction = () =>
i18n.translate('embeddableExamples.book.addToLibrary', {
defaultMessage: 'Add Book To Library',
}),
id: ACTION_ADD_BOOK_TO_LIBRARY,
type: ACTION_ADD_BOOK_TO_LIBRARY,
order: 100,
getIconType: () => 'folderCheck',

View file

@ -53,6 +53,7 @@ export const createEditBookAction = (getStartServices: () => Promise<StartServic
createAction({
getDisplayName: () =>
i18n.translate('embeddableExamples.book.edit', { defaultMessage: 'Edit Book' }),
id: ACTION_EDIT_BOOK,
type: ACTION_EDIT_BOOK,
order: 100,
getIconType: () => 'documents',

View file

@ -35,6 +35,7 @@ export const createUnlinkBookFromLibraryAction = () =>
i18n.translate('embeddableExamples.book.unlinkFromLibrary', {
defaultMessage: 'Unlink Book from Library Item',
}),
id: ACTION_UNLINK_BOOK_FROM_LIBRARY,
type: ACTION_UNLINK_BOOK_FROM_LIBRARY,
order: 100,
getIconType: () => 'folderExclamation',

View file

@ -51,21 +51,15 @@ import {
TodoRefEmbeddableFactory,
TodoRefEmbeddableFactoryDefinition,
} from './todo/todo_ref_embeddable_factory';
import { ACTION_EDIT_BOOK, createEditBookAction } from './book/edit_book_action';
import { BookEmbeddable, BOOK_EMBEDDABLE } from './book/book_embeddable';
import { createEditBookAction } from './book/edit_book_action';
import { BOOK_EMBEDDABLE } from './book/book_embeddable';
import {
BookEmbeddableFactory,
BookEmbeddableFactoryDefinition,
} from './book/book_embeddable_factory';
import { UiActionsStart } from '../../../src/plugins/ui_actions/public';
import {
ACTION_ADD_BOOK_TO_LIBRARY,
createAddBookToLibraryAction,
} from './book/add_book_to_library_action';
import {
ACTION_UNLINK_BOOK_FROM_LIBRARY,
createUnlinkBookFromLibraryAction,
} from './book/unlink_book_from_library_action';
import { createAddBookToLibraryAction } from './book/add_book_to_library_action';
import { createUnlinkBookFromLibraryAction } from './book/unlink_book_from_library_action';
export interface EmbeddableExamplesSetupDependencies {
embeddable: EmbeddableSetup;
@ -92,14 +86,6 @@ export interface EmbeddableExamplesStart {
factories: ExampleEmbeddableFactories;
}
declare module '../../../src/plugins/ui_actions/public' {
export interface ActionContextMapping {
[ACTION_EDIT_BOOK]: { embeddable: BookEmbeddable };
[ACTION_ADD_BOOK_TO_LIBRARY]: { embeddable: BookEmbeddable };
[ACTION_UNLINK_BOOK_FROM_LIBRARY]: { embeddable: BookEmbeddable };
}
}
export class EmbeddableExamplesPlugin
implements
Plugin<

View file

@ -30,6 +30,7 @@ interface StartServices {
export const createHelloWorldAction = (getStartServices: () => Promise<StartServices>) =>
createAction({
id: ACTION_HELLO_WORLD,
type: ACTION_HELLO_WORLD,
getDisplayName: () => 'Hello World!',
execute: async () => {

View file

@ -19,8 +19,8 @@
import { Plugin, CoreSetup, CoreStart } from '../../../src/core/public';
import { UiActionsSetup, UiActionsStart } from '../../../src/plugins/ui_actions/public';
import { createHelloWorldAction, ACTION_HELLO_WORLD } from './hello_world_action';
import { helloWorldTrigger, HELLO_WORLD_TRIGGER_ID } from './hello_world_trigger';
import { createHelloWorldAction } from './hello_world_action';
import { helloWorldTrigger } from './hello_world_trigger';
export interface UiActionExamplesSetupDependencies {
uiActions: UiActionsSetup;
@ -30,16 +30,6 @@ export interface UiActionExamplesStartDependencies {
uiActions: UiActionsStart;
}
declare module '../../../src/plugins/ui_actions/public' {
export interface TriggerContextMapping {
[HELLO_WORLD_TRIGGER_ID]: {};
}
export interface ActionContextMapping {
[ACTION_HELLO_WORLD]: {};
}
}
export class UiActionExamplesPlugin
implements
Plugin<void, void, UiActionExamplesSetupDependencies, UiActionExamplesStartDependencies> {

View file

@ -38,7 +38,8 @@ export const ACTION_EDIT_USER = 'ACTION_EDIT_USER';
export const ACTION_TRIGGER_PHONE_USER = 'ACTION_TRIGGER_PHONE_USER';
export const ACTION_SHOWCASE_PLUGGABILITY = 'ACTION_SHOWCASE_PLUGGABILITY';
export const showcasePluggability = createAction<typeof ACTION_SHOWCASE_PLUGGABILITY>({
export const showcasePluggability = createAction({
id: ACTION_SHOWCASE_PLUGGABILITY,
type: ACTION_SHOWCASE_PLUGGABILITY,
getDisplayName: () => 'This is pluggable! Any plugin can inject their actions here.',
execute: async (context: ActionExecutionContext) =>
@ -49,13 +50,15 @@ export interface PhoneContext {
phone: string;
}
export const makePhoneCallAction = createAction<typeof ACTION_CALL_PHONE_NUMBER>({
export const makePhoneCallAction = createAction<PhoneContext>({
id: ACTION_CALL_PHONE_NUMBER,
type: ACTION_CALL_PHONE_NUMBER,
getDisplayName: () => 'Call phone number',
execute: async (context) => alert(`Pretend calling ${context.phone}...`),
});
export const lookUpWeatherAction = createAction<typeof ACTION_TRAVEL_GUIDE>({
export const lookUpWeatherAction = createAction<CountryContext>({
id: ACTION_TRAVEL_GUIDE,
type: ACTION_TRAVEL_GUIDE,
getIconType: () => 'popout',
getDisplayName: () => 'View travel guide',
@ -68,7 +71,8 @@ export interface CountryContext {
country: string;
}
export const viewInMapsAction = createAction<typeof ACTION_VIEW_IN_MAPS>({
export const viewInMapsAction = createAction<CountryContext>({
id: ACTION_VIEW_IN_MAPS,
type: ACTION_VIEW_IN_MAPS,
getIconType: () => 'popout',
getDisplayName: () => 'View in maps',
@ -109,7 +113,8 @@ function EditUserModal({
}
export const createEditUserAction = (getOpenModal: () => Promise<OverlayStart['openModal']>) =>
createAction<typeof ACTION_EDIT_USER>({
createAction<UserContext>({
id: ACTION_EDIT_USER,
type: ACTION_EDIT_USER,
getIconType: () => 'pencil',
getDisplayName: () => 'Edit user',
@ -126,7 +131,8 @@ export interface UserContext {
}
export const createTriggerPhoneTriggerAction = (getUiActionsApi: () => Promise<UiActionsStart>) =>
createAction<typeof ACTION_TRIGGER_PHONE_USER>({
createAction<UserContext>({
id: ACTION_TRIGGER_PHONE_USER,
type: ACTION_TRIGGER_PHONE_USER,
getDisplayName: () => 'Call phone number',
shouldAutoExecute: async () => true,

View file

@ -77,7 +77,7 @@ const ActionsExplorer = ({ uiActionsApi, openModal }: Props) => {
<EuiButton
data-test-subj="addDynamicAction"
onClick={() => {
const dynamicAction = createAction<typeof ACTION_HELLO_WORLD>({
const dynamicAction = createAction({
id: `${ACTION_HELLO_WORLD}-${name}`,
type: ACTION_HELLO_WORLD,
getDisplayName: () => `Say hello to ${name}`,

View file

@ -28,15 +28,6 @@ import {
createEditUserAction,
makePhoneCallAction,
showcasePluggability,
UserContext,
CountryContext,
PhoneContext,
ACTION_EDIT_USER,
ACTION_SHOWCASE_PLUGGABILITY,
ACTION_CALL_PHONE_NUMBER,
ACTION_TRAVEL_GUIDE,
ACTION_VIEW_IN_MAPS,
ACTION_TRIGGER_PHONE_USER,
createTriggerPhoneTriggerAction,
} from './actions/actions';
import { DeveloperExamplesSetup } from '../../developer_examples/public';
@ -51,23 +42,6 @@ interface SetupDeps {
developerExamples: DeveloperExamplesSetup;
}
declare module '../../../src/plugins/ui_actions/public' {
export interface TriggerContextMapping {
[USER_TRIGGER]: UserContext;
[COUNTRY_TRIGGER]: CountryContext;
[PHONE_TRIGGER]: PhoneContext;
}
export interface ActionContextMapping {
[ACTION_EDIT_USER]: UserContext;
[ACTION_SHOWCASE_PLUGGABILITY]: {};
[ACTION_CALL_PHONE_NUMBER]: PhoneContext;
[ACTION_TRAVEL_GUIDE]: CountryContext;
[ACTION_VIEW_IN_MAPS]: CountryContext;
[ACTION_TRIGGER_PHONE_USER]: UserContext;
}
}
export class UiActionsExplorerPlugin implements Plugin<void, void, {}, StartDeps> {
public setup(core: CoreSetup<StartDeps>, deps: SetupDeps) {
deps.uiActions.registerTrigger({

View file

@ -19,7 +19,7 @@
import _ from 'lodash';
import { ActionByType, IncompatibleActionError } from '../../services/ui_actions';
import { Action, IncompatibleActionError } from '../../services/ui_actions';
import {
ViewMode,
PanelState,
@ -39,7 +39,7 @@ export interface AddToLibraryActionContext {
embeddable: IEmbeddable;
}
export class AddToLibraryAction implements ActionByType<typeof ACTION_ADD_TO_LIBRARY> {
export class AddToLibraryAction implements Action<AddToLibraryActionContext> {
public readonly type = ACTION_ADD_TO_LIBRARY;
public readonly id = ACTION_ADD_TO_LIBRARY;
public order = 15;

View file

@ -21,7 +21,7 @@ import _ from 'lodash';
import uuid from 'uuid';
import { CoreStart } from 'src/core/public';
import { ActionByType, IncompatibleActionError } from '../../services/ui_actions';
import { Action, IncompatibleActionError } from '../../services/ui_actions';
import { SavedObject } from '../../services/saved_objects';
import {
ViewMode,
@ -45,7 +45,7 @@ export interface ClonePanelActionContext {
embeddable: IEmbeddable;
}
export class ClonePanelAction implements ActionByType<typeof ACTION_CLONE_PANEL> {
export class ClonePanelAction implements Action<ClonePanelActionContext> {
public readonly type = ACTION_CLONE_PANEL;
public readonly id = ACTION_CLONE_PANEL;
public order = 45;

View file

@ -19,7 +19,7 @@
import { dashboardExpandPanelAction } from '../../dashboard_strings';
import { IEmbeddable } from '../../services/embeddable';
import { ActionByType, IncompatibleActionError } from '../../services/ui_actions';
import { Action, IncompatibleActionError } from '../../services/ui_actions';
import {
DASHBOARD_CONTAINER_TYPE,
DashboardContainer,
@ -46,7 +46,7 @@ export interface ExpandPanelActionContext {
embeddable: IEmbeddable;
}
export class ExpandPanelAction implements ActionByType<typeof ACTION_EXPAND_PANEL> {
export class ExpandPanelAction implements Action<ExpandPanelActionContext> {
public readonly type = ACTION_EXPAND_PANEL;
public readonly id = ACTION_EXPAND_PANEL;
public order = 7;

View file

@ -24,7 +24,7 @@ import { FormatFactory } from '../../../../data/common/field_formats/utils';
import { DataPublicPluginStart, exporters } from '../../services/data';
import { downloadMultipleAs } from '../../services/share';
import { Adapters, IEmbeddable } from '../../services/embeddable';
import { ActionByType } from '../../services/ui_actions';
import { Action } from '../../services/ui_actions';
import { dashboardExportCsvAction } from '../../dashboard_strings';
export const ACTION_EXPORT_CSV = 'ACTION_EXPORT_CSV';
@ -44,7 +44,7 @@ export interface ExportContext {
* This is "Export CSV" action which appears in the context
* menu of a dashboard panel.
*/
export class ExportCSVAction implements ActionByType<typeof ACTION_EXPORT_CSV> {
export class ExportCSVAction implements Action<ExportContext> {
public readonly id = ACTION_EXPORT_CSV;
public readonly type = ACTION_EXPORT_CSV;

View file

@ -19,7 +19,7 @@
import React from 'react';
import { ActionByType, IncompatibleActionError } from '../../services/ui_actions';
import { Action, IncompatibleActionError } from '../../services/ui_actions';
import { reactToUiComponent } from '../../services/kibana_react';
import {
IEmbeddable,
@ -38,7 +38,7 @@ export interface LibraryNotificationActionContext {
embeddable: IEmbeddable;
}
export class LibraryNotificationAction implements ActionByType<typeof ACTION_LIBRARY_NOTIFICATION> {
export class LibraryNotificationAction implements Action<LibraryNotificationActionContext> {
public readonly id = ACTION_LIBRARY_NOTIFICATION;
public readonly type = ACTION_LIBRARY_NOTIFICATION;
public readonly order = 1;

View file

@ -20,7 +20,7 @@
import { CoreStart } from 'src/core/public';
import { IEmbeddable, ViewMode, EmbeddableStart } from '../../services/embeddable';
import { DASHBOARD_CONTAINER_TYPE, DashboardContainer } from '../embeddable';
import { ActionByType, IncompatibleActionError } from '../../services/ui_actions';
import { Action, IncompatibleActionError } from '../../services/ui_actions';
import { openReplacePanelFlyout } from './open_replace_panel_flyout';
import { dashboardReplacePanelAction } from '../../dashboard_strings';
@ -34,7 +34,7 @@ export interface ReplacePanelActionContext {
embeddable: IEmbeddable;
}
export class ReplacePanelAction implements ActionByType<typeof ACTION_REPLACE_PANEL> {
export class ReplacePanelAction implements Action<ReplacePanelActionContext> {
public readonly type = ACTION_REPLACE_PANEL;
public readonly id = ACTION_REPLACE_PANEL;
public order = 3;

View file

@ -18,7 +18,7 @@
*/
import _ from 'lodash';
import { ActionByType, IncompatibleActionError } from '../../services/ui_actions';
import { Action, IncompatibleActionError } from '../../services/ui_actions';
import {
ViewMode,
PanelState,
@ -38,7 +38,7 @@ export interface UnlinkFromLibraryActionContext {
embeddable: IEmbeddable;
}
export class UnlinkFromLibraryAction implements ActionByType<typeof ACTION_UNLINK_FROM_LIBRARY> {
export class UnlinkFromLibraryAction implements Action<UnlinkFromLibraryActionContext> {
public readonly type = ACTION_UNLINK_FROM_LIBRARY;
public readonly id = ACTION_UNLINK_FROM_LIBRARY;
public order = 15;

View file

@ -62,27 +62,15 @@ import {
} from './services/kibana_react';
import {
ACTION_CLONE_PANEL,
ACTION_EXPAND_PANEL,
ACTION_REPLACE_PANEL,
ClonePanelAction,
ClonePanelActionContext,
createDashboardContainerByValueRenderer,
DASHBOARD_CONTAINER_TYPE,
DashboardContainerFactory,
DashboardContainerFactoryDefinition,
ExpandPanelAction,
ExpandPanelActionContext,
ReplacePanelAction,
ReplacePanelActionContext,
ACTION_UNLINK_FROM_LIBRARY,
UnlinkFromLibraryActionContext,
UnlinkFromLibraryAction,
ACTION_ADD_TO_LIBRARY,
AddToLibraryActionContext,
AddToLibraryAction,
ACTION_LIBRARY_NOTIFICATION,
LibraryNotificationActionContext,
LibraryNotificationAction,
} from './application';
import {
@ -94,11 +82,7 @@ import { createSavedDashboardLoader } from './saved_dashboards';
import { DashboardConstants } from './dashboard_constants';
import { PlaceholderEmbeddableFactory } from './application/embeddable/placeholder';
import { UrlGeneratorState } from '../../share/public';
import {
ACTION_EXPORT_CSV,
ExportContext,
ExportCSVAction,
} from './application/actions/export_csv_action';
import { ExportCSVAction } from './application/actions/export_csv_action';
import { dashboardFeatureCatalog } from './dashboard_strings';
declare module '../../share/public' {
@ -147,18 +131,6 @@ export interface DashboardStart {
DashboardContainerByValueRenderer: ReturnType<typeof createDashboardContainerByValueRenderer>;
}
declare module '../../../plugins/ui_actions/public' {
export interface ActionContextMapping {
[ACTION_EXPAND_PANEL]: ExpandPanelActionContext;
[ACTION_REPLACE_PANEL]: ReplacePanelActionContext;
[ACTION_CLONE_PANEL]: ClonePanelActionContext;
[ACTION_ADD_TO_LIBRARY]: AddToLibraryActionContext;
[ACTION_UNLINK_FROM_LIBRARY]: UnlinkFromLibraryActionContext;
[ACTION_LIBRARY_NOTIFICATION]: LibraryNotificationActionContext;
[ACTION_EXPORT_CSV]: ExportContext;
}
}
export class DashboardPlugin
implements
Plugin<DashboardSetup, DashboardStart, DashboardSetupDependencies, DashboardStartDependencies> {

View file

@ -18,7 +18,7 @@
*/
export {
ActionByType,
Action,
IncompatibleActionError,
UiActionsSetup,
UiActionsStart,

View file

@ -19,7 +19,7 @@
import { i18n } from '@kbn/i18n';
import { toMountPoint } from '../../../kibana_react/public';
import { ActionByType, createAction, IncompatibleActionError } from '../../../ui_actions/public';
import { Action, createAction, IncompatibleActionError } from '../../../ui_actions/public';
import { getOverlays, getIndexPatterns } from '../services';
import { applyFiltersPopover } from '../ui/apply_filters';
import { Filter, FilterManager, TimefilterContract, esFilters } from '..';
@ -41,8 +41,8 @@ async function isCompatible(context: ApplyGlobalFilterActionContext) {
export function createFilterAction(
filterManager: FilterManager,
timeFilter: TimefilterContract
): ActionByType<typeof ACTION_GLOBAL_APPLY_FILTER> {
return createAction<typeof ACTION_GLOBAL_APPLY_FILTER>({
): Action {
return createAction({
type: ACTION_GLOBAL_APPLY_FILTER,
id: ACTION_GLOBAL_APPLY_FILTER,
order: 100,

View file

@ -29,12 +29,16 @@ import {
} from '../../../public';
import { dataPluginMock } from '../../../public/mocks';
import { setIndexPatterns, setSearchService } from '../../../public/services';
import { TriggerContextMapping } from '../../../../ui_actions/public';
describe('brushEvent', () => {
const DAY_IN_MS = 24 * 60 * 60 * 1000;
const JAN_01_2014 = 1388559600000;
let baseEvent: TriggerContextMapping['SELECT_RANGE_TRIGGER']['data'];
let baseEvent: {
table: any;
column: number;
range: number[];
timeFieldName?: string;
};
const mockField = {
name: 'time',

View file

@ -18,7 +18,7 @@
*/
import { Datatable } from 'src/plugins/expressions/public';
import { ActionByType, createAction, UiActionsStart } from '../../../../plugins/ui_actions/public';
import { Action, createAction, UiActionsStart } from '../../../../plugins/ui_actions/public';
import { APPLY_FILTER_TRIGGER } from '../triggers';
import { createFiltersFromRangeSelectAction } from './filters/create_filters_from_range_select';
@ -38,8 +38,8 @@ export const ACTION_SELECT_RANGE = 'ACTION_SELECT_RANGE';
export function createSelectRangeAction(
getStartServices: () => { uiActions: UiActionsStart }
): ActionByType<typeof ACTION_SELECT_RANGE> {
return createAction<typeof ACTION_SELECT_RANGE>({
): Action {
return createAction({
type: ACTION_SELECT_RANGE,
id: ACTION_SELECT_RANGE,
shouldAutoExecute: async () => true,

View file

@ -18,7 +18,7 @@
*/
import { Datatable } from 'src/plugins/expressions/public';
import { ActionByType, createAction, UiActionsStart } from '../../../../plugins/ui_actions/public';
import { Action, createAction, UiActionsStart } from '../../../../plugins/ui_actions/public';
import { APPLY_FILTER_TRIGGER } from '../triggers';
import { createFiltersFromValueClickAction } from './filters/create_filters_from_value_click';
import type { Filter } from '../../common/es_query/filters';
@ -44,8 +44,8 @@ export interface ValueClickContext {
export function createValueClickAction(
getStartServices: () => { uiActions: UiActionsStart }
): ActionByType<typeof ACTION_VALUE_CLICK> {
return createAction<typeof ACTION_VALUE_CLICK>({
): Action {
return createAction({
type: ACTION_VALUE_CLICK,
id: ACTION_VALUE_CLICK,
shouldAutoExecute: async () => true,

View file

@ -54,11 +54,6 @@ import {
createFilterAction,
createFiltersFromValueClickAction,
createFiltersFromRangeSelectAction,
ApplyGlobalFilterActionContext,
ACTION_SELECT_RANGE,
ACTION_VALUE_CLICK,
SelectRangeActionContext,
ValueClickActionContext,
createValueClickAction,
createSelectRangeAction,
} from './actions';
@ -67,19 +62,6 @@ import { SavedObjectsClientPublicToCommon } from './index_patterns';
import { getIndexPatternLoad } from './index_patterns/expressions';
import { UsageCollectionSetup } from '../../usage_collection/public';
import { getTableViewDescription } from './utils/table_inspector_view';
import { TriggerId } from '../../ui_actions/public';
declare module '../../ui_actions/public' {
export interface TriggerContextMapping {
[APPLY_FILTER_TRIGGER]: ApplyGlobalFilterActionContext;
}
export interface ActionContextMapping {
[ACTION_GLOBAL_APPLY_FILTER]: ApplyGlobalFilterActionContext;
[ACTION_SELECT_RANGE]: SelectRangeActionContext;
[ACTION_VALUE_CLICK]: ValueClickActionContext;
}
}
export class DataPublicPlugin
implements
@ -126,14 +108,14 @@ export class DataPublicPlugin
);
uiActions.addTriggerAction(
'SELECT_RANGE_TRIGGER' as TriggerId,
'SELECT_RANGE_TRIGGER',
createSelectRangeAction(() => ({
uiActions: startServices().plugins.uiActions,
}))
);
uiActions.addTriggerAction(
'VALUE_CLICK_TRIGGER' as TriggerId,
'VALUE_CLICK_TRIGGER',
createValueClickAction(() => ({
uiActions: startServices().plugins.uiActions,
}))

View file

@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n';
import { Trigger } from '../../../ui_actions/public';
export const APPLY_FILTER_TRIGGER = 'FILTER_TRIGGER';
export const applyFilterTrigger: Trigger<'FILTER_TRIGGER'> = {
export const applyFilterTrigger: Trigger = {
id: APPLY_FILTER_TRIGGER,
title: i18n.translate('data.triggers.applyFilterTitle', {
defaultMessage: 'Apply filter',

View file

@ -38,7 +38,7 @@ import { DataViewRow, DataViewColumn } from '../types';
import { IUiSettingsClient } from '../../../../../../core/public';
import { Datatable, DatatableColumn } from '../../../../../expressions/public';
import { FieldFormatsStart } from '../../../field_formats';
import { TriggerId, UiActionsStart } from '../../../../../ui_actions/public';
import { UiActionsStart } from '../../../../../ui_actions/public';
interface DataTableFormatState {
columns: DataViewColumn[];
@ -112,7 +112,7 @@ export class DataTableFormat extends Component<DataTableFormatProps, DataTableFo
onClick={() => {
const value = table.rows[rowIndex][column.id];
const eventData = { table, column: columnIndex, row: rowIndex, value };
uiActions.executeTriggerActions('VALUE_CLICK_TRIGGER' as TriggerId, {
uiActions.executeTriggerActions('VALUE_CLICK_TRIGGER', {
data: { data: [eventData] },
});
}}
@ -145,7 +145,7 @@ export class DataTableFormat extends Component<DataTableFormatProps, DataTableFo
onClick={() => {
const value = table.rows[rowIndex][column.id];
const eventData = { table, column: columnIndex, row: rowIndex, value };
uiActions.executeTriggerActions('VALUE_CLICK_TRIGGER' as TriggerId, {
uiActions.executeTriggerActions('VALUE_CLICK_TRIGGER', {
data: { data: [eventData], negate: true },
});
}}

View file

@ -18,44 +18,13 @@
*/
import { UiActionsSetup } from '../../ui_actions/public';
import {
ACTION_ADD_PANEL,
ACTION_CUSTOMIZE_PANEL,
ACTION_EDIT_PANEL,
ACTION_INSPECT_PANEL,
CONTEXT_MENU_TRIGGER,
contextMenuTrigger,
EmbeddableContext,
PANEL_BADGE_TRIGGER,
PANEL_NOTIFICATION_TRIGGER,
panelBadgeTrigger,
panelNotificationTrigger,
RangeSelectContext,
REMOVE_PANEL_ACTION,
SELECT_RANGE_TRIGGER,
selectRangeTrigger,
ValueClickContext,
VALUE_CLICK_TRIGGER,
valueClickTrigger,
} from './lib';
declare module '../../ui_actions/public' {
export interface TriggerContextMapping {
[CONTEXT_MENU_TRIGGER]: EmbeddableContext;
[PANEL_BADGE_TRIGGER]: EmbeddableContext;
[PANEL_NOTIFICATION_TRIGGER]: EmbeddableContext;
[SELECT_RANGE_TRIGGER]: RangeSelectContext;
[VALUE_CLICK_TRIGGER]: ValueClickContext;
}
export interface ActionContextMapping {
[ACTION_CUSTOMIZE_PANEL]: EmbeddableContext;
[ACTION_ADD_PANEL]: EmbeddableContext;
[ACTION_INSPECT_PANEL]: EmbeddableContext;
[REMOVE_PANEL_ACTION]: EmbeddableContext;
[ACTION_EDIT_PANEL]: EmbeddableContext;
}
}
/**
* This method initializes Embeddable plugin with initial set of
* triggers and actions.

View file

@ -25,7 +25,6 @@ import { RenderCompleteDispatcher } from '../../../../kibana_utils/public';
import { Adapters } from '../types';
import { IContainer } from '../containers';
import { EmbeddableOutput, IEmbeddable } from './i_embeddable';
import { TriggerContextMapping } from '../ui_actions';
import { EmbeddableInput, ViewMode } from '../../../common/types';
function getPanelTitle(input: EmbeddableInput, output: EmbeddableOutput) {
@ -248,7 +247,7 @@ export abstract class Embeddable<
this.onResetInput(newInput);
}
public supportedTriggers(): Array<keyof TriggerContextMapping> {
public supportedTriggers(): string[] {
return [];
}
}

View file

@ -20,7 +20,6 @@
import { Observable } from 'rxjs';
import { Adapters } from '../types';
import { IContainer } from '../containers/i_container';
import { TriggerContextMapping } from '../../../../ui_actions/public';
import { EmbeddableInput } from '../../../common/types';
export interface EmbeddableError {
@ -173,5 +172,5 @@ export interface IEmbeddable<
/**
* List of triggers that this embeddable will execute.
*/
supportedTriggers(): Array<keyof TriggerContextMapping>;
supportedTriggers(): string[];
}

View file

@ -24,7 +24,7 @@ import { mountWithIntl, nextTick } from '@kbn/test/jest';
import { findTestSubject } from '@elastic/eui/lib/test';
import { I18nProvider } from '@kbn/i18n/react';
import { CONTEXT_MENU_TRIGGER } from '../triggers';
import { Action, UiActionsStart, ActionType } from '../../../../ui_actions/public';
import { Action, UiActionsStart } from '../../../../ui_actions/public';
import { Trigger, ViewMode } from '../types';
import { isErrorEmbeddable } from '../embeddables';
import { EmbeddablePanel } from './embeddable_panel';
@ -216,7 +216,7 @@ const renderInEditModeAndOpenContextMenu = async (
test('HelloWorldContainer in edit mode hides disabledActions', async () => {
const action = {
id: 'FOO',
type: 'FOO' as ActionType,
type: 'FOO',
getIconType: () => undefined,
getDisplayName: () => 'foo',
isCompatible: async () => true,
@ -252,7 +252,7 @@ test('HelloWorldContainer in edit mode hides disabledActions', async () => {
test('HelloWorldContainer hides disabled badges', async () => {
const action = {
id: 'BAR',
type: 'BAR' as ActionType,
type: 'BAR',
getIconType: () => undefined,
getDisplayName: () => 'bar',
isCompatible: async () => true,

View file

@ -17,16 +17,15 @@
* under the License.
*/
import { createAction, ActionType } from '../../ui_actions';
import { createAction } from '../../ui_actions';
import { ViewMode } from '../../types';
import { IEmbeddable } from '../..';
// Casting to ActionType is a hack - in a real situation use
// declare module and add this id to ActionContextMapping.
export const EDIT_MODE_ACTION = 'EDIT_MODE_ACTION' as ActionType;
export const EDIT_MODE_ACTION = 'EDIT_MODE_ACTION';
export function createEditModeAction() {
return createAction<typeof EDIT_MODE_ACTION>({
return createAction({
id: EDIT_MODE_ACTION,
type: EDIT_MODE_ACTION,
getDisplayName: () => 'I only show up in edit mode',
isCompatible: async (context: { embeddable: IEmbeddable }) =>

View file

@ -17,12 +17,10 @@
* under the License.
*/
import { IncompatibleActionError, ActionType, ActionDefinitionByType } from '../../ui_actions';
import { IncompatibleActionError, Action } from '../../ui_actions';
import { EmbeddableInput, Embeddable, EmbeddableOutput, IEmbeddable } from '../../embeddables';
// Casting to ActionType is a hack - in a real situation use
// declare module and add this id to ActionContextMapping.
export const SAY_HELLO_ACTION = 'SAY_HELLO_ACTION' as ActionType;
export const SAY_HELLO_ACTION = 'SAY_HELLO_ACTION';
export interface FullNameEmbeddableOutput extends EmbeddableOutput {
fullName: string;
@ -42,7 +40,7 @@ export interface SayHelloActionContext {
message?: string;
}
export class SayHelloAction implements ActionDefinitionByType<typeof SAY_HELLO_ACTION> {
export class SayHelloAction implements Action<SayHelloActionContext> {
public readonly type = SAY_HELLO_ACTION;
public readonly id = SAY_HELLO_ACTION;

View file

@ -18,16 +18,14 @@
*/
import React from 'react';
import { EuiFlyoutBody } from '@elastic/eui';
import { createAction, IncompatibleActionError, ActionType } from '../../ui_actions';
import { createAction, IncompatibleActionError } from '../../ui_actions';
import { CoreStart } from '../../../../../../core/public';
import { toMountPoint } from '../../../../../kibana_react/public';
import { Embeddable, EmbeddableInput } from '../../embeddables';
import { GetMessageModal } from './get_message_modal';
import { FullNameEmbeddableOutput, hasFullNameOutput } from './say_hello_action';
// Casting to ActionType is a hack - in a real situation use
// declare module and add this id to ActionContextMapping.
export const ACTION_SEND_MESSAGE = 'ACTION_SEND_MESSAGE' as ActionType;
export const ACTION_SEND_MESSAGE = 'ACTION_SEND_MESSAGE';
interface ActionContext {
embeddable: Embeddable<EmbeddableInput, FullNameEmbeddableOutput>;
@ -44,7 +42,8 @@ export function createSendMessageAction(overlays: CoreStart['overlays']) {
overlays.openFlyout(toMountPoint(<EuiFlyoutBody>{content}</EuiFlyoutBody>));
};
return createAction<typeof ACTION_SEND_MESSAGE>({
return createAction<ActionContext>({
id: ACTION_SEND_MESSAGE,
type: ACTION_SEND_MESSAGE,
getDisplayName: () => 'Send message',
isCompatible,

View file

@ -24,13 +24,6 @@ import { EuiButton } from '@elastic/eui';
import * as Rx from 'rxjs';
import { UiActionsStart } from '../../../../../../ui_actions/public';
import { ContactCardEmbeddable, CONTACT_USER_TRIGGER } from './contact_card_embeddable';
import { EmbeddableContext } from '../../../triggers';
declare module '../../../../../../ui_actions/public' {
export interface TriggerContextMapping {
[CONTACT_USER_TRIGGER]: EmbeddableContext;
}
}
interface Props {
embeddable: ContactCardEmbeddable;

View file

@ -56,7 +56,7 @@ export type ChartActionContext<T extends IEmbeddable = IEmbeddable> =
| RowClickContext;
export const CONTEXT_MENU_TRIGGER = 'CONTEXT_MENU_TRIGGER';
export const contextMenuTrigger: Trigger<'CONTEXT_MENU_TRIGGER'> = {
export const contextMenuTrigger: Trigger = {
id: CONTEXT_MENU_TRIGGER,
title: i18n.translate('embeddableApi.contextMenuTrigger.title', {
defaultMessage: 'Context menu',
@ -67,7 +67,7 @@ export const contextMenuTrigger: Trigger<'CONTEXT_MENU_TRIGGER'> = {
};
export const PANEL_BADGE_TRIGGER = 'PANEL_BADGE_TRIGGER';
export const panelBadgeTrigger: Trigger<'PANEL_BADGE_TRIGGER'> = {
export const panelBadgeTrigger: Trigger = {
id: PANEL_BADGE_TRIGGER,
title: i18n.translate('embeddableApi.panelBadgeTrigger.title', {
defaultMessage: 'Panel badges',
@ -78,7 +78,7 @@ export const panelBadgeTrigger: Trigger<'PANEL_BADGE_TRIGGER'> = {
};
export const PANEL_NOTIFICATION_TRIGGER = 'PANEL_NOTIFICATION_TRIGGER';
export const panelNotificationTrigger: Trigger<'PANEL_NOTIFICATION_TRIGGER'> = {
export const panelNotificationTrigger: Trigger = {
id: PANEL_NOTIFICATION_TRIGGER,
title: i18n.translate('embeddableApi.panelNotificationTrigger.title', {
defaultMessage: 'Panel notifications',
@ -89,7 +89,7 @@ export const panelNotificationTrigger: Trigger<'PANEL_NOTIFICATION_TRIGGER'> = {
};
export const SELECT_RANGE_TRIGGER = 'SELECT_RANGE_TRIGGER';
export const selectRangeTrigger: Trigger<'SELECT_RANGE_TRIGGER'> = {
export const selectRangeTrigger: Trigger = {
id: SELECT_RANGE_TRIGGER,
title: i18n.translate('embeddableApi.selectRangeTrigger.title', {
defaultMessage: 'Range selection',
@ -100,7 +100,7 @@ export const selectRangeTrigger: Trigger<'SELECT_RANGE_TRIGGER'> = {
};
export const VALUE_CLICK_TRIGGER = 'VALUE_CLICK_TRIGGER';
export const valueClickTrigger: Trigger<'VALUE_CLICK_TRIGGER'> = {
export const valueClickTrigger: Trigger = {
id: VALUE_CLICK_TRIGGER,
title: i18n.translate('embeddableApi.valueClickTrigger.title', {
defaultMessage: 'Single click',

View file

@ -215,7 +215,7 @@ export const CONTEXT_MENU_TRIGGER = "CONTEXT_MENU_TRIGGER";
// Warning: (ae-missing-release-tag) "contextMenuTrigger" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const contextMenuTrigger: Trigger<'CONTEXT_MENU_TRIGGER'>;
export const contextMenuTrigger: Trigger;
// Warning: (ae-missing-release-tag) "defaultEmbeddableFactoryProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@ -298,10 +298,8 @@ export abstract class Embeddable<TEmbeddableInput extends EmbeddableInput = Embe
static runtimeId: number;
// (undocumented)
readonly runtimeId: number;
// Warning: (ae-forgotten-export) The symbol "TriggerContextMapping" needs to be exported by the entry point index.d.ts
//
// (undocumented)
supportedTriggers(): Array<keyof TriggerContextMapping>;
supportedTriggers(): string[];
// (undocumented)
abstract readonly type: string;
// (undocumented)
@ -663,7 +661,7 @@ export interface IEmbeddable<I extends EmbeddableInput = EmbeddableInput, O exte
reload(): void;
render(domNode: HTMLElement | Element): void;
readonly runtimeId?: number;
supportedTriggers(): Array<keyof TriggerContextMapping>;
supportedTriggers(): string[];
readonly type: string;
updateInput(changes: Partial<I>): void;
}
@ -741,7 +739,7 @@ export const PANEL_NOTIFICATION_TRIGGER = "PANEL_NOTIFICATION_TRIGGER";
// Warning: (ae-missing-release-tag) "panelBadgeTrigger" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const panelBadgeTrigger: Trigger<'PANEL_BADGE_TRIGGER'>;
export const panelBadgeTrigger: Trigger;
// Warning: (ae-missing-release-tag) "PanelNotFoundError" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@ -755,7 +753,7 @@ export class PanelNotFoundError extends Error {
// Warning: (ae-missing-release-tag) "panelNotificationTrigger" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const panelNotificationTrigger: Trigger<'PANEL_NOTIFICATION_TRIGGER'>;
export const panelNotificationTrigger: Trigger;
// Warning: (ae-missing-release-tag) "PanelState" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//

View file

@ -18,14 +18,12 @@
*/
import { ActionExecutionContext, createAction } from '../../../ui_actions/public';
import { ActionType } from '../types';
import { defaultTrigger } from '../triggers';
const sayHelloAction = createAction({
// Casting to ActionType is a hack - in a real situation use
// declare module and add this id to ActionContextMapping.
type: 'test' as ActionType,
isCompatible: ({ amICompatible }: { amICompatible: boolean }) => Promise.resolve(amICompatible),
const sayHelloAction = createAction<{ amICompatible: boolean }>({
id: 'test',
type: 'test',
isCompatible: ({ amICompatible }) => Promise.resolve(amICompatible),
execute: () => Promise.resolve(),
});
@ -33,7 +31,7 @@ test('action is not compatible based on context', async () => {
const isCompatible = await sayHelloAction.isCompatible({
amICompatible: false,
trigger: defaultTrigger,
} as ActionExecutionContext);
} as ActionExecutionContext<{ amICompatible: boolean }>);
expect(isCompatible).toBe(false);
});
@ -41,6 +39,6 @@ test('action is compatible based on context', async () => {
const isCompatible = await sayHelloAction.isCompatible({
amICompatible: true,
trigger: defaultTrigger,
} as ActionExecutionContext);
} as ActionExecutionContext<{ amICompatible: boolean }>);
expect(isCompatible).toBe(true);
});

View file

@ -18,15 +18,9 @@
*/
import { UiComponent } from 'src/plugins/kibana_utils/public';
import { ActionType, ActionContextMapping, BaseContext } from '../types';
import { Presentable } from '../util/presentable';
import { Trigger } from '../triggers';
export type ActionByType<T extends ActionType> = Action<ActionContextMapping[T], T>;
export type ActionDefinitionByType<T extends ActionType> = ActionDefinition<
ActionContextMapping[T]
>;
/**
* During action execution we can provide additional information,
* for example, trigger, that caused the action execution
@ -41,19 +35,18 @@ export interface ActionExecutionMeta {
/**
* Action methods are executed with Context from trigger + {@link ActionExecutionMeta}
*/
export type ActionExecutionContext<Context extends BaseContext = BaseContext> = Context &
ActionExecutionMeta;
export type ActionExecutionContext<Context extends object = object> = Context & ActionExecutionMeta;
/**
* Simplified action context for {@link ActionDefinition}
* When defining action consumer may use either it's own Context
* or an ActionExecutionContext<Context> to get access to {@link ActionExecutionMeta} params
*/
export type ActionDefinitionContext<Context extends BaseContext = BaseContext> =
export type ActionDefinitionContext<Context extends object = object> =
| Context
| ActionExecutionContext<Context>;
export interface Action<Context extends BaseContext = {}, T = ActionType>
export interface Action<Context extends object = object>
extends Partial<Presentable<ActionExecutionContext<Context>>> {
/**
* Determined the order when there is more than one action matched to a trigger.
@ -69,7 +62,7 @@ export interface Action<Context extends BaseContext = {}, T = ActionType>
/**
* The action type is what determines the context shape.
*/
readonly type: T;
readonly type: string;
/**
* Optional EUI icon type that can be displayed along with the title.
@ -117,7 +110,7 @@ export interface Action<Context extends BaseContext = {}, T = ActionType>
/**
* A convenience interface used to register an action.
*/
export interface ActionDefinition<Context extends BaseContext = {}>
export interface ActionDefinition<Context extends object = object>
extends Partial<Presentable<ActionDefinitionContext<Context>>> {
/**
* ID of the action that uniquely identifies this action in the actions registry.
@ -127,7 +120,7 @@ export interface ActionDefinition<Context extends BaseContext = {}>
/**
* ID of the factory for this action. Used to construct dynamic actions.
*/
readonly type?: ActionType;
readonly type?: string;
/**
* Returns a promise that resolves to true if this item is compatible given

View file

@ -22,7 +22,6 @@ import React from 'react';
import { Action, ActionContext as Context, ActionDefinition } from './action';
import { Presentable, PresentableGrouping } from '../util/presentable';
import { uiToReactComponent } from '../../../kibana_react/public';
import { ActionType } from '../types';
/**
* @internal
@ -32,7 +31,7 @@ export class ActionInternal<A extends ActionDefinition = ActionDefinition>
constructor(public readonly definition: A) {}
public readonly id: string = this.definition.id;
public readonly type: ActionType = this.definition.type || '';
public readonly type: string = this.definition.type || '';
public readonly order: number = this.definition.order || 0;
public readonly MenuItem? = this.definition.MenuItem;
public readonly ReactMenuItem? = this.MenuItem ? uiToReactComponent(this.MenuItem) : undefined;

View file

@ -17,25 +17,16 @@
* under the License.
*/
import { ActionContextMapping } from '../types';
import { ActionByType } from './action';
import { ActionType } from '../types';
import { ActionDefinition } from './action';
import { ActionDefinition, Action } from './action';
interface ActionDefinitionByType<T extends ActionType>
extends Omit<ActionDefinition<ActionContextMapping[T]>, 'id'> {
id?: string;
}
export function createAction<T extends ActionType>(
action: ActionDefinitionByType<T>
): ActionByType<T> {
export function createAction<Context extends object = object>(
action: ActionDefinition<Context>
): Action<Context> {
return {
getIconType: () => undefined,
order: 0,
id: action.type,
isCompatible: () => Promise.resolve(true),
getDisplayName: () => '',
...action,
} as ActionByType<T>;
} as Action<Context>;
}

View file

@ -34,6 +34,7 @@ const createTestAction = ({
grouping?: PresentableGrouping;
}) =>
createAction({
id: type as any, // mapping doesn't matter for this test
type: type as any, // mapping doesn't matter for this test
getDisplayName: () => dispayName,
order,

View file

@ -24,7 +24,6 @@ import { i18n } from '@kbn/i18n';
import { uiToReactComponent } from '../../../kibana_react/public';
import { Action, ActionExecutionContext } from '../actions';
import { Trigger } from '../triggers';
import { BaseContext } from '../types';
export const defaultTitle = i18n.translate('uiActions.actionPanel.title', {
defaultMessage: 'Options',
@ -34,7 +33,7 @@ export const txtMore = i18n.translate('uiActions.actionPanel.more', {
defaultMessage: 'More',
});
interface ActionWithContext<Context extends BaseContext = BaseContext> {
interface ActionWithContext<Context extends object = object> {
action: Action<Context>;
context: Context;

View file

@ -39,7 +39,6 @@ export {
} from './util';
export {
Trigger,
TriggerContext,
VISUALIZE_FIELD_TRIGGER,
visualizeFieldTrigger,
VISUALIZE_GEO_FIELD_TRIGGER,
@ -49,18 +48,9 @@ export {
RowClickContext,
} from './triggers';
export {
TriggerContextMapping,
TriggerId,
ActionContextMapping,
ActionType,
VisualizeFieldContext,
ACTION_VISUALIZE_FIELD,
ACTION_VISUALIZE_GEO_FIELD,
ACTION_VISUALIZE_LENS_FIELD,
} from './types';
export {
ActionByType,
ActionDefinitionByType,
ActionExecutionContext,
ActionExecutionMeta,
} from './actions';
export { ActionExecutionContext, ActionExecutionMeta } from './actions';

View file

@ -21,7 +21,6 @@ import { CoreSetup, CoreStart } from 'src/core/public';
import { UiActionsSetup, UiActionsStart } from '.';
import { plugin as pluginInitializer } from '.';
import { coreMock } from '../../../core/public/mocks';
import { TriggerId } from './types';
export type Setup = jest.Mocked<UiActionsSetup>;
export type Start = jest.Mocked<UiActionsStart>;
@ -50,7 +49,7 @@ const createStartContract = (): Start => {
getAction: jest.fn(),
hasAction: jest.fn(),
getTrigger: jest.fn(),
getTriggerActions: jest.fn((id: TriggerId) => []),
getTriggerActions: jest.fn((id: string) => []),
getTriggerCompatibleActions: jest.fn(),
registerAction: jest.fn(),
registerTrigger: jest.fn(),

View file

@ -15,11 +15,10 @@ import { PublicMethodsOf } from '@kbn/utility-types';
import React from 'react';
import { UiComponent } from 'src/plugins/kibana_utils/public';
// Warning: (ae-forgotten-export) The symbol "BaseContext" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "Action" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface Action<Context extends BaseContext = {}, T = ActionType> extends Partial<UiActionsPresentable<ActionExecutionContext<Context>>> {
export interface Action<Context extends object = object> extends Partial<UiActionsPresentable<ActionExecutionContext<Context>>> {
execute(context: ActionExecutionContext<Context>): Promise<void>;
getDisplayName(context: ActionExecutionContext<Context>): string;
getHref?(context: ActionExecutionContext<Context>): Promise<string | undefined>;
@ -31,7 +30,7 @@ export interface Action<Context extends BaseContext = {}, T = ActionType> extend
}>;
order?: number;
shouldAutoExecute?(context: ActionExecutionContext<Context>): Promise<boolean>;
readonly type: T;
readonly type: string;
}
// Warning: (ae-missing-release-tag) "ACTION_VISUALIZE_FIELD" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
@ -49,36 +48,10 @@ export const ACTION_VISUALIZE_GEO_FIELD = "ACTION_VISUALIZE_GEO_FIELD";
// @public (undocumented)
export const ACTION_VISUALIZE_LENS_FIELD = "ACTION_VISUALIZE_LENS_FIELD";
// Warning: (ae-missing-release-tag) "ActionByType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type ActionByType<T extends ActionType> = Action<ActionContextMapping[T], T>;
// Warning: (ae-missing-release-tag) "ActionContextMapping" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface ActionContextMapping {
// Warning: (ae-forgotten-export) The symbol "DEFAULT_ACTION" needs to be exported by the entry point index.d.ts
//
// (undocumented)
[DEFAULT_ACTION]: BaseContext;
// (undocumented)
[ACTION_VISUALIZE_FIELD]: VisualizeFieldContext;
// (undocumented)
[ACTION_VISUALIZE_GEO_FIELD]: VisualizeFieldContext;
// (undocumented)
[ACTION_VISUALIZE_LENS_FIELD]: VisualizeFieldContext;
}
// Warning: (ae-missing-release-tag) "ActionDefinitionByType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type ActionDefinitionByType<T extends ActionType> = UiActionsActionDefinition<ActionContextMapping[T]>;
// Warning: (ae-missing-release-tag) "ActionExecutionContext" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export type ActionExecutionContext<Context extends BaseContext = BaseContext> = Context & ActionExecutionMeta;
export type ActionExecutionContext<Context extends object = object> = Context & ActionExecutionMeta;
// Warning: (ae-missing-release-tag) "ActionExecutionMeta" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@ -87,22 +60,16 @@ export interface ActionExecutionMeta {
trigger: Trigger;
}
// Warning: (ae-missing-release-tag) "ActionType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type ActionType = keyof ActionContextMapping;
// Warning: (ae-forgotten-export) The symbol "BuildContextMenuParams" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "buildContextMenuForActions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export function buildContextMenuForActions({ actions, title, closeMenu, }: BuildContextMenuParams): Promise<EuiContextMenuPanelDescriptor[]>;
// Warning: (ae-forgotten-export) The symbol "ActionDefinitionByType" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "createAction" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export function createAction<T extends ActionType>(action: ActionDefinitionByType_2<T>): ActionByType<T>;
export function createAction<Context extends object = object>(action: UiActionsActionDefinition<Context>): Action<Context>;
// Warning: (ae-missing-release-tag) "IncompatibleActionError" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@ -142,61 +109,34 @@ export interface RowClickContext {
// Warning: (ae-missing-release-tag) "rowClickTrigger" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const rowClickTrigger: Trigger<'ROW_CLICK_TRIGGER'>;
export const rowClickTrigger: Trigger;
// Warning: (ae-missing-release-tag) "Trigger" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export interface Trigger<ID extends TriggerId = TriggerId> {
export interface Trigger {
description?: string;
id: ID;
id: string;
title?: string;
}
// Warning: (ae-missing-release-tag) "TriggerContext" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type TriggerContext<T> = T extends TriggerId ? TriggerContextMapping[T] : never;
// Warning: (ae-missing-release-tag) "TriggerContextMapping" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface TriggerContextMapping {
// Warning: (ae-forgotten-export) The symbol "DEFAULT_TRIGGER" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "TriggerContext" needs to be exported by the entry point index.d.ts
//
// (undocumented)
[DEFAULT_TRIGGER]: TriggerContext_2;
// (undocumented)
[ROW_CLICK_TRIGGER]: RowClickContext;
// (undocumented)
[VISUALIZE_FIELD_TRIGGER]: VisualizeFieldContext;
// (undocumented)
[VISUALIZE_GEO_FIELD_TRIGGER]: VisualizeFieldContext;
}
// Warning: (ae-missing-release-tag) "TriggerId" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type TriggerId = keyof TriggerContextMapping;
// Warning: (ae-forgotten-export) The symbol "ActionDefinitionContext" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "ActionDefinition" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export interface UiActionsActionDefinition<Context extends BaseContext = {}> extends Partial<UiActionsPresentable<ActionDefinitionContext<Context>>> {
export interface UiActionsActionDefinition<Context extends object = object> extends Partial<UiActionsPresentable<ActionDefinitionContext<Context>>> {
execute(context: ActionDefinitionContext<Context>): Promise<void>;
getHref?(context: ActionDefinitionContext<Context>): Promise<string | undefined>;
readonly id: string;
isCompatible?(context: ActionDefinitionContext<Context>): Promise<boolean>;
shouldAutoExecute?(context: ActionDefinitionContext<Context>): Promise<boolean>;
readonly type?: ActionType;
readonly type?: string;
}
// Warning: (ae-missing-release-tag) "Presentable" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export interface UiActionsPresentable<Context extends object = object> {
export interface UiActionsPresentable<Context = unknown> {
getDisplayName(context: Context): string;
getDisplayNameTooltip(context: Context): string;
getHref?(context: Context): Promise<string | undefined>;
@ -214,7 +154,7 @@ export interface UiActionsPresentable<Context extends object = object> {
// Warning: (ae-missing-release-tag) "PresentableGrouping" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type UiActionsPresentableGrouping<Context extends object = object> = Array<PresentableGroup<Context>>;
export type UiActionsPresentableGrouping<Context = unknown> = Array<PresentableGroup<Context>>;
// Warning: (ae-missing-release-tag) "UiActionsService" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@ -225,35 +165,35 @@ export class UiActionsService {
//
// (undocumented)
protected readonly actions: ActionRegistry;
readonly addTriggerAction: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T, action: UiActionsActionDefinition<TriggerContextMapping[T]> | Action<TriggerContextMapping[T], "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">) => void;
readonly addTriggerAction: (triggerId: string, action: UiActionsActionDefinition) => void;
// (undocumented)
readonly attachAction: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T, actionId: string) => void;
readonly attachAction: (triggerId: string, actionId: string) => void;
readonly clear: () => void;
// (undocumented)
readonly detachAction: (triggerId: TriggerId, actionId: string) => void;
readonly detachAction: (triggerId: string, actionId: string) => void;
// @deprecated (undocumented)
readonly executeTriggerActions: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T, context: TriggerContext<T>) => Promise<void>;
readonly executeTriggerActions: (triggerId: string, context: object) => Promise<void>;
// Warning: (ae-forgotten-export) The symbol "UiActionsExecutionService" needs to be exported by the entry point index.d.ts
//
// (undocumented)
readonly executionService: UiActionsExecutionService;
readonly fork: () => UiActionsService;
// (undocumented)
readonly getAction: <T extends UiActionsActionDefinition<{}>>(id: string) => Action<ActionContext<T>, "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">;
readonly getAction: <T extends UiActionsActionDefinition<object>>(id: string) => Action<ActionContext<T>>;
// Warning: (ae-forgotten-export) The symbol "TriggerContract" needs to be exported by the entry point index.d.ts
//
// (undocumented)
readonly getTrigger: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T) => TriggerContract<T>;
readonly getTrigger: (triggerId: string) => TriggerContract;
// (undocumented)
readonly getTriggerActions: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T) => Action<TriggerContextMapping[T], "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">[];
readonly getTriggerActions: (triggerId: string) => Action[];
// (undocumented)
readonly getTriggerCompatibleActions: <T extends "" | "ROW_CLICK_TRIGGER" | "VISUALIZE_FIELD_TRIGGER" | "VISUALIZE_GEO_FIELD_TRIGGER" | "FILTER_TRIGGER" | "CONTEXT_MENU_TRIGGER" | "PANEL_BADGE_TRIGGER" | "PANEL_NOTIFICATION_TRIGGER" | "SELECT_RANGE_TRIGGER" | "VALUE_CLICK_TRIGGER">(triggerId: T, context: TriggerContextMapping[T]) => Promise<Action<TriggerContextMapping[T], "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">[]>;
readonly getTriggerCompatibleActions: (triggerId: string, context: object) => Promise<Action[]>;
// (undocumented)
readonly hasAction: (actionId: string) => boolean;
// Warning: (ae-forgotten-export) The symbol "ActionContext" needs to be exported by the entry point index.d.ts
//
// (undocumented)
readonly registerAction: <A extends UiActionsActionDefinition<{}>>(definition: A) => Action<ActionContext<A>, "" | "ACTION_VISUALIZE_FIELD" | "ACTION_VISUALIZE_GEO_FIELD" | "ACTION_VISUALIZE_LENS_FIELD" | "ACTION_GLOBAL_APPLY_FILTER" | "ACTION_SELECT_RANGE" | "ACTION_VALUE_CLICK" | "ACTION_CUSTOMIZE_PANEL" | "ACTION_ADD_PANEL" | "openInspector" | "deletePanel" | "editPanel">;
readonly registerAction: <A extends UiActionsActionDefinition<object>>(definition: A) => Action<ActionContext<A>>;
// (undocumented)
readonly registerTrigger: (trigger: Trigger) => void;
// Warning: (ae-forgotten-export) The symbol "TriggerRegistry" needs to be exported by the entry point index.d.ts
@ -314,12 +254,12 @@ export interface VisualizeFieldContext {
// Warning: (ae-missing-release-tag) "visualizeFieldTrigger" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const visualizeFieldTrigger: Trigger<'VISUALIZE_FIELD_TRIGGER'>;
export const visualizeFieldTrigger: Trigger;
// Warning: (ae-missing-release-tag) "visualizeGeoFieldTrigger" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const visualizeGeoFieldTrigger: Trigger<'VISUALIZE_GEO_FIELD_TRIGGER'>;
export const visualizeGeoFieldTrigger: Trigger;
// Warnings were encountered during analysis:

View file

@ -19,14 +19,13 @@
import { uniqBy } from 'lodash';
import { Action } from '../actions';
import { BaseContext } from '../types';
import { defer as createDefer, Defer } from '../../../kibana_utils/public';
import { buildContextMenuForActions, openContextMenu } from '../context_menu';
import { Trigger } from '../triggers';
interface ExecuteActionTask {
action: Action;
context: BaseContext;
context: object;
trigger: Trigger;
defer: Defer<void>;
alwaysShowPopup?: boolean;
@ -44,8 +43,8 @@ export class UiActionsExecutionService {
context,
trigger,
}: {
action: Action<BaseContext>;
context: BaseContext;
action: Action;
context: object;
trigger: Trigger;
},
alwaysShowPopup?: boolean

View file

@ -20,19 +20,17 @@
import { UiActionsService } from './ui_actions_service';
import { Action, ActionInternal, createAction } from '../actions';
import { createHelloWorldAction } from '../tests/test_samples';
import { TriggerRegistry, TriggerId, ActionType, ActionRegistry } from '../types';
import { TriggerRegistry, ActionRegistry } from '../types';
import { Trigger } from '../triggers';
// Casting to ActionType or TriggerId is a hack - in a real situation use
// declare module and add this id to the appropriate context mapping.
const FOO_TRIGGER: TriggerId = 'FOO_TRIGGER' as TriggerId;
const BAR_TRIGGER: TriggerId = 'BAR_TRIGGER' as TriggerId;
const MY_TRIGGER: TriggerId = 'MY_TRIGGER' as TriggerId;
const FOO_TRIGGER = 'FOO_TRIGGER';
const BAR_TRIGGER = 'BAR_TRIGGER';
const MY_TRIGGER = 'MY_TRIGGER';
const testAction1: Action = {
id: 'action1',
order: 1,
type: 'type1' as ActionType,
type: 'type1',
execute: async () => {},
getDisplayName: () => 'test1',
getIconType: () => '',
@ -42,7 +40,7 @@ const testAction1: Action = {
const testAction2: Action = {
id: 'action2',
order: 2,
type: 'type2' as ActionType,
type: 'type2',
execute: async () => {},
getDisplayName: () => 'test2',
getIconType: () => '',
@ -99,7 +97,7 @@ describe('UiActionsService', () => {
getDisplayName: () => 'test',
getIconType: () => '',
isCompatible: async () => true,
type: 'test' as ActionType,
type: 'test',
});
});
@ -111,7 +109,7 @@ describe('UiActionsService', () => {
getDisplayName: () => 'test',
getIconType: () => '',
isCompatible: async () => true,
type: 'test' as ActionType,
type: 'test',
});
expect(action).toBeInstanceOf(ActionInternal);
@ -123,7 +121,7 @@ describe('UiActionsService', () => {
const action1: Action = {
id: 'action1',
order: 1,
type: 'type1' as ActionType,
type: 'type1',
execute: async () => {},
getDisplayName: () => 'test',
getIconType: () => '',
@ -132,7 +130,7 @@ describe('UiActionsService', () => {
const action2: Action = {
id: 'action2',
order: 2,
type: 'type2' as ActionType,
type: 'type2',
execute: async () => {},
getDisplayName: () => 'test',
getIconType: () => '',
@ -207,7 +205,8 @@ describe('UiActionsService', () => {
test('filters out actions not applicable based on the context', async () => {
const service = new UiActionsService();
const action = createAction({
type: 'test' as ActionType,
id: 'test',
type: 'test',
isCompatible: ({ accept }: { accept: boolean }) => Promise.resolve(accept),
execute: () => Promise.resolve(),
});
@ -238,16 +237,15 @@ describe('UiActionsService', () => {
test(`throws an error with an invalid trigger ID`, async () => {
const service = new UiActionsService();
// Without the cast "as TriggerId" typescript will happily throw an error!
await expect(
service.getTriggerCompatibleActions('I do not exist' as TriggerId, {})
).rejects.toMatchObject(new Error('Trigger [triggerId = I do not exist] does not exist.'));
await expect(service.getTriggerCompatibleActions('I do not exist', {})).rejects.toMatchObject(
new Error('Trigger [triggerId = I do not exist] does not exist.')
);
});
test('returns empty list if trigger not attached to any action', async () => {
const service = new UiActionsService();
const testTrigger: Trigger = {
id: '123' as TriggerId,
id: '123',
title: '123',
};
service.registerTrigger(testTrigger);
@ -445,9 +443,7 @@ describe('UiActionsService', () => {
} as any;
service.registerAction(action);
expect(() =>
service.detachAction('i do not exist' as TriggerId, ACTION_HELLO_WORLD)
).toThrowError(
expect(() => service.detachAction('i do not exist', ACTION_HELLO_WORLD)).toThrowError(
'No trigger [triggerId = i do not exist] exists, for detaching action [actionId = ACTION_HELLO_WORLD].'
);
});
@ -461,7 +457,7 @@ describe('UiActionsService', () => {
} as any;
service.registerAction(action);
expect(() => service.addTriggerAction('i do not exist' as TriggerId, action)).toThrowError(
expect(() => service.addTriggerAction('i do not exist', action)).toThrowError(
'No trigger [triggerId = i do not exist] exists, for attaching action [actionId = ACTION_HELLO_WORLD].'
);
});

View file

@ -17,15 +17,9 @@
* under the License.
*/
import {
TriggerRegistry,
ActionRegistry,
TriggerToActionsRegistry,
TriggerId,
TriggerContextMapping,
} from '../types';
import { TriggerRegistry, ActionRegistry, TriggerToActionsRegistry } from '../types';
import { ActionInternal, Action, ActionDefinition, ActionContext } from '../actions';
import { Trigger, TriggerContext } from '../triggers/trigger';
import { Trigger } from '../triggers/trigger';
import { TriggerInternal } from '../triggers/trigger_internal';
import { TriggerContract } from '../triggers/trigger_contract';
import { UiActionsExecutionService } from './ui_actions_execution_service';
@ -67,7 +61,7 @@ export class UiActionsService {
this.triggerToActions.set(trigger.id, []);
};
public readonly getTrigger = <T extends TriggerId>(triggerId: T): TriggerContract<T> => {
public readonly getTrigger = (triggerId: string): TriggerContract => {
const trigger = this.triggers.get(triggerId);
if (!trigger) {
@ -103,7 +97,7 @@ export class UiActionsService {
return this.actions.has(actionId);
};
public readonly attachAction = <T extends TriggerId>(triggerId: T, actionId: string): void => {
public readonly attachAction = (triggerId: string, actionId: string): void => {
const trigger = this.triggers.get(triggerId);
if (!trigger) {
@ -119,7 +113,7 @@ export class UiActionsService {
}
};
public readonly detachAction = (triggerId: TriggerId, actionId: string) => {
public readonly detachAction = (triggerId: string, actionId: string) => {
const trigger = this.triggers.get(triggerId);
if (!trigger) {
@ -139,14 +133,10 @@ export class UiActionsService {
/**
* `addTriggerAction` is similar to `attachAction` as it attaches action to a
* trigger, but it also registers the action, if it has not been registered, yet.
*
* `addTriggerAction` also infers better typing of the `action` argument.
*/
public readonly addTriggerAction = <T extends TriggerId>(
triggerId: T,
// The action can accept partial or no context, but if it needs context not provided
// by this type of trigger, typescript will complain. yay!
action: ActionDefinition<TriggerContextMapping[T]> | Action<TriggerContextMapping[T]> // TODO: remove `Action` https://github.com/elastic/kibana/issues/74501
public readonly addTriggerAction = (
triggerId: string,
action: ActionDefinition // TODO: remove `Action` https://github.com/elastic/kibana/issues/74501
): void => {
if (!this.actions.has(action.id)) this.registerAction(action);
this.attachAction(triggerId, action.id);
@ -162,9 +152,7 @@ export class UiActionsService {
return this.actions.get(id) as ActionInternal<T>;
};
public readonly getTriggerActions = <T extends TriggerId>(
triggerId: T
): Array<Action<TriggerContextMapping[T]>> => {
public readonly getTriggerActions = (triggerId: string): Action[] => {
// This line checks if trigger exists, otherwise throws.
this.getTrigger!(triggerId);
@ -174,13 +162,13 @@ export class UiActionsService {
.map((actionId) => this.actions.get(actionId) as ActionInternal)
.filter(Boolean);
return actions as Array<Action<TriggerContext<T>>>;
return actions as Action[];
};
public readonly getTriggerCompatibleActions = async <T extends TriggerId>(
triggerId: T,
context: TriggerContextMapping[T]
): Promise<Array<Action<TriggerContextMapping[T]>>> => {
public readonly getTriggerCompatibleActions = async (
triggerId: string,
context: object
): Promise<Action[]> => {
const actions = this.getTriggerActions!(triggerId);
const isCompatibles = await Promise.all(
actions.map((action) =>
@ -191,8 +179,7 @@ export class UiActionsService {
)
);
return actions.reduce(
(acc: Array<Action<TriggerContextMapping[T]>>, action, i) =>
isCompatibles[i] ? [...acc, action] : acc,
(acc: Action[], action, i) => (isCompatibles[i] ? [...acc, action] : acc),
[]
);
};
@ -202,11 +189,8 @@ export class UiActionsService {
*
* Use `plugins.uiActions.getTrigger(triggerId).exec(params)` instead.
*/
public readonly executeTriggerActions = async <T extends TriggerId>(
triggerId: T,
context: TriggerContext<T>
) => {
const trigger = this.getTrigger<T>(triggerId);
public readonly executeTriggerActions = async (triggerId: string, context: object) => {
const trigger = this.getTrigger(triggerId);
await trigger.exec(context);
};

View file

@ -21,7 +21,6 @@ import { Action, createAction } from '../actions';
import { openContextMenu } from '../context_menu';
import { uiActionsPluginMock } from '../mocks';
import { Trigger } from '../triggers';
import { TriggerId, ActionType } from '../types';
import { waitFor } from '@testing-library/dom';
jest.mock('../context_menu');
@ -31,17 +30,13 @@ const openContextMenuSpy = (openContextMenu as any) as jest.SpyInstance;
const CONTACT_USER_TRIGGER = 'CONTACT_USER_TRIGGER';
// Casting to ActionType is a hack - in a real situation use
// declare module and add this id to ActionContextMapping.
const TEST_ACTION_TYPE = 'TEST_ACTION_TYPE' as ActionType;
function createTestAction<C extends object>(
type: string,
checkCompatibility: (context: C) => boolean,
autoExecutable = false
): Action<object> {
return createAction<typeof TEST_ACTION_TYPE>({
type: type as ActionType,
return createAction({
type,
id: type,
isCompatible: (context: C) => Promise.resolve(checkCompatibility(context)),
execute: (context) => executeFn(context),
@ -67,7 +62,7 @@ beforeEach(reset);
test('executes a single action mapped to a trigger', async () => {
const { setup, doStart } = uiActions;
const trigger: Trigger = {
id: 'MY-TRIGGER' as TriggerId,
id: 'MY-TRIGGER',
title: 'My trigger',
};
const action = createTestAction('test1', () => true);
@ -77,7 +72,7 @@ test('executes a single action mapped to a trigger', async () => {
const context = {};
const start = doStart();
await start.executeTriggerActions('MY-TRIGGER' as TriggerId, context);
await start.executeTriggerActions('MY-TRIGGER', context);
jest.runAllTimers();
@ -88,7 +83,7 @@ test('executes a single action mapped to a trigger', async () => {
test("doesn't throw an error if there are no compatible actions to execute", async () => {
const { setup, doStart } = uiActions;
const trigger: Trigger = {
id: 'MY-TRIGGER' as TriggerId,
id: 'MY-TRIGGER',
title: 'My trigger',
};
@ -96,15 +91,13 @@ test("doesn't throw an error if there are no compatible actions to execute", asy
const context = {};
const start = doStart();
await expect(
start.executeTriggerActions('MY-TRIGGER' as TriggerId, context)
).resolves.toBeUndefined();
await expect(start.executeTriggerActions('MY-TRIGGER', context)).resolves.toBeUndefined();
});
test('does not execute an incompatible action', async () => {
const { setup, doStart } = uiActions;
const trigger: Trigger = {
id: 'MY-TRIGGER' as TriggerId,
id: 'MY-TRIGGER',
title: 'My trigger',
};
const action = createTestAction<{ name: string }>(
@ -119,7 +112,7 @@ test('does not execute an incompatible action', async () => {
const context = {
name: 'executeme',
};
await start.executeTriggerActions('MY-TRIGGER' as TriggerId, context);
await start.executeTriggerActions('MY-TRIGGER', context);
jest.runAllTimers();
@ -129,7 +122,7 @@ test('does not execute an incompatible action', async () => {
test('shows a context menu when more than one action is mapped to a trigger', async () => {
const { setup, doStart } = uiActions;
const trigger: Trigger = {
id: 'MY-TRIGGER' as TriggerId,
id: 'MY-TRIGGER',
title: 'My trigger',
};
const action1 = createTestAction('test1', () => true);
@ -143,7 +136,7 @@ test('shows a context menu when more than one action is mapped to a trigger', as
const start = doStart();
const context = {};
await start.getTrigger('MY-TRIGGER' as TriggerId)!.exec(context);
await start.getTrigger('MY-TRIGGER')!.exec(context);
jest.runAllTimers();
@ -156,7 +149,7 @@ test('shows a context menu when more than one action is mapped to a trigger', as
test('shows a context menu when there is only one action mapped to a trigger and "alwaysShowPopup" is set', async () => {
const { setup, doStart } = uiActions;
const trigger: Trigger = {
id: 'MY-TRIGGER' as TriggerId,
id: 'MY-TRIGGER',
title: 'My trigger',
};
const action1 = createTestAction('test1', () => true);
@ -168,7 +161,7 @@ test('shows a context menu when there is only one action mapped to a trigger and
const start = doStart();
const context = {};
await start.getTrigger('MY-TRIGGER' as TriggerId)!.exec(context, true);
await start.getTrigger('MY-TRIGGER')!.exec(context, true);
jest.runAllTimers();
@ -181,7 +174,7 @@ test('shows a context menu when there is only one action mapped to a trigger and
test('passes whole action context to isCompatible()', async () => {
const { setup, doStart } = uiActions;
const trigger = {
id: 'MY-TRIGGER' as TriggerId,
id: 'MY-TRIGGER',
title: 'My trigger',
};
const action = createTestAction<{ foo: string }>('test', ({ foo }) => {
@ -195,14 +188,14 @@ test('passes whole action context to isCompatible()', async () => {
const start = doStart();
const context = { foo: 'bar' };
await start.executeTriggerActions('MY-TRIGGER' as TriggerId, context);
await start.executeTriggerActions('MY-TRIGGER', context);
jest.runAllTimers();
});
test("doesn't show a context menu for auto executable actions", async () => {
const { setup, doStart } = uiActions;
const trigger: Trigger = {
id: 'MY-TRIGGER' as TriggerId,
id: 'MY-TRIGGER',
title: 'My trigger',
};
const action1 = createTestAction('test1', () => true, true);
@ -216,7 +209,7 @@ test("doesn't show a context menu for auto executable actions", async () => {
const start = doStart();
const context = {};
await start.executeTriggerActions('MY-TRIGGER' as TriggerId, context);
await start.executeTriggerActions('MY-TRIGGER', context);
jest.runAllTimers();
@ -229,7 +222,7 @@ test("doesn't show a context menu for auto executable actions", async () => {
test('passes trigger into execute', async () => {
const { setup, doStart } = uiActions;
const trigger = {
id: 'MY-TRIGGER' as TriggerId,
id: 'MY-TRIGGER',
title: 'My trigger',
};
const action = createTestAction<{ foo: string }>('test', () => true);
@ -240,7 +233,7 @@ test('passes trigger into execute', async () => {
const start = doStart();
const context = { foo: 'bar' };
await start.executeTriggerActions('MY-TRIGGER' as TriggerId, context);
await start.executeTriggerActions('MY-TRIGGER', context);
jest.runAllTimers();
expect(executeFn).toBeCalledWith({
...context,

View file

@ -19,17 +19,16 @@
import { ActionInternal, Action } from '../actions';
import { uiActionsPluginMock } from '../mocks';
import { TriggerId, ActionType } from '../types';
const action1: Action = {
id: 'action1',
order: 1,
type: 'type1' as ActionType,
type: 'type1',
} as any;
const action2: Action = {
id: 'action2',
order: 2,
type: 'type2' as ActionType,
type: 'type2',
} as any;
test('returns actions set on trigger', () => {
@ -38,24 +37,24 @@ test('returns actions set on trigger', () => {
setup.registerAction(action2);
setup.registerTrigger({
description: 'foo',
id: 'trigger' as TriggerId,
id: 'trigger',
title: 'baz',
});
const start = doStart();
const list0 = start.getTriggerActions('trigger' as TriggerId);
const list0 = start.getTriggerActions('trigger');
expect(list0).toHaveLength(0);
setup.addTriggerAction('trigger' as TriggerId, action1);
const list1 = start.getTriggerActions('trigger' as TriggerId);
setup.addTriggerAction('trigger', action1);
const list1 = start.getTriggerActions('trigger');
expect(list1).toHaveLength(1);
expect(list1[0]).toBeInstanceOf(ActionInternal);
expect(list1[0].id).toBe(action1.id);
setup.addTriggerAction('trigger' as TriggerId, action2);
const list2 = start.getTriggerActions('trigger' as TriggerId);
setup.addTriggerAction('trigger', action2);
const list2 = start.getTriggerActions('trigger');
expect(list2).toHaveLength(2);
expect(!!list2.find(({ id }: any) => id === 'action1')).toBe(true);

View file

@ -21,23 +21,23 @@ import { uiActionsPluginMock } from '../mocks';
import { createHelloWorldAction } from '../tests/test_samples';
import { Action, createAction } from '../actions';
import { Trigger } from '../triggers';
import { TriggerId, ActionType } from '../types';
let action: Action<{ name: string }, ActionType>;
let action: Action<{ name: string }>;
let uiActions: ReturnType<typeof uiActionsPluginMock.createPlugin>;
beforeEach(() => {
uiActions = uiActionsPluginMock.createPlugin();
action = createAction({
type: 'test' as ActionType,
id: 'test',
type: 'test',
execute: () => Promise.resolve(),
});
uiActions.setup.registerAction(action);
uiActions.setup.registerTrigger({
id: 'trigger' as TriggerId,
id: 'trigger',
title: 'trigger',
});
uiActions.setup.addTriggerAction('trigger' as TriggerId, action);
uiActions.setup.addTriggerAction('trigger', action);
});
test('can register action', async () => {
@ -54,14 +54,14 @@ test('getTriggerCompatibleActions returns attached actions', async () => {
setup.registerAction(helloWorldAction);
const testTrigger: Trigger = {
id: 'MY-TRIGGER' as TriggerId,
id: 'MY-TRIGGER',
title: 'My trigger',
};
setup.registerTrigger(testTrigger);
setup.addTriggerAction('MY-TRIGGER' as TriggerId, helloWorldAction);
setup.addTriggerAction('MY-TRIGGER', helloWorldAction);
const start = doStart();
const actions = await start.getTriggerCompatibleActions('MY-TRIGGER' as TriggerId, {});
const actions = await start.getTriggerCompatibleActions('MY-TRIGGER', {});
expect(actions.length).toBe(1);
expect(actions[0].id).toBe(helloWorldAction.id);
@ -70,7 +70,8 @@ test('getTriggerCompatibleActions returns attached actions', async () => {
test('filters out actions not applicable based on the context', async () => {
const { setup, doStart } = uiActions;
const action1 = createAction({
type: 'test1' as ActionType,
id: 'test1',
type: 'test1',
isCompatible: async (context: { accept: boolean }) => {
return Promise.resolve(context.accept);
},
@ -78,7 +79,7 @@ test('filters out actions not applicable based on the context', async () => {
});
const testTrigger: Trigger = {
id: 'MY-TRIGGER2' as TriggerId,
id: 'MY-TRIGGER2',
title: 'My trigger',
};
@ -100,15 +101,15 @@ test(`throws an error with an invalid trigger ID`, async () => {
const { doStart } = uiActions;
const start = doStart();
await expect(
start.getTriggerCompatibleActions('I do not exist' as TriggerId, {})
).rejects.toMatchObject(new Error('Trigger [triggerId = I do not exist] does not exist.'));
await expect(start.getTriggerCompatibleActions('I do not exist', {})).rejects.toMatchObject(
new Error('Trigger [triggerId = I do not exist] does not exist.')
);
});
test(`with a trigger mapping that maps to an non-existing action returns empty list`, async () => {
const { setup, doStart } = uiActions;
const testTrigger: Trigger = {
id: '123' as TriggerId,
id: '123',
title: '123',
};
setup.registerTrigger(testTrigger);

View file

@ -20,9 +20,8 @@
import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiBadge, EuiFlyoutBody } from '@elastic/eui';
import { CoreStart } from 'src/core/public';
import { createAction, ActionByType } from '../../actions';
import { createAction, Action } from '../../actions';
import { toMountPoint, reactToUiComponent } from '../../../../kibana_react/public';
import { ActionType } from '../../types';
const ReactMenuItem: React.FC = () => {
return (
@ -37,14 +36,11 @@ const ReactMenuItem: React.FC = () => {
const UiMenuItem = reactToUiComponent(ReactMenuItem);
// Casting to ActionType is a hack - in a real situation use
// declare module and add this id to ActionContextMapping.
export const ACTION_HELLO_WORLD = 'ACTION_HELLO_WORLD' as ActionType;
export const ACTION_HELLO_WORLD = 'ACTION_HELLO_WORLD';
export function createHelloWorldAction(
overlays: CoreStart['overlays']
): ActionByType<typeof ACTION_HELLO_WORLD> {
return createAction<typeof ACTION_HELLO_WORLD>({
export function createHelloWorldAction(overlays: CoreStart['overlays']): Action {
return createAction({
id: ACTION_HELLO_WORLD,
type: ACTION_HELLO_WORLD,
getIconType: () => 'lock',
MenuItem: UiMenuItem,

View file

@ -20,7 +20,7 @@
import { Trigger } from '.';
export const DEFAULT_TRIGGER = '';
export const defaultTrigger: Trigger<''> = {
export const defaultTrigger: Trigger = {
id: DEFAULT_TRIGGER,
title: 'Unknown',
description: 'Unknown trigger.',

View file

@ -23,7 +23,7 @@ import { Datatable } from '../../../expressions';
export const ROW_CLICK_TRIGGER = 'ROW_CLICK_TRIGGER';
export const rowClickTrigger: Trigger<'ROW_CLICK_TRIGGER'> = {
export const rowClickTrigger: Trigger = {
id: ROW_CLICK_TRIGGER,
title: i18n.translate('uiActions.triggers.rowClickTitle', {
defaultMessage: 'Table row click',

View file

@ -17,8 +17,6 @@
* under the License.
*/
import { TriggerContextMapping, TriggerId } from '../types';
/**
* This is a convenience interface used to register a *trigger*.
*
@ -30,11 +28,11 @@ import { TriggerContextMapping, TriggerId } from '../types';
* trigger is *called* it first displays a context menu for user to pick a
* single action to execute.
*/
export interface Trigger<ID extends TriggerId = TriggerId> {
export interface Trigger {
/**
* Unique name of the trigger as identified in `ui_actions` plugin trigger registry.
*/
id: ID;
id: string;
/**
* User friendly name of the trigger.
@ -46,5 +44,3 @@ export interface Trigger<ID extends TriggerId = TriggerId> {
*/
description?: string;
}
export type TriggerContext<T> = T extends TriggerId ? TriggerContextMapping[T] : never;

View file

@ -18,16 +18,15 @@
*/
import { TriggerInternal } from './trigger_internal';
import { TriggerId, TriggerContextMapping } from '../types';
/**
* This is a public representation of a trigger that is provided to other plugins.
*/
export class TriggerContract<T extends TriggerId> {
export class TriggerContract<Context extends object = object> {
/**
* Unique name of the trigger as identified in `ui_actions` plugin trigger registry.
*/
public readonly id: T;
public readonly id: string;
/**
* User friendly name of the trigger.
@ -39,7 +38,7 @@ export class TriggerContract<T extends TriggerId> {
*/
public readonly description?: string;
constructor(private readonly internal: TriggerInternal<T>) {
constructor(private readonly internal: TriggerInternal<Context>) {
this.id = this.internal.trigger.id;
this.title = this.internal.trigger.title;
this.description = this.internal.trigger.description;
@ -48,7 +47,7 @@ export class TriggerContract<T extends TriggerId> {
/**
* Use this method to execute action attached to this trigger.
*/
public readonly exec = async (context: TriggerContextMapping[T], alwaysShowPopup?: boolean) => {
public readonly exec = async (context: Context, alwaysShowPopup?: boolean) => {
await this.internal.execute(context, alwaysShowPopup);
};
}

View file

@ -20,18 +20,17 @@
import { Trigger } from './trigger';
import { TriggerContract } from './trigger_contract';
import { UiActionsService } from '../service';
import { TriggerId, TriggerContextMapping } from '../types';
/**
* Internal representation of a trigger kept for consumption only internally
* within `ui_actions` plugin.
*/
export class TriggerInternal<T extends TriggerId> {
public readonly contract = new TriggerContract<T>(this);
export class TriggerInternal<Context extends object = object> {
public readonly contract: TriggerContract<Context> = new TriggerContract<Context>(this);
constructor(public readonly service: UiActionsService, public readonly trigger: Trigger<T>) {}
constructor(public readonly service: UiActionsService, public readonly trigger: Trigger) {}
public async execute(context: TriggerContextMapping[T], alwaysShowPopup?: boolean) {
public async execute(context: Context, alwaysShowPopup?: boolean) {
const triggerId = this.trigger.id;
const actions = await this.service.getTriggerCompatibleActions!(triggerId, context);

Some files were not shown because too many files have changed in this diff Show more