diff --git a/src/platform/plugins/private/image_embeddable/public/actions/create_image_action.ts b/src/platform/plugins/private/image_embeddable/public/actions/create_image_action.ts index c18b25f7a8179..62e542697dd74 100644 --- a/src/platform/plugins/private/image_embeddable/public/actions/create_image_action.ts +++ b/src/platform/plugins/private/image_embeddable/public/actions/create_image_action.ts @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n'; import { CanAddNewPanel } from '@kbn/presentation-containers'; import { EmbeddableApiContext } from '@kbn/presentation-publishing'; -import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public'; +import { ADD_PANEL_ANNOTATION_GROUP } from '@kbn/embeddable-plugin/public'; import { IncompatibleActionError, ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public'; import { ADD_IMAGE_EMBEDDABLE_ACTION_ID, @@ -48,7 +48,7 @@ export const registerCreateImageAction = () => { // swallow the rejection, since this just means the user closed without saving } }, - grouping: [COMMON_EMBEDDABLE_GROUPING.annotation], + grouping: [ADD_PANEL_ANNOTATION_GROUP], getDisplayName: () => i18n.translate('imageEmbeddable.imageEmbeddableFactory.displayName', { defaultMessage: 'Image', diff --git a/src/platform/plugins/private/links/public/actions/create_links_panel_action.ts b/src/platform/plugins/private/links/public/actions/create_links_panel_action.ts index 666e650d6d586..3fa64383eb797 100644 --- a/src/platform/plugins/private/links/public/actions/create_links_panel_action.ts +++ b/src/platform/plugins/private/links/public/actions/create_links_panel_action.ts @@ -9,7 +9,7 @@ import { EmbeddableApiContext } from '@kbn/presentation-publishing'; import { ADD_PANEL_TRIGGER, IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; -import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public'; +import { ADD_PANEL_ANNOTATION_GROUP } from '@kbn/embeddable-plugin/public'; import { APP_ICON, APP_NAME, CONTENT_ID } from '../../common'; import { uiActions } from '../services/kibana_services'; @@ -38,7 +38,7 @@ export const registerCreateLinksPanelAction = () => { initialState: runtimeState, }); }, - grouping: [COMMON_EMBEDDABLE_GROUPING.annotation], + grouping: [ADD_PANEL_ANNOTATION_GROUP], getDisplayName: () => APP_NAME, }); uiActions.attachAction(ADD_PANEL_TRIGGER, ADD_LINKS_PANEL_ACTION_ID); diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/add_panel_action_menu_items.ts b/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/add_panel_action_menu_items.ts index b91320e321f88..fe1d1e73e5a96 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/add_panel_action_menu_items.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/add_panel_action_menu_items.ts @@ -13,7 +13,7 @@ import { addPanelMenuTrigger, } from '@kbn/ui-actions-plugin/public'; import { PresentationContainer } from '@kbn/presentation-containers'; -import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public'; +import { ADD_PANEL_OTHER_GROUP } from '@kbn/embeddable-plugin/public'; import type { IconType, CommonProps } from '@elastic/eui'; import React, { type MouseEventHandler } from 'react'; @@ -98,12 +98,12 @@ export const getAddPanelActionMenuItemsGroup = ( }); } else { // use other group as the default for definitions that don't have a group - const fallbackGroup = COMMON_EMBEDDABLE_GROUPING.other; + const fallbackGroup = ADD_PANEL_OTHER_GROUP; if (!grouped[fallbackGroup.id]) { grouped[fallbackGroup.id] = { id: fallbackGroup.id, - title: fallbackGroup.getDisplayName?.({ embeddable: api }) || '', + title: fallbackGroup.getDisplayName?.() || '', 'data-test-subj': `dashboardEditorMenu-${fallbackGroup.id}Group`, order: fallbackGroup.order || 0, items: [], diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/use_get_dashboard_panels.test.ts b/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/use_get_dashboard_panels.test.ts index 0bd8d95dc7916..7965403a6b01a 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/use_get_dashboard_panels.test.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/use_get_dashboard_panels.test.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public'; +import { ADD_PANEL_ANNOTATION_GROUP, ADD_PANEL_LEGACY_GROUP } from '@kbn/embeddable-plugin/public'; import type { PresentationContainer } from '@kbn/presentation-containers'; import type { Action, UiActionsService } from '@kbn/ui-actions-plugin/public'; import { ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public'; @@ -92,8 +92,8 @@ describe('Get dashboard panels hook', () => { describe('augmenting ui action group items with dashboard visualization types', () => { it.each([ ['visualizations', VisGroups.PROMOTED], - [COMMON_EMBEDDABLE_GROUPING.legacy.id, VisGroups.LEGACY], - [COMMON_EMBEDDABLE_GROUPING.annotation.id, VisGroups.TOOLS], + [ADD_PANEL_LEGACY_GROUP.id, VisGroups.LEGACY], + [ADD_PANEL_ANNOTATION_GROUP.id, VisGroups.TOOLS], ])( 'includes in the ui action %s group, %s dashboard visualization group types', async (uiActionGroupId, dashboardVisualizationGroupId) => { diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/use_get_dashboard_panels.ts b/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/use_get_dashboard_panels.ts index 4556991816c99..8d26c2a3b5708 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/use_get_dashboard_panels.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_app/top_nav/add_new_panel/use_get_dashboard_panels.ts @@ -10,7 +10,7 @@ import { useCallback, useMemo, useRef } from 'react'; import { AsyncSubject, defer, from, lastValueFrom, map, type Subscription } from 'rxjs'; -import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public'; +import { ADD_PANEL_ANNOTATION_GROUP, ADD_PANEL_LEGACY_GROUP } from '@kbn/embeddable-plugin/public'; import { PresentationContainer } from '@kbn/presentation-containers'; import { ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public'; import { VisGroups, type BaseVisType, type VisTypeAlias } from '@kbn/visualizations-plugin/public'; @@ -155,7 +155,7 @@ export const useGetDashboardPanels = ({ api, createNewVisType }: UseGetDashboard ), }; } - case COMMON_EMBEDDABLE_GROUPING.legacy.id: { + case ADD_PANEL_LEGACY_GROUP.id: { return { ...panelGroup, items: sortGroupPanelsByOrder( @@ -165,7 +165,7 @@ export const useGetDashboardPanels = ({ api, createNewVisType }: UseGetDashboard ), }; } - case COMMON_EMBEDDABLE_GROUPING.annotation.id: { + case ADD_PANEL_ANNOTATION_GROUP.id: { return { ...panelGroup, items: sortGroupPanelsByOrder( diff --git a/src/platform/plugins/shared/embeddable/public/index.ts b/src/platform/plugins/shared/embeddable/public/index.ts index b388427f402bc..88dafd108e5ea 100644 --- a/src/platform/plugins/shared/embeddable/public/index.ts +++ b/src/platform/plugins/shared/embeddable/public/index.ts @@ -12,12 +12,13 @@ import { EmbeddablePublicPlugin } from './plugin'; export { useAddFromLibraryTypes } from './add_from_library/registry'; export { openAddFromLibraryFlyout } from './add_from_library/open_add_from_library_flyout'; +export { PanelNotFoundError, PanelIncompatibleError } from './react_embeddable_system'; +export { EmbeddableStateTransfer } from './state_transfer'; export { cellValueTrigger, CELL_VALUE_TRIGGER, contextMenuTrigger, CONTEXT_MENU_TRIGGER, - EmbeddableStateTransfer, isMultiValueClickTriggerContext, isRangeSelectTriggerContext, isRowClickTriggerContext, @@ -25,26 +26,22 @@ export { MULTI_VALUE_CLICK_TRIGGER, panelBadgeTrigger, panelHoverTrigger, - PanelNotFoundError, - PanelIncompatibleError, panelNotificationTrigger, PANEL_BADGE_TRIGGER, PANEL_HOVER_TRIGGER, PANEL_NOTIFICATION_TRIGGER, SELECT_RANGE_TRIGGER, VALUE_CLICK_TRIGGER, - ViewMode, -} from './lib'; +} from './ui_actions/triggers'; +export { ViewMode } from '../common/types'; export type { CellValueContext, ChartActionContext, - EmbeddableEditorState, - EmbeddablePackageState, MultiValueClickContext, - PropertySpec, RangeSelectContext, ValueClickContext, -} from './lib'; +} from './ui_actions/triggers'; +export type { EmbeddableEditorState, EmbeddablePackageState } from './state_transfer'; export type { EmbeddableSetup, EmbeddableStart } from './types'; export type { EnhancementRegistryDefinition } from './enhancements/types'; @@ -58,4 +55,8 @@ export function plugin(initializerContext: PluginInitializerContext) { return new EmbeddablePublicPlugin(initializerContext); } -export { COMMON_EMBEDDABLE_GROUPING } from './lib/embeddables/common/constants'; +export { + ADD_PANEL_ANNOTATION_GROUP, + ADD_PANEL_OTHER_GROUP, + ADD_PANEL_LEGACY_GROUP, +} from './ui_actions/add_panel_groups'; diff --git a/src/platform/plugins/shared/embeddable/public/lib/embeddables/common/constants.ts b/src/platform/plugins/shared/embeddable/public/lib/embeddables/common/constants.ts deleted file mode 100644 index eec876216da47..0000000000000 --- a/src/platform/plugins/shared/embeddable/public/lib/embeddables/common/constants.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 { i18n } from '@kbn/i18n'; -import { UiActionsPresentableGroup } from '@kbn/ui-actions-plugin/public'; - -export const COMMON_EMBEDDABLE_GROUPING: { [key: string]: UiActionsPresentableGroup } = { - annotation: { - id: 'annotation-and-navigation', - getDisplayName: () => - i18n.translate('embeddableApi.common.constants.grouping.annotations', { - defaultMessage: 'Annotations and Navigation', - }), - order: 900, // This is the order of the group in the context menu - }, - other: { - id: 'other', - getDisplayName: () => - i18n.translate('embeddableApi.common.constants.grouping.other', { - defaultMessage: 'Other', - }), - getIconType: () => 'empty', - order: -1, // Given an item that doesn't specify a group is assigned zero, this forces other to come after all intentionally grouped section - }, - legacy: { - id: 'legacy', - getDisplayName: () => - i18n.translate('embeddableApi.common.constants.grouping.legacy', { - defaultMessage: 'Legacy', - }), - order: -2, // Given an item that doesn't specify a group is assigned zero, this forces it to the bottom of the list - }, -}; diff --git a/src/platform/plugins/shared/embeddable/public/lib/errors.test.ts b/src/platform/plugins/shared/embeddable/public/lib/errors.test.ts deleted file mode 100644 index ebac7371acd51..0000000000000 --- a/src/platform/plugins/shared/embeddable/public/lib/errors.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 { IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; -import { PanelNotFoundError } from './errors'; - -describe('IncompatibleActionError', () => { - test('is instance of error', () => { - const error = new IncompatibleActionError(); - expect(error).toBeInstanceOf(Error); - }); - - test('has INCOMPATIBLE_ACTION code', () => { - const error = new IncompatibleActionError(); - expect(error.code).toBe('INCOMPATIBLE_ACTION'); - }); -}); - -describe('PanelNotFoundError', () => { - test('is instance of error', () => { - const error = new PanelNotFoundError(); - expect(error).toBeInstanceOf(Error); - }); - - test('has PANEL_NOT_FOUND code', () => { - const error = new PanelNotFoundError(); - expect(error.code).toBe('PANEL_NOT_FOUND'); - }); -}); diff --git a/src/platform/plugins/shared/embeddable/public/lib/index.ts b/src/platform/plugins/shared/embeddable/public/lib/index.ts deleted file mode 100644 index 3c816f15095b3..0000000000000 --- a/src/platform/plugins/shared/embeddable/public/lib/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 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 * from './errors'; -export * from './types'; -export * from './triggers'; -export * from './state_transfer'; diff --git a/src/platform/plugins/shared/embeddable/public/lib/types.ts b/src/platform/plugins/shared/embeddable/public/lib/types.ts deleted file mode 100644 index 9a3f98891235d..0000000000000 --- a/src/platform/plugins/shared/embeddable/public/lib/types.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 interface Trigger { - id: string; - title?: string; - description?: string; -} - -export interface PropertySpec { - displayName: string; - accessPath: string; - id: string; - description: string; - value?: string; -} -export { ViewMode } from '../../common/types'; - -export interface CommonlyUsedRange { - from: string; - to: string; - display: string; -} diff --git a/src/platform/plugins/shared/embeddable/public/lib/ui_actions.ts b/src/platform/plugins/shared/embeddable/public/lib/ui_actions.ts deleted file mode 100644 index 27c7992cea05e..0000000000000 --- a/src/platform/plugins/shared/embeddable/public/lib/ui_actions.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * 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 * from '@kbn/ui-actions-plugin/public'; diff --git a/src/platform/plugins/shared/embeddable/public/plugin.tsx b/src/platform/plugins/shared/embeddable/public/plugin.tsx index 84ea1676dd018..288f91f2145fd 100644 --- a/src/platform/plugins/shared/embeddable/public/plugin.tsx +++ b/src/platform/plugins/shared/embeddable/public/plugin.tsx @@ -17,8 +17,8 @@ import { } from '@kbn/core/public'; import { Storage } from '@kbn/kibana-utils-plugin/public'; import { migrateToLatest } from '@kbn/kibana-utils-plugin/common'; -import { bootstrap } from './bootstrap'; -import { EmbeddableStateTransfer } from './lib/state_transfer'; +import { registerTriggers } from './ui_actions/register_triggers'; +import { EmbeddableStateTransfer } from './state_transfer'; import { EmbeddableStateWithType, CommonEmbeddableStartContract } from '../common/types'; import { getExtractFunction, @@ -47,7 +47,7 @@ export class EmbeddablePublicPlugin implements Plugin + i18n.translate('embeddableApi.common.constants.grouping.annotations', { + defaultMessage: 'Annotations and Navigation', + }), + order: 900, // This is the order of the group in the context menu +}; + +export const ADD_PANEL_OTHER_GROUP = { + id: 'other', + getDisplayName: () => + i18n.translate('embeddableApi.common.constants.grouping.other', { + defaultMessage: 'Other', + }), + getIconType: () => 'empty', + order: -1, // Given an item that doesn't specify a group is assigned zero, this forces other to come after all intentionally grouped section +}; + +export const ADD_PANEL_LEGACY_GROUP = { + id: 'legacy', + getDisplayName: () => + i18n.translate('embeddableApi.common.constants.grouping.legacy', { + defaultMessage: 'Legacy', + }), + order: -2, // Given an item that doesn't specify a group is assigned zero, this forces it to the bottom of the list +}; diff --git a/src/platform/plugins/shared/embeddable/public/bootstrap.ts b/src/platform/plugins/shared/embeddable/public/ui_actions/register_triggers.ts similarity index 86% rename from src/platform/plugins/shared/embeddable/public/bootstrap.ts rename to src/platform/plugins/shared/embeddable/public/ui_actions/register_triggers.ts index 1ab5e0b7eac3f..97d2cf0f58399 100644 --- a/src/platform/plugins/shared/embeddable/public/bootstrap.ts +++ b/src/platform/plugins/shared/embeddable/public/ui_actions/register_triggers.ts @@ -17,13 +17,9 @@ import { valueClickTrigger, cellValueTrigger, panelHoverTrigger, -} from './lib'; +} from './triggers'; -/** - * This method initializes Embeddable plugin with initial set of - * triggers and actions. - */ -export const bootstrap = (uiActions: UiActionsSetup) => { +export const registerTriggers = (uiActions: UiActionsSetup) => { uiActions.registerTrigger(contextMenuTrigger); uiActions.registerTrigger(panelHoverTrigger); uiActions.registerTrigger(panelBadgeTrigger); diff --git a/src/platform/plugins/shared/embeddable/public/lib/triggers/triggers.ts b/src/platform/plugins/shared/embeddable/public/ui_actions/triggers.ts similarity index 100% rename from src/platform/plugins/shared/embeddable/public/lib/triggers/triggers.ts rename to src/platform/plugins/shared/embeddable/public/ui_actions/triggers.ts diff --git a/src/plugins/visualizations/public/actions/add_agg_vis_action.ts b/src/plugins/visualizations/public/actions/add_agg_vis_action.ts index f3dfe8807be27..cd3faa92d7787 100644 --- a/src/plugins/visualizations/public/actions/add_agg_vis_action.ts +++ b/src/plugins/visualizations/public/actions/add_agg_vis_action.ts @@ -14,7 +14,7 @@ import { HasType, HasAppContext, } from '@kbn/presentation-publishing'; -import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public'; +import { ADD_PANEL_LEGACY_GROUP } from '@kbn/embeddable-plugin/public'; import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; import { apiHasType } from '@kbn/presentation-publishing'; import { apiCanAddNewPanel, CanAddNewPanel } from '@kbn/presentation-containers'; @@ -33,7 +33,7 @@ const isApiCompatible = (api: unknown | null): api is AddAggVisualizationPanelAc export class AddAggVisualizationPanelAction implements Action { public readonly type = ADD_AGG_VIS_ACTION_ID; public readonly id = ADD_AGG_VIS_ACTION_ID; - public readonly grouping = [COMMON_EMBEDDABLE_GROUPING.legacy]; + public readonly grouping = [ADD_PANEL_LEGACY_GROUP]; private readonly aggVisualizationCreationEnabled: boolean; public readonly order = 20;