Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[uiActions] make trigger action registry async #205512

Merged
merged 36 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d125a86
[uiActions] make trigger action registry async
nreese Jan 3, 2025
9db2492
tslint for dashboards plugin
nreese Jan 3, 2025
58459d7
tslint discover
nreese Jan 3, 2025
aaeafa7
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 3, 2025
67f03fb
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 3, 2025
15e543e
use async registry for panel actions
nreese Jan 3, 2025
ba3a8b4
presentation_container_example tslint
nreese Jan 3, 2025
9d77458
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 3, 2025
fa3bddf
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 3, 2025
7f55e04
use getTriggerCompatibleActions
nreese Jan 3, 2025
e2e3fc2
PresentationPanelErrorInternal
nreese Jan 3, 2025
d30c785
fix test
nreese Jan 3, 2025
2488716
revert change to tsconfig.js
nreese Jan 3, 2025
d2d47d9
revert change to index file
nreese Jan 3, 2025
20c36fa
revert changes to PresentationPanel
nreese Jan 3, 2025
ad14ab3
clean up
nreese Jan 3, 2025
38c646f
tsconfig
nreese Jan 3, 2025
fb68162
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 3, 2025
182dc84
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 3, 2025
5c5f026
dashboard tslint
nreese Jan 4, 2025
6776f96
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 4, 2025
6f1bd4d
fix dynamic_action_manager.test.ts
nreese Jan 4, 2025
55caaba
jest test fix
nreese Jan 4, 2025
f07b487
jest
nreese Jan 4, 2025
ecd374f
Merge branch 'main' into async_actions
elasticmachine Jan 7, 2025
4da6abd
add wait
nreese Jan 7, 2025
25302a2
fix filters notification popover test
nreese Jan 7, 2025
12e93d5
Merge remote-tracking branch 'upstream/main' into async_actions
nreese Jan 8, 2025
98c19e0
allSettled
nreese Jan 8, 2025
488d0f9
Merge branch 'main' into async_actions
elasticmachine Jan 8, 2025
8e38822
Merge branch 'main' into async_actions
elasticmachine Jan 8, 2025
afc3c66
Merge branch 'main' into async_actions
elasticmachine Jan 8, 2025
1e0e79f
Merge branch 'main' into async_actions
elasticmachine Jan 10, 2025
7ac06f4
do not throw error when loading panel components
nreese Jan 10, 2025
acba4f1
revert spelling change
nreese Jan 10, 2025
f60f201
Merge branch 'main' into async_actions
elasticmachine Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,24 @@ export function AddButton({ pageApi, uiActions }: { pageApi: unknown; uiActions:
id: ADD_PANEL_TRIGGER,
},
};
const actionsPromises = uiActions.getTriggerActions(ADD_PANEL_TRIGGER).map(async (action) => {
return {
isCompatible: await action.isCompatible(actionContext),
action,
};
});

