mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[uiActions] Support emitting nested triggers and actions (#70602)
* Introduce automatically executed actions * Introduce batching of emitted triggers to be execute on the macro task
This commit is contained in:
parent
0173ef3528
commit
1ac56d7bfc
27 changed files with 368 additions and 215 deletions
|
@ -31,7 +31,7 @@ export const ACTION_VIEW_IN_MAPS = 'ACTION_VIEW_IN_MAPS';
|
|||
export const ACTION_TRAVEL_GUIDE = 'ACTION_TRAVEL_GUIDE';
|
||||
export const ACTION_CALL_PHONE_NUMBER = 'ACTION_CALL_PHONE_NUMBER';
|
||||
export const ACTION_EDIT_USER = 'ACTION_EDIT_USER';
|
||||
export const ACTION_PHONE_USER = 'ACTION_PHONE_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>({
|
||||
|
@ -120,19 +120,13 @@ export interface UserContext {
|
|||
update: (user: User) => void;
|
||||
}
|
||||
|
||||
export const createPhoneUserAction = (getUiActionsApi: () => Promise<UiActionsStart>) =>
|
||||
createAction<typeof ACTION_PHONE_USER>({
|
||||
type: ACTION_PHONE_USER,
|
||||
export const createTriggerPhoneTriggerAction = (getUiActionsApi: () => Promise<UiActionsStart>) =>
|
||||
createAction<typeof ACTION_TRIGGER_PHONE_USER>({
|
||||
type: ACTION_TRIGGER_PHONE_USER,
|
||||
getDisplayName: () => 'Call phone number',
|
||||
shouldAutoExecute: async () => true,
|
||||
isCompatible: async ({ user }) => user.phone !== undefined,
|
||||
execute: async ({ user }) => {
|
||||
// One option - execute the more specific action directly.
|
||||
// makePhoneCallAction.execute({ phone: user.phone });
|
||||
|
||||
// Another option - emit the trigger and automatically get *all* the actions attached
|
||||
// to the phone number trigger.
|
||||
// TODO: we need to figure out the best way to handle these nested actions however, since
|
||||
// we don't want multiple context menu's to pop up.
|
||||
if (user.phone !== undefined) {
|
||||
(await getUiActionsApi()).executeTriggerActions(PHONE_TRIGGER, { phone: user.phone });
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import {
|
|||
PHONE_TRIGGER,
|
||||
USER_TRIGGER,
|
||||
COUNTRY_TRIGGER,
|
||||
createPhoneUserAction,
|
||||
lookUpWeatherAction,
|
||||
viewInMapsAction,
|
||||
createEditUserAction,
|
||||
|
@ -37,7 +36,8 @@ import {
|
|||
ACTION_CALL_PHONE_NUMBER,
|
||||
ACTION_TRAVEL_GUIDE,
|
||||
ACTION_VIEW_IN_MAPS,
|
||||
ACTION_PHONE_USER,
|
||||
ACTION_TRIGGER_PHONE_USER,
|
||||
createTriggerPhoneTriggerAction,
|
||||
} from './actions/actions';
|
||||
import { DeveloperExamplesSetup } from '../../developer_examples/public';
|
||||
import image from './ui_actions.png';
|
||||
|
@ -64,7 +64,7 @@ declare module '../../../src/plugins/ui_actions/public' {
|
|||
[ACTION_CALL_PHONE_NUMBER]: PhoneContext;
|
||||
[ACTION_TRAVEL_GUIDE]: CountryContext;
|
||||
[ACTION_VIEW_IN_MAPS]: CountryContext;
|
||||
[ACTION_PHONE_USER]: UserContext;
|
||||
[ACTION_TRIGGER_PHONE_USER]: UserContext;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ export class UiActionsExplorerPlugin implements Plugin<void, void, {}, StartDeps
|
|||
|
||||
deps.uiActions.addTriggerAction(
|
||||
USER_TRIGGER,
|
||||
createPhoneUserAction(async () => (await startServices)[1].uiActions)
|
||||
createTriggerPhoneTriggerAction(async () => (await startServices)[1].uiActions)
|
||||
);
|
||||
deps.uiActions.addTriggerAction(
|
||||
USER_TRIGGER,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue