+ Example custom action clicked
+
+ );
+ },
+ },
+ });
+
+ // This submenu was defined in the root profile example_root_pofile/profile.tsx
+ // And we can still add actions to it from the data source profile here.
+ registry.registerCustomActionUnderSubmenu('example-custom-root-submenu', {
+ id: 'example-custom-action5',
+ type: AppMenuActionType.custom,
+ controlProps: {
+ label: 'Custom action (from Data Source profile)',
+ onClick: ({ onFinishAction }) => {
+ alert('Example Data source action under root submenu clicked');
+ onFinishAction();
+ },
+ },
+ });
+
+ return prevValue.appMenuRegistry(registry);
+ },
+ };
+ },
getRowAdditionalLeadingControls: (prev) => (params) => {
const additionalControls = prev(params) || [];
diff --git a/src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/profile.tsx b/src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/profile.tsx
index 125cb609fb84..82988e5514b1 100644
--- a/src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/profile.tsx
+++ b/src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/profile.tsx
@@ -7,8 +7,8 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
-import { EuiBadge } from '@elastic/eui';
-import { getFieldValue } from '@kbn/discover-utils';
+import { EuiBadge, EuiFlyout } from '@elastic/eui';
+import { AppMenuActionType, getFieldValue } from '@kbn/discover-utils';
import React from 'react';
import { RootProfileProvider, SolutionType } from '../../../profiles';
@@ -28,6 +28,68 @@ export const createExampleRootProfileProvider = (): RootProfileProvider => ({
);
},
}),
+ /**
+ * The `getAppMenu` extension point gives access to AppMenuRegistry with methods registerCustomAction and registerCustomActionUnderSubmenu.
+ * The extension also provides the essential params like current dataView, adHocDataViews etc when defining a custom action implementation.
+ * And it supports opening custom flyouts and any other modals on the click.
+ * `getAppMenu` can be configured in both root and data source profiles.
+ * @param prev
+ */
+ getAppMenu: (prev) => (params) => {
+ const prevValue = prev(params);
+
+ // Check `params` for the available deps
+
+ return {
+ appMenuRegistry: (registry) => {
+ // Note: Only 2 custom actions are allowed to be rendered in the app menu. The rest will be ignored.
+
+ // Register a custom submenu action
+ registry.registerCustomAction({
+ id: 'example-custom-root-submenu',
+ type: AppMenuActionType.custom,
+ label: 'Custom Submenu',
+ testId: 'example-custom-root-submenu',
+ actions: [
+ {
+ id: 'example-custom-root-action11',
+ type: AppMenuActionType.custom,
+ controlProps: {
+ label: 'Custom action 11 (from Root profile)',
+ testId: 'example-custom-root-action11',
+ onClick: ({ onFinishAction }) => {
+ alert('Example Root Custom action 11 clicked');
+ onFinishAction(); // This allows to close the popover and return focus back to the app menu DOM node
+ },
+ },
+ },
+ {
+ id: 'example-custom-root-action12',
+ type: AppMenuActionType.custom,
+ controlProps: {
+ label: 'Custom action 12 (from Root profile)',
+ testId: 'example-custom-root-action12',
+ onClick: ({ onFinishAction }) => {
+ // This is an example of a custom action that opens a flyout or any other custom modal.
+ // To do so, simply return a React element and call onFinishAction when you're done.
+ return (
+