Promise.all(actionsPromises).then((actions) => {
if (cancelled) {
return;
}
uiActions.getTriggerCompatibleActions(ADD_PANEL_TRIGGER, actionContext).then((actions) => {
if (cancelled) return;

const nextItems = actions
.filter(
({ action, isCompatible }) => isCompatible && action.id !== 'ACTION_CREATE_ESQL_CHART'
)
.map(({ action }) => {
return (
<EuiContextMenuItem
key={action.id}
icon="share"
onClick={() => {
action.execute(actionContext);
setIsPopoverOpen(false);
}}
>
{action.getDisplayName(actionContext)}
</EuiContextMenuItem>
);
});
const nextItems = actions.map((action) => {
return (
<EuiContextMenuItem
key={action.id}
icon="share"
onClick={() => {
action.execute(actionContext);
setIsPopoverOpen(false);
}}
>
{action.getDisplayName(actionContext)}
</EuiContextMenuItem>
);
});
setItems(nextItems);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function plugin() {
return new PresentationPanelPlugin();
}

export { getEditPanelAction, ACTION_CUSTOMIZE_PANEL } from './panel_actions';
export { ACTION_CUSTOMIZE_PANEL } from './panel_actions/customize_panel_action/constants';
export { ACTION_EDIT_PANEL } from './panel_actions/edit_panel_action/constants';
export { PresentationPanel } from './panel_component';
export type { PresentationPanelProps } from './panel_component/types';
export { PresentationPanelError } from './panel_component/presentation_panel_error';
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import { BehaviorSubject } from 'rxjs';

import { CoreStart } from '@kbn/core/public';
import { PresentationPanelStartDependencies } from './plugin';
import type { CoreStart } from '@kbn/core/public';
import type { PresentationPanelStartDependencies } from './plugin';

export let core: CoreStart;
export let uiActions: PresentationPanelStartDependencies['uiActions'];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const ACTION_CUSTOMIZE_PANEL = 'ACTION_CUSTOMIZE_PANEL';
export const CUSTOM_TIME_RANGE_BADGE = 'CUSTOM_TIME_RANGE_BADGE';
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
import { PrettyDuration } from '@elastic/eui';
import {
Action,
ActionExecutionMeta,
FrequentCompatibilityChangeAction,
IncompatibleActionError,
} from '@kbn/ui-actions-plugin/public';
import React from 'react';

import { UI_SETTINGS } from '@kbn/data-plugin/common';
import { apiPublishesTimeRange, EmbeddableApiContext } from '@kbn/presentation-publishing';
import { core } from '../../kibana_services';
import { customizePanelAction } from '../panel_actions';

export const CUSTOM_TIME_RANGE_BADGE = 'CUSTOM_TIME_RANGE_BADGE';
import { ACTION_CUSTOMIZE_PANEL, CUSTOM_TIME_RANGE_BADGE } from './constants';
import { core, uiActions } from '../../kibana_services';

export class CustomTimeRangeBadge
implements Action<EmbeddableApiContext>, FrequentCompatibilityChangeAction<EmbeddableApiContext>
Expand Down Expand Up @@ -69,8 +68,9 @@ export class CustomTimeRangeBadge
});
}

public async execute({ embeddable }: EmbeddableApiContext) {
customizePanelAction.execute({ embeddable });
public async execute(context: ActionExecutionMeta & EmbeddableApiContext) {
const action = await uiActions.getAction(ACTION_CUSTOMIZE_PANEL);
action.execute(context);
}

public getIconType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {
} from '@kbn/presentation-publishing';
import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { openCustomizePanelFlyout } from './open_customize_panel';

export const ACTION_CUSTOMIZE_PANEL = 'ACTION_CUSTOMIZE_PANEL';
import { ACTION_CUSTOMIZE_PANEL } from './constants';

export type CustomizePanelActionApi = CanAccessViewMode &
Partial<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { hasEditCapabilities } from '@kbn/presentation-publishing';
import { FilterItems } from '@kbn/unified-search-plugin/public';
import { editPanelAction } from '../panel_actions';
import { CustomizePanelActionApi } from './customize_panel_action';
import { executeEditPanelAction } from '../edit_panel_action/execute_edit_action';

export const filterDetailsActionStrings = {
getQueryTitle: () =>
Expand Down Expand Up @@ -75,7 +75,7 @@ export function FiltersDetails({ editMode, api }: FiltersDetailsProps) {
<EuiButtonEmpty
size="xs"
data-test-subj="customizePanelEditQueryButton"
onClick={() => editPanelAction.execute({ embeddable: api })}
onClick={() => executeEditPanelAction(api)}
aria-label={i18n.translate(
'presentationPanel.action.customizePanel.flyout.optionsMenuForm.editQueryButtonAriaLabel',
{
Expand Down Expand Up @@ -112,7 +112,7 @@ export function FiltersDetails({ editMode, api }: FiltersDetailsProps) {
<EuiButtonEmpty
size="xs"
data-test-subj="customizePanelEditFiltersButton"
onClick={() => editPanelAction.execute({ embeddable: api })}
onClick={() => executeEditPanelAction(api)}
aria-label={i18n.translate(
'presentationPanel.action.customizePanel.flyout.optionsMenuForm.editFiltersButtonAriaLabel',
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const ACTION_EDIT_PANEL = 'editPanel';
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import {
FrequentCompatibilityChangeAction,
IncompatibleActionError,
} from '@kbn/ui-actions-plugin/public';

export const ACTION_EDIT_PANEL = 'editPanel';
import { ACTION_EDIT_PANEL } from './constants';

export type EditPanelActionApi = CanAccessViewMode & HasEditCapabilities;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { ActionExecutionMeta } from '@kbn/ui-actions-plugin/public';
import type { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { CONTEXT_MENU_TRIGGER } from '../triggers';
import { ACTION_EDIT_PANEL } from './constants';
import { uiActions } from '../../kibana_services';

export async function executeEditPanelAction(api: unknown) {
try {
const action = await uiActions.getAction(ACTION_EDIT_PANEL);
action.execute({
embeddable: api,
trigger: { id: CONTEXT_MENU_TRIGGER },
} as EmbeddableApiContext & ActionExecutionMeta);
} catch (error) {
// eslint-disable-next-line no-console
console.warn('Unable to execute edit action, Error: ', error.message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export {
ACTION_CUSTOMIZE_PANEL,
CustomizePanelAction,
CustomTimeRangeBadge,
} from './customize_panel_action';
export { EditPanelAction } from './edit_panel_action/edit_panel_action';
export { InspectPanelAction } from './inspect_panel_action/inspect_panel_action';
export { getEditPanelAction } from './panel_actions';
export { RemovePanelAction } from './remove_panel_action/remove_panel_action';
export {
contextMenuTrigger,
CONTEXT_MENU_TRIGGER,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const ACTION_INSPECT_PANEL = 'openInspector';
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import {
HasParentApi,
} from '@kbn/presentation-publishing';
import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { ACTION_INSPECT_PANEL } from './constants';
import { inspector } from '../../kibana_services';

export const ACTION_INSPECT_PANEL = 'openInspector';

export type InspectPanelActionApi = HasInspectorAdapters &
Partial<PublishesPanelTitle & HasParentApi>;
const isApiCompatible = (api: unknown | null): api is InspectPanelActionApi => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { uiActions } from '../kibana_services';
import { ACTION_EDIT_PANEL } from './edit_panel_action/constants';
import { ACTION_INSPECT_PANEL } from './inspect_panel_action/constants';
import { ACTION_REMOVE_PANEL } from './remove_panel_action/constants';
import {
ACTION_CUSTOMIZE_PANEL,
CUSTOM_TIME_RANGE_BADGE,
} from './customize_panel_action/constants';
import { CONTEXT_MENU_TRIGGER, PANEL_BADGE_TRIGGER } from './triggers';

export const registerActions = () => {
uiActions.registerActionAsync(ACTION_REMOVE_PANEL, async () => {
const { RemovePanelAction } = await import('../panel_component/panel_module');
return new RemovePanelAction();
});
uiActions.attachAction(CONTEXT_MENU_TRIGGER, ACTION_REMOVE_PANEL);

uiActions.registerActionAsync(CUSTOM_TIME_RANGE_BADGE, async () => {
const { CustomTimeRangeBadge } = await import('../panel_component/panel_module');
return new CustomTimeRangeBadge();
});
uiActions.attachAction(PANEL_BADGE_TRIGGER, CUSTOM_TIME_RANGE_BADGE);

uiActions.registerActionAsync(ACTION_INSPECT_PANEL, async () => {
const { InspectPanelAction } = await import('../panel_component/panel_module');
return new InspectPanelAction();
});
uiActions.attachAction(CONTEXT_MENU_TRIGGER, ACTION_INSPECT_PANEL);

uiActions.registerActionAsync(ACTION_EDIT_PANEL, async () => {
const { EditPanelAction } = await import('../panel_component/panel_module');
return new EditPanelAction();
});
uiActions.attachAction(CONTEXT_MENU_TRIGGER, ACTION_EDIT_PANEL);

uiActions.registerActionAsync(ACTION_CUSTOMIZE_PANEL, async () => {
const { CustomizePanelAction } = await import('../panel_component/panel_module');
return new CustomizePanelAction();
});
uiActions.attachAction(CONTEXT_MENU_TRIGGER, ACTION_CUSTOMIZE_PANEL);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const ACTION_REMOVE_PANEL = 'deletePanel';
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ import {
PublishesViewMode,
} from '@kbn/presentation-publishing';
import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';

import { getContainerParentFromAPI, PresentationContainer } from '@kbn/presentation-containers';

export const ACTION_REMOVE_PANEL = 'deletePanel';
import { ACTION_REMOVE_PANEL } from './constants';

export type RemovePanelActionApi = PublishesViewMode &
HasUniqueId &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { EmbeddableApiContext } from '@kbn/presentation-publishing';
import type { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { Action } from '@kbn/ui-actions-plugin/public';

export type AnyApiAction = Action<EmbeddableApiContext>;
Loading
Loading