Skip to content

[Ui Actions] Support emitting nested triggers and actions #59162

@stacey-gammon

Description

@stacey-gammon

There is an example of this in the ui_actions_explorer (once #58765 is merged).

export const createPhoneUserAction = (getUiActionsApi: () => Promise<UiActionsStart>) =>
  createAction<typeof ACTION_PHONE_USER>({
    type: ACTION_PHONE_USER,
    getDisplayName: () => 'Call phone number',
    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 });
      }
    },

This causes two pop up menus to show up. We have a real life desire to support this as well for the VALUE_CLICK_TRIGGER. If the data emitted with the value click trigger can be transformed to a Filter shape then you should be able to execute any actions that are attached to VALUE_CLICK_TRIGGER as well as any actions attached to APPLY_FILTER_TRIGGER.

For instance, say you have an action that just works of field: string, value: string data - e.g. it just searches google or something www.google.com/s?q="${field} ${value}". If you click on a pie slice, you will have this data. You should be able to attach the search google action to that trigger, as well as the usual actions that rely on Filter context.

Implementation thoughts

First: introduce the concept of automatically executed actions. I think this could be useful for other reasons anyway (consider the situation of a HOVER trigger and wanting to attach it to an action that shows a tooltip and an action that shows a global threshold line - those are two actions that should be executed simultaneously, and not shown to the user in a context menu for them to choose from).

Second: introduce batching of emitted triggers to be execute on the next event loop.

Then, an auto executed action can be attached to VALUE_CLICK_TRIGGER - ACTION_EMIT_APPLY_FILTER_TRIGGER. This checks to see if the data can be transformed into a Filter shape. If it does, it uiActionApi.emit(APPLY_FILTER_TRIGGER, filters). Because this is auto executed, it gets emitted before the event loop, should get batched up and then the context menu shown to the user should contain both actions attached to VALUE_CLICK_TRIGGER and actions attached to APPLY_FILTER_TRIGGER

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature:UIActionsUI actions. These are client side only, not related to the server side actions..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions