Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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