Skip to content

Commit dda3a3e

Browse files
authored
[uiActions] Support emitting nested triggers and actions (#70602) (#72027)
* Introduce automatically executed actions * Introduce batching of emitted triggers to be execute on the macro task
1 parent 2515eb6 commit dda3a3e

27 files changed

+368
-215
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [ApplyGlobalFilterActionContext](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.md) &gt; [embeddable](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.embeddable.md)
4+
5+
## ApplyGlobalFilterActionContext.embeddable property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
embeddable?: IEmbeddable;
11+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [ApplyGlobalFilterActionContext](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.md) &gt; [filters](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.filters.md)
4+
5+
## ApplyGlobalFilterActionContext.filters property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
filters: Filter[];
11+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [ApplyGlobalFilterActionContext](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.md)
4+
5+
## ApplyGlobalFilterActionContext interface
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
export interface ApplyGlobalFilterActionContext
11+
```
12+
13+
## Properties
14+
15+
| Property | Type | Description |
16+
| --- | --- | --- |
17+
| [embeddable](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.embeddable.md) | <code>IEmbeddable</code> | |
18+
| [filters](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.filters.md) | <code>Filter[]</code> | |
19+
| [timeFieldName](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.timefieldname.md) | <code>string</code> | |
20+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [ApplyGlobalFilterActionContext](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.md) &gt; [timeFieldName](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.timefieldname.md)
4+
5+
## ApplyGlobalFilterActionContext.timeFieldName property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
timeFieldName?: string;
11+
```

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
| Interface | Description |
4949
| --- | --- |
5050
| [AggParamOption](./kibana-plugin-plugins-data-public.aggparamoption.md) | |
51+
| [ApplyGlobalFilterActionContext](./kibana-plugin-plugins-data-public.applyglobalfilteractioncontext.md) | |
5152
| [DataPublicPluginSetup](./kibana-plugin-plugins-data-public.datapublicpluginsetup.md) | |
5253
| [DataPublicPluginStart](./kibana-plugin-plugins-data-public.datapublicpluginstart.md) | |
5354
| [EsQueryConfig](./kibana-plugin-plugins-data-public.esqueryconfig.md) | |

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.plugin.setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
<b>Signature:</b>
88

99
```typescript
10-
setup(core: CoreSetup, { expressions, uiActions, usageCollection }: DataSetupDependencies): DataPublicPluginSetup;
10+
setup(core: CoreSetup<DataStartDependencies, DataPublicPluginStart>, { expressions, uiActions, usageCollection }: DataSetupDependencies): DataPublicPluginSetup;
1111
```
1212

1313
## Parameters
1414

1515
| Parameter | Type | Description |
1616
| --- | --- | --- |
17-
| core | <code>CoreSetup</code> | |
17+
| core | <code>CoreSetup&lt;DataStartDependencies, DataPublicPluginStart&gt;</code> | |
1818
| { expressions, uiActions, usageCollection } | <code>DataSetupDependencies</code> | |
1919

2020
<b>Returns:</b>

examples/ui_actions_explorer/public/actions/actions.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const ACTION_VIEW_IN_MAPS = 'ACTION_VIEW_IN_MAPS';
3131
export const ACTION_TRAVEL_GUIDE = 'ACTION_TRAVEL_GUIDE';
3232
export const ACTION_CALL_PHONE_NUMBER = 'ACTION_CALL_PHONE_NUMBER';
3333
export const ACTION_EDIT_USER = 'ACTION_EDIT_USER';
34-
export const ACTION_PHONE_USER = 'ACTION_PHONE_USER';
34+
export const ACTION_TRIGGER_PHONE_USER = 'ACTION_TRIGGER_PHONE_USER';
3535
export const ACTION_SHOWCASE_PLUGGABILITY = 'ACTION_SHOWCASE_PLUGGABILITY';
3636

3737
export const showcasePluggability = createAction<typeof ACTION_SHOWCASE_PLUGGABILITY>({
@@ -120,19 +120,13 @@ export interface UserContext {
120120
update: (user: User) => void;
121121
}
122122

123-
export const createPhoneUserAction = (getUiActionsApi: () => Promise<UiActionsStart>) =>
124-
createAction<typeof ACTION_PHONE_USER>({
125-
type: ACTION_PHONE_USER,
123+
export const createTriggerPhoneTriggerAction = (getUiActionsApi: () => Promise<UiActionsStart>) =>
124+
createAction<typeof ACTION_TRIGGER_PHONE_USER>({
125+
type: ACTION_TRIGGER_PHONE_USER,
126126
getDisplayName: () => 'Call phone number',
127+
shouldAutoExecute: async () => true,
127128
isCompatible: async ({ user }) => user.phone !== undefined,
128129
execute: async ({ user }) => {
129-
// One option - execute the more specific action directly.
130-
// makePhoneCallAction.execute({ phone: user.phone });
131-
132-
// Another option - emit the trigger and automatically get *all* the actions attached
133-
// to the phone number trigger.
134-
// TODO: we need to figure out the best way to handle these nested actions however, since
135-
// we don't want multiple context menu's to pop up.
136130
if (user.phone !== undefined) {
137131
(await getUiActionsApi()).executeTriggerActions(PHONE_TRIGGER, { phone: user.phone });
138132
}

examples/ui_actions_explorer/public/plugin.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
PHONE_TRIGGER,
2424
USER_TRIGGER,
2525
COUNTRY_TRIGGER,
26-
createPhoneUserAction,
2726
lookUpWeatherAction,
2827
viewInMapsAction,
2928
createEditUserAction,
@@ -37,7 +36,8 @@ import {
3736
ACTION_CALL_PHONE_NUMBER,
3837
ACTION_TRAVEL_GUIDE,
3938
ACTION_VIEW_IN_MAPS,
40-
ACTION_PHONE_USER,
39+
ACTION_TRIGGER_PHONE_USER,
40+
createTriggerPhoneTriggerAction,
4141
} from './actions/actions';
4242
import { DeveloperExamplesSetup } from '../../developer_examples/public';
4343
import image from './ui_actions.png';
@@ -64,7 +64,7 @@ declare module '../../../src/plugins/ui_actions/public' {
6464
[ACTION_CALL_PHONE_NUMBER]: PhoneContext;
6565
[ACTION_TRAVEL_GUIDE]: CountryContext;
6666
[ACTION_VIEW_IN_MAPS]: CountryContext;
67-
[ACTION_PHONE_USER]: UserContext;
67+
[ACTION_TRIGGER_PHONE_USER]: UserContext;
6868
}
6969
}
7070

@@ -84,7 +84,7 @@ export class UiActionsExplorerPlugin implements Plugin<void, void, {}, StartDeps
8484

8585
deps.uiActions.addTriggerAction(
8686
USER_TRIGGER,
87-
createPhoneUserAction(async () => (await startServices)[1].uiActions)
87+
createTriggerPhoneTriggerAction(async () => (await startServices)[1].uiActions)
8888
);
8989
deps.uiActions.addTriggerAction(
9090
USER_TRIGGER,

src/plugins/data/public/actions/apply_filter_action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import { toMountPoint } from '../../../kibana_react/public';
2222
import { ActionByType, createAction, IncompatibleActionError } from '../../../ui_actions/public';
2323
import { getOverlays, getIndexPatterns } from '../services';
2424
import { applyFiltersPopover } from '../ui/apply_filters';
25+
import type { IEmbeddable } from '../../../embeddable/public';
2526
import { Filter, FilterManager, TimefilterContract, esFilters } from '..';
2627

2728
export const ACTION_GLOBAL_APPLY_FILTER = 'ACTION_GLOBAL_APPLY_FILTER';
2829

2930
export interface ApplyGlobalFilterActionContext {
3031
filters: Filter[];
3132
timeFieldName?: string;
33+
embeddable?: IEmbeddable;
3234
}
3335

3436
async function isCompatible(context: ApplyGlobalFilterActionContext) {

src/plugins/data/public/actions/filters/create_filters_from_range_select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import moment from 'moment';
2222
import { esFilters, IFieldType, RangeFilterParams } from '../../../public';
2323
import { getIndexPatterns } from '../../../public/services';
2424
import { deserializeAggConfig } from '../../search/expressions/utils';
25-
import { RangeSelectContext } from '../../../../embeddable/public';
25+
import type { RangeSelectContext } from '../../../../embeddable/public';
2626

2727
export async function createFiltersFromRangeSelectAction(event: RangeSelectContext['data']) {
2828
const column: Record<string, any> = event.table.columns[event.column];

0 commit comments

Comments
 (0)