From 2ee9cbf377e217cac0fa07a4394d3d0d2184285c Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 2 Jan 2025 11:43:14 -0700 Subject: [PATCH] [embeddable] remove embeddable class (#205164) Part of embeddable rebuild clean-up. Removes legacy Embeddable class and types from embeddable plugin. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine --- .../embeddable_api_context.ts | 22 +++++++ .../presentation_publishing/index.ts | 8 +-- .../dashboard/public/dashboard_api/types.ts | 11 +--- .../public/dashboard_container/index.ts | 1 - .../panel_placement/index.ts | 2 +- .../panel_placement/types.ts | 11 ---- .../plugins/shared/dashboard/public/index.ts | 1 - .../plugins/shared/embeddable/public/index.ts | 7 --- .../embeddables/embeddable_error_handler.tsx | 58 ------------------- .../public/lib/embeddables/index.ts | 14 ----- .../shared/embeddable/public/lib/index.ts | 1 - .../public/lib/triggers/triggers.ts | 14 ----- .../plugins/shared/embeddable/tsconfig.json | 1 - .../floating_actions/floating_actions.tsx | 3 +- .../dynamic_action_grouping.ts | 6 +- src/plugins/visualizations/kibana.jsonc | 3 +- .../create_vis_embeddable_from_object.ts | 2 +- .../embeddable}/diff_embeddable_input.test.ts | 3 +- .../embeddable}/diff_embeddable_input.ts | 2 +- .../public/legacy/embeddable}/embeddable.tsx | 2 +- .../legacy/embeddable}/error_embeddable.scss | 0 .../legacy/embeddable}/error_embeddable.tsx | 0 .../public/legacy/embeddable}/i_embeddable.ts | 2 +- .../embeddable/visualize_embeddable.tsx | 4 +- src/plugins/visualizations/tsconfig.json | 3 +- .../legacy_visualizations/is_legacy_map.ts | 11 +--- .../shared/ml/public/embeddables/types.ts | 3 +- .../public/lib/variables/event_variables.ts | 9 ++- .../plugins/apm/public/embeddable/types.ts | 2 +- .../lens/add_to_timeline.test.ts | 26 ++++----- .../lens/copy_to_clipboard.test.ts | 19 +++--- .../alerts_histogram_panel/helpers.test.tsx | 6 +- .../alerts_histogram_panel/helpers.tsx | 8 ++- 33 files changed, 77 insertions(+), 188 deletions(-) create mode 100644 src/platform/packages/shared/presentation/presentation_publishing/embeddable_api_context.ts delete mode 100644 src/platform/plugins/shared/embeddable/public/lib/embeddables/embeddable_error_handler.tsx delete mode 100644 src/platform/plugins/shared/embeddable/public/lib/embeddables/index.ts rename src/{platform/plugins/shared/embeddable/public/lib/embeddables => plugins/visualizations/public/legacy/embeddable}/diff_embeddable_input.test.ts (98%) rename src/{platform/plugins/shared/embeddable/public/lib/embeddables => plugins/visualizations/public/legacy/embeddable}/diff_embeddable_input.ts (97%) rename src/{platform/plugins/shared/embeddable/public/lib/embeddables => plugins/visualizations/public/legacy/embeddable}/embeddable.tsx (99%) rename src/{platform/plugins/shared/embeddable/public/lib/embeddables => plugins/visualizations/public/legacy/embeddable}/error_embeddable.scss (100%) rename src/{platform/plugins/shared/embeddable/public/lib/embeddables => plugins/visualizations/public/legacy/embeddable}/error_embeddable.tsx (100%) rename src/{platform/plugins/shared/embeddable/public/lib/embeddables => plugins/visualizations/public/legacy/embeddable}/i_embeddable.ts (98%) diff --git a/src/platform/packages/shared/presentation/presentation_publishing/embeddable_api_context.ts b/src/platform/packages/shared/presentation/presentation_publishing/embeddable_api_context.ts new file mode 100644 index 0000000000000..3af7b7f428596 --- /dev/null +++ b/src/platform/packages/shared/presentation/presentation_publishing/embeddable_api_context.ts @@ -0,0 +1,22 @@ +/* + * 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 EmbeddableApiContext { + /** + * TODO: once all actions are entirely decoupled from the embeddable system, this key should be renamed to "api" + * to reflect the fact that this context could contain any api. + */ + embeddable: unknown; +} + +export const isEmbeddableApiContext = (context: unknown): context is EmbeddableApiContext => + !!context && + typeof context === 'object' && + !!(context as EmbeddableApiContext).embeddable && + typeof (context as EmbeddableApiContext).embeddable === 'object'; diff --git a/src/platform/packages/shared/presentation/presentation_publishing/index.ts b/src/platform/packages/shared/presentation/presentation_publishing/index.ts index 09e6453586665..62e68521a5b09 100644 --- a/src/platform/packages/shared/presentation/presentation_publishing/index.ts +++ b/src/platform/packages/shared/presentation/presentation_publishing/index.ts @@ -7,13 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -export interface EmbeddableApiContext { - /** - * TODO: once all actions are entirely decoupled from the embeddable system, this key should be renamed to "api" - * to reflect the fact that this context could contain any api. - */ - embeddable: unknown; -} +export { isEmbeddableApiContext, type EmbeddableApiContext } from './embeddable_api_context'; export { getInitialValuesFromComparators, diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_api/types.ts b/src/platform/plugins/shared/dashboard/public/dashboard_api/types.ts index 73e7e9422641f..238bd5976bfa1 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_api/types.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_api/types.ts @@ -41,12 +41,7 @@ import { ControlGroupSerializedState, } from '@kbn/controls-plugin/public'; import { Filter, Query, TimeRange } from '@kbn/es-query'; -import { - DefaultEmbeddableApi, - EmbeddablePackageState, - ErrorEmbeddable, - IEmbeddable, -} from '@kbn/embeddable-plugin/public'; +import type { DefaultEmbeddableApi, EmbeddablePackageState } from '@kbn/embeddable-plugin/public'; import { Observable, Subject } from 'rxjs'; import { RefreshInterval, SearchSessionInfoProvider } from '@kbn/data-plugin/public'; import { IKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public'; @@ -175,9 +170,7 @@ export type DashboardApi = CanExpandPanels & setTags: (tags: string[]) => void; setTimeRange: (timeRange?: TimeRange | undefined) => void; unifiedSearchFilters$: PublishesUnifiedSearch['filters$']; - - // TODO remove types below this line - from legacy embeddable system - untilEmbeddableLoaded: (id: string) => Promise; + untilEmbeddableLoaded: (id: string) => Promise; }; export interface DashboardInternalApi { diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_container/index.ts b/src/platform/plugins/shared/dashboard/public/dashboard_container/index.ts index c3f1989d66cd6..02b84b619aaf9 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_container/index.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_container/index.ts @@ -16,4 +16,3 @@ export const LATEST_DASHBOARD_CONTAINER_VERSION = convertNumberToDashboardVersio export { LazyDashboardRenderer } from './external_api/lazy_dashboard_renderer'; export type { DashboardLocatorParams } from './types'; -export type { IProvidesLegacyPanelPlacementSettings } from './panel_placement'; diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_container/panel_placement/index.ts b/src/platform/plugins/shared/dashboard/public/dashboard_container/panel_placement/index.ts index d903886695745..3706aefca3512 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_container/panel_placement/index.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_container/panel_placement/index.ts @@ -11,4 +11,4 @@ export { placeClonePanel } from './place_clone_panel_strategy'; export { registerDashboardPanelPlacementSetting } from './panel_placement_registry'; -export type { GetPanelPlacementSettings, IProvidesLegacyPanelPlacementSettings } from './types'; +export type { GetPanelPlacementSettings } from './types'; diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_container/panel_placement/types.ts b/src/platform/plugins/shared/dashboard/public/dashboard_container/panel_placement/types.ts index 2dd826f9a5821..93f9d2d7fc78e 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_container/panel_placement/types.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_container/panel_placement/types.ts @@ -7,7 +7,6 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { EmbeddableInput } from '@kbn/embeddable-plugin/public'; import { MaybePromise } from '@kbn/utility-types'; import { DashboardPanelState } from '../../../common'; import type { GridData } from '../../../server/content_management'; @@ -30,16 +29,6 @@ export interface PanelPlacementProps { currentPanels: { [key: string]: DashboardPanelState }; } -export interface IProvidesLegacyPanelPlacementSettings< - InputType extends EmbeddableInput = EmbeddableInput, - AttributesType = unknown -> { - getLegacyPanelPlacementSettings: ( - input: InputType, - attributes?: AttributesType - ) => Partial; -} - export type GetPanelPlacementSettings = ( serializedState?: SerializedState ) => MaybePromise; diff --git a/src/platform/plugins/shared/dashboard/public/index.ts b/src/platform/plugins/shared/dashboard/public/index.ts index 109be5bc0eaf0..458d1cc35ddde 100644 --- a/src/platform/plugins/shared/dashboard/public/index.ts +++ b/src/platform/plugins/shared/dashboard/public/index.ts @@ -22,7 +22,6 @@ export { LazyDashboardRenderer as DashboardRenderer, DASHBOARD_CONTAINER_TYPE, type DashboardLocatorParams, - type IProvidesLegacyPanelPlacementSettings, } from './dashboard_container'; export type { DashboardSetup, DashboardStart, DashboardFeatureFlagConfig } from './plugin'; diff --git a/src/platform/plugins/shared/embeddable/public/index.ts b/src/platform/plugins/shared/embeddable/public/index.ts index 4ec1c43df2dbb..b388427f402bc 100644 --- a/src/platform/plugins/shared/embeddable/public/index.ts +++ b/src/platform/plugins/shared/embeddable/public/index.ts @@ -17,10 +17,7 @@ export { CELL_VALUE_TRIGGER, contextMenuTrigger, CONTEXT_MENU_TRIGGER, - Embeddable, EmbeddableStateTransfer, - ErrorEmbeddable, - isContextMenuTriggerContext, isMultiValueClickTriggerContext, isRangeSelectTriggerContext, isRowClickTriggerContext, @@ -41,12 +38,8 @@ export { export type { CellValueContext, ChartActionContext, - EmbeddableContext, EmbeddableEditorState, - EmbeddableInput, - EmbeddableOutput, EmbeddablePackageState, - IEmbeddable, MultiValueClickContext, PropertySpec, RangeSelectContext, diff --git a/src/platform/plugins/shared/embeddable/public/lib/embeddables/embeddable_error_handler.tsx b/src/platform/plugins/shared/embeddable/public/lib/embeddables/embeddable_error_handler.tsx deleted file mode 100644 index 33402bfb85e0d..0000000000000 --- a/src/platform/plugins/shared/embeddable/public/lib/embeddables/embeddable_error_handler.tsx +++ /dev/null @@ -1,58 +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 { isFunction } from 'lodash'; -import React, { ReactNode, useEffect, useRef, useState } from 'react'; -import { isPromise } from '@kbn/std'; -import type { MaybePromise } from '@kbn/utility-types'; -import type { ErrorLike } from '@kbn/expressions-plugin/common'; -import type { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable'; - -type IReactEmbeddable = IEmbeddable>; - -interface EmbeddableErrorHandlerProps { - children: IReactEmbeddable['catchError']; - embeddable?: IReactEmbeddable; - error: ErrorLike | string; -} - -export function EmbeddableErrorHandler({ - children, - embeddable, - error, -}: EmbeddableErrorHandlerProps) { - const [node, setNode] = useState(); - const ref = useRef(null); - - useEffect(() => { - if (!ref.current) { - return; - } - - const handler = embeddable?.catchError?.bind(embeddable) ?? children; - if (!handler) { - return; - } - - const renderedNode = handler( - typeof error === 'string' ? { message: error, name: '' } : error, - ref.current - ); - if (isFunction(renderedNode)) { - return renderedNode; - } - if (isPromise(renderedNode)) { - renderedNode.then(setNode); - } else { - setNode(renderedNode); - } - }, [children, embeddable, error]); - - return
{node}
; -} diff --git a/src/platform/plugins/shared/embeddable/public/lib/embeddables/index.ts b/src/platform/plugins/shared/embeddable/public/lib/embeddables/index.ts deleted file mode 100644 index 029a653a9f1c6..0000000000000 --- a/src/platform/plugins/shared/embeddable/public/lib/embeddables/index.ts +++ /dev/null @@ -1,14 +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 '../../../common/lib/saved_object_embeddable'; -export { Embeddable } from './embeddable'; -export { EmbeddableErrorHandler } from './embeddable_error_handler'; -export { ErrorEmbeddable } from './error_embeddable'; -export type { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable'; diff --git a/src/platform/plugins/shared/embeddable/public/lib/index.ts b/src/platform/plugins/shared/embeddable/public/lib/index.ts index 60f8a3638816d..3c816f15095b3 100644 --- a/src/platform/plugins/shared/embeddable/public/lib/index.ts +++ b/src/platform/plugins/shared/embeddable/public/lib/index.ts @@ -8,7 +8,6 @@ */ export * from './errors'; -export * from './embeddables'; export * from './types'; export * from './triggers'; export * from './state_transfer'; diff --git a/src/platform/plugins/shared/embeddable/public/lib/triggers/triggers.ts b/src/platform/plugins/shared/embeddable/public/lib/triggers/triggers.ts index 818c80283bf1c..cdebc6129afb6 100644 --- a/src/platform/plugins/shared/embeddable/public/lib/triggers/triggers.ts +++ b/src/platform/plugins/shared/embeddable/public/lib/triggers/triggers.ts @@ -12,14 +12,6 @@ import type { EmbeddableApiContext } from '@kbn/presentation-publishing'; import { Datatable, DatatableColumnMeta } from '@kbn/expressions-plugin/common'; import { Trigger, RowClickContext } from '@kbn/ui-actions-plugin/public'; import { BooleanRelation } from '@kbn/es-query'; -import { IEmbeddable } from '..'; - -/** - * @deprecated use `EmbeddableApiContext` from `@kbn/presentation-publishing` - */ -export interface EmbeddableContext { - embeddable: T; -} export type ValueClickContext = Partial & { data: { @@ -192,9 +184,3 @@ export const isRowClickTriggerContext = (context: ChartActionContext): context i !!context.data && typeof context.data === 'object' && typeof (context as RowClickContext).data.rowIndex === 'number'; - -export const isContextMenuTriggerContext = (context: unknown): context is EmbeddableContext => - !!context && - typeof context === 'object' && - !!(context as EmbeddableContext).embeddable && - typeof (context as EmbeddableContext).embeddable === 'object'; diff --git a/src/platform/plugins/shared/embeddable/tsconfig.json b/src/platform/plugins/shared/embeddable/tsconfig.json index aeb64ab3f2c32..54498ade512b6 100644 --- a/src/platform/plugins/shared/embeddable/tsconfig.json +++ b/src/platform/plugins/shared/embeddable/tsconfig.json @@ -12,7 +12,6 @@ "@kbn/utility-types", "@kbn/es-query", "@kbn/i18n", - "@kbn/std", "@kbn/expressions-plugin", "@kbn/saved-objects-management-plugin", "@kbn/saved-objects-tagging-oss-plugin", diff --git a/src/platform/plugins/shared/presentation_util/public/components/floating_actions/floating_actions.tsx b/src/platform/plugins/shared/presentation_util/public/components/floating_actions/floating_actions.tsx index ade106ae11098..4fcc0ef869c96 100644 --- a/src/platform/plugins/shared/presentation_util/public/components/floating_actions/floating_actions.tsx +++ b/src/platform/plugins/shared/presentation_util/public/components/floating_actions/floating_actions.tsx @@ -15,7 +15,6 @@ import { Subscription } from 'rxjs'; import { PANEL_HOVER_TRIGGER, panelHoverTrigger, - type EmbeddableInput, type ViewMode, } from '@kbn/embeddable-plugin/public'; import { apiHasUniqueId } from '@kbn/presentation-publishing'; @@ -31,7 +30,7 @@ export interface FloatingActionsProps { isEnabled?: boolean; api?: unknown; viewMode?: ViewMode; - disabledActions?: EmbeddableInput['disabledActions']; + disabledActions?: string[]; } export type FloatingActionItem = AnyApiAction & { diff --git a/src/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_grouping.ts b/src/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_grouping.ts index 640a3bbb70391..8493c00d522b5 100644 --- a/src/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_grouping.ts +++ b/src/plugins/ui_actions_enhanced/public/dynamic_actions/dynamic_action_grouping.ts @@ -8,12 +8,10 @@ */ import { i18n } from '@kbn/i18n'; -import { IEmbeddable } from '@kbn/embeddable-plugin/public'; +import type { EmbeddableApiContext } from '@kbn/presentation-publishing'; import { UiActionsPresentableGrouping as PresentableGrouping } from '@kbn/ui-actions-plugin/public'; -export const dynamicActionGrouping: PresentableGrouping<{ - embeddable?: IEmbeddable; -}> = [ +export const dynamicActionGrouping: PresentableGrouping = [ { id: 'dynamicActions', getDisplayName: () => diff --git a/src/plugins/visualizations/kibana.jsonc b/src/plugins/visualizations/kibana.jsonc index 8e8b492e99a0b..33817bed4357f 100644 --- a/src/plugins/visualizations/kibana.jsonc +++ b/src/plugins/visualizations/kibana.jsonc @@ -45,7 +45,8 @@ "kibanaUtils", "kibanaReact", "charts", - "savedObjects" + "savedObjects", + "presentationPanel" ], "extraPublicDirs": [ "common/constants", diff --git a/src/plugins/visualizations/public/legacy/embeddable/create_vis_embeddable_from_object.ts b/src/plugins/visualizations/public/legacy/embeddable/create_vis_embeddable_from_object.ts index 76acb5da63c53..843aa51731abc 100644 --- a/src/plugins/visualizations/public/legacy/embeddable/create_vis_embeddable_from_object.ts +++ b/src/plugins/visualizations/public/legacy/embeddable/create_vis_embeddable_from_object.ts @@ -7,7 +7,6 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { ErrorEmbeddable } from '@kbn/embeddable-plugin/public'; import type { DataView } from '@kbn/data-views-plugin/public'; import { Vis } from '../../types'; import type { @@ -22,6 +21,7 @@ import { getHttp, getTimeFilter, getCapabilities } from '../../services'; import { urlFor } from '../../utils/saved_visualize_utils'; import { createVisualizeEmbeddableAsync } from './visualize_embeddable_async'; import { AttributeService } from './attribute_service'; +import { ErrorEmbeddable } from './error_embeddable'; /** @deprecated * VisualizeEmbeddable is no longer registered with the legacy embeddable system and is only diff --git a/src/platform/plugins/shared/embeddable/public/lib/embeddables/diff_embeddable_input.test.ts b/src/plugins/visualizations/public/legacy/embeddable/diff_embeddable_input.test.ts similarity index 98% rename from src/platform/plugins/shared/embeddable/public/lib/embeddables/diff_embeddable_input.test.ts rename to src/plugins/visualizations/public/legacy/embeddable/diff_embeddable_input.test.ts index b4b8a2a1da920..80724cca7cd9f 100644 --- a/src/platform/plugins/shared/embeddable/public/lib/embeddables/diff_embeddable_input.test.ts +++ b/src/plugins/visualizations/public/legacy/embeddable/diff_embeddable_input.test.ts @@ -7,9 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { ViewMode } from '..'; import { KibanaExecutionContext } from '@kbn/core/types'; -import { EmbeddableInput } from '.'; +import { EmbeddableInput, ViewMode } from '@kbn/embeddable-plugin/common'; import { omitGenericEmbeddableInput, genericEmbeddableInputIsEqual } from './diff_embeddable_input'; const getGenericEmbeddableState = (state?: Partial): EmbeddableInput => { diff --git a/src/platform/plugins/shared/embeddable/public/lib/embeddables/diff_embeddable_input.ts b/src/plugins/visualizations/public/legacy/embeddable/diff_embeddable_input.ts similarity index 97% rename from src/platform/plugins/shared/embeddable/public/lib/embeddables/diff_embeddable_input.ts rename to src/plugins/visualizations/public/legacy/embeddable/diff_embeddable_input.ts index ba55f098bba45..baf145152f72b 100644 --- a/src/platform/plugins/shared/embeddable/public/lib/embeddables/diff_embeddable_input.ts +++ b/src/plugins/visualizations/public/legacy/embeddable/diff_embeddable_input.ts @@ -9,7 +9,7 @@ import fastIsEqual from 'fast-deep-equal'; import { pick, omit } from 'lodash'; -import { EmbeddableInput } from '.'; +import type { EmbeddableInput } from '@kbn/embeddable-plugin/common'; // list out the keys from the EmbeddableInput type to allow lodash to pick them later const allGenericInputKeys: Readonly> = [ diff --git a/src/platform/plugins/shared/embeddable/public/lib/embeddables/embeddable.tsx b/src/plugins/visualizations/public/legacy/embeddable/embeddable.tsx similarity index 99% rename from src/platform/plugins/shared/embeddable/public/lib/embeddables/embeddable.tsx rename to src/plugins/visualizations/public/legacy/embeddable/embeddable.tsx index 3af13b3d998a3..738df6d3280ea 100644 --- a/src/platform/plugins/shared/embeddable/public/lib/embeddables/embeddable.tsx +++ b/src/plugins/visualizations/public/legacy/embeddable/embeddable.tsx @@ -14,8 +14,8 @@ import { merge } from 'rxjs'; import { debounceTime, distinctUntilChanged, map, skip } from 'rxjs'; import { RenderCompleteDispatcher } from '@kbn/kibana-utils-plugin/public'; import { Adapters } from '@kbn/inspector-plugin/public'; +import { EmbeddableInput, ViewMode } from '@kbn/embeddable-plugin/common'; import { EmbeddableError, EmbeddableOutput, IEmbeddable } from './i_embeddable'; -import { EmbeddableInput, ViewMode } from '../../../common/types'; import { genericEmbeddableInputIsEqual, omitGenericEmbeddableInput } from './diff_embeddable_input'; function getPanelTitle(input: EmbeddableInput, output: EmbeddableOutput) { diff --git a/src/platform/plugins/shared/embeddable/public/lib/embeddables/error_embeddable.scss b/src/plugins/visualizations/public/legacy/embeddable/error_embeddable.scss similarity index 100% rename from src/platform/plugins/shared/embeddable/public/lib/embeddables/error_embeddable.scss rename to src/plugins/visualizations/public/legacy/embeddable/error_embeddable.scss diff --git a/src/platform/plugins/shared/embeddable/public/lib/embeddables/error_embeddable.tsx b/src/plugins/visualizations/public/legacy/embeddable/error_embeddable.tsx similarity index 100% rename from src/platform/plugins/shared/embeddable/public/lib/embeddables/error_embeddable.tsx rename to src/plugins/visualizations/public/legacy/embeddable/error_embeddable.tsx diff --git a/src/platform/plugins/shared/embeddable/public/lib/embeddables/i_embeddable.ts b/src/plugins/visualizations/public/legacy/embeddable/i_embeddable.ts similarity index 98% rename from src/platform/plugins/shared/embeddable/public/lib/embeddables/i_embeddable.ts rename to src/plugins/visualizations/public/legacy/embeddable/i_embeddable.ts index 51a24527dd4aa..29bb089ceeef2 100644 --- a/src/platform/plugins/shared/embeddable/public/lib/embeddables/i_embeddable.ts +++ b/src/plugins/visualizations/public/legacy/embeddable/i_embeddable.ts @@ -10,7 +10,7 @@ import { ErrorLike } from '@kbn/expressions-plugin/common'; import { Adapters } from '@kbn/inspector-plugin/public'; import { Observable } from 'rxjs'; -import { EmbeddableInput } from '../../../common/types'; +import type { EmbeddableInput } from '@kbn/embeddable-plugin/common'; export type EmbeddableError = ErrorLike; export type { EmbeddableInput }; diff --git a/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx b/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx index 1f631f30f8eb5..3f77ce9ecb661 100644 --- a/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx +++ b/src/plugins/visualizations/public/legacy/embeddable/visualize_embeddable.tsx @@ -22,7 +22,7 @@ import type { DataView } from '@kbn/data-views-plugin/public'; import { Warnings } from '@kbn/charts-plugin/public'; import { hasUnsupportedDownsampledAggregationFailure } from '@kbn/search-response-warnings'; import { Adapters } from '@kbn/inspector-plugin/public'; -import { Embeddable, EmbeddableInput, EmbeddableOutput } from '@kbn/embeddable-plugin/public'; +import { EmbeddableInput } from '@kbn/embeddable-plugin/common'; import { SavedObjectEmbeddableInput } from '@kbn/embeddable-plugin/common'; import { ExpressionAstExpression, @@ -47,6 +47,8 @@ import { VisSavedObject } from '../../types'; import { toExpressionAst } from '../../embeddable/to_ast'; import { AttributeService } from './attribute_service'; import { VisualizationsStartDeps } from '../../plugin'; +import { Embeddable } from './embeddable'; +import { EmbeddableOutput } from './i_embeddable'; export interface VisualizeEmbeddableDeps { start: StartServicesGetter< diff --git a/src/plugins/visualizations/tsconfig.json b/src/plugins/visualizations/tsconfig.json index 51deaf4139aa2..32811524e65f7 100644 --- a/src/plugins/visualizations/tsconfig.json +++ b/src/plugins/visualizations/tsconfig.json @@ -73,7 +73,8 @@ "@kbn/search-response-warnings", "@kbn/embeddable-enhanced-plugin", "@kbn/content-management-utils", - "@kbn/react-hooks" + "@kbn/react-hooks", + "@kbn/presentation-panel-plugin" ], "exclude": ["target/**/*"] } diff --git a/x-pack/platform/plugins/shared/maps/public/legacy_visualizations/is_legacy_map.ts b/x-pack/platform/plugins/shared/maps/public/legacy_visualizations/is_legacy_map.ts index 46f7b9cf27be5..bf04fd37ea74f 100644 --- a/x-pack/platform/plugins/shared/maps/public/legacy_visualizations/is_legacy_map.ts +++ b/x-pack/platform/plugins/shared/maps/public/legacy_visualizations/is_legacy_map.ts @@ -5,16 +5,7 @@ * 2.0. */ -import { Embeddable } from '@kbn/embeddable-plugin/public'; -import type { HasVisualizeConfig, VisualizeEmbeddable } from '@kbn/visualizations-plugin/public'; - -export function isLegacyMap(embeddable: Embeddable) { - return ( - embeddable.type === 'visualization' && - typeof (embeddable as VisualizeEmbeddable).getVis === 'function' && - ['region_map', 'tile_map'].includes((embeddable as VisualizeEmbeddable).getVis()?.type?.name) - ); -} +import type { HasVisualizeConfig } from '@kbn/visualizations-plugin/public'; export function isLegacyMapApi(api: HasVisualizeConfig) { return ['region_map', 'tile_map'].includes(api.getVis().type?.name); diff --git a/x-pack/platform/plugins/shared/ml/public/embeddables/types.ts b/x-pack/platform/plugins/shared/ml/public/embeddables/types.ts index 1bcb0f9ae3579..56749e7ab40cb 100644 --- a/x-pack/platform/plugins/shared/ml/public/embeddables/types.ts +++ b/x-pack/platform/plugins/shared/ml/public/embeddables/types.ts @@ -7,7 +7,8 @@ import type { CoreStart } from '@kbn/core/public'; import type { RefreshInterval } from '@kbn/data-plugin/common'; -import type { DefaultEmbeddableApi, EmbeddableInput } from '@kbn/embeddable-plugin/public'; +import type { DefaultEmbeddableApi } from '@kbn/embeddable-plugin/public'; +import type { EmbeddableInput } from '@kbn/embeddable-plugin/common'; import type { Filter, Query, TimeRange } from '@kbn/es-query'; import type { MlEntityField } from '@kbn/ml-anomaly-utils'; import type { diff --git a/x-pack/plugins/drilldowns/url_drilldown/public/lib/variables/event_variables.ts b/x-pack/plugins/drilldowns/url_drilldown/public/lib/variables/event_variables.ts index a66f1d1905dd8..7ef361172967a 100644 --- a/x-pack/plugins/drilldowns/url_drilldown/public/lib/variables/event_variables.ts +++ b/x-pack/plugins/drilldowns/url_drilldown/public/lib/variables/event_variables.ts @@ -7,13 +7,16 @@ import { i18n } from '@kbn/i18n'; import { monaco } from '@kbn/monaco'; -import { getPanelTitle, type PublishesPanelTitle } from '@kbn/presentation-publishing'; +import { + getPanelTitle, + isEmbeddableApiContext, + type PublishesPanelTitle, +} from '@kbn/presentation-publishing'; import { ChartActionContext, isRangeSelectTriggerContext, isValueClickTriggerContext, isRowClickTriggerContext, - isContextMenuTriggerContext, RangeSelectContext, SELECT_RANGE_TRIGGER, ValueClickContext, @@ -131,7 +134,7 @@ export const getEventScopeValues = (context: ChartActionContext): UrlDrilldownEv return getEventScopeFromValueClickTriggerContext(context); } else if (isRowClickTriggerContext(context)) { return getEventScopeFromRowClickTriggerContext(context); - } else if (isContextMenuTriggerContext(context)) { + } else if (isEmbeddableApiContext(context)) { return {}; } else { throw new Error("UrlDrilldown [getEventScope] can't build scope from not supported trigger"); diff --git a/x-pack/solutions/observability/plugins/apm/public/embeddable/types.ts b/x-pack/solutions/observability/plugins/apm/public/embeddable/types.ts index 14b8d18fe2101..1e61aedcd0e2d 100644 --- a/x-pack/solutions/observability/plugins/apm/public/embeddable/types.ts +++ b/x-pack/solutions/observability/plugins/apm/public/embeddable/types.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import type { EmbeddableInput } from '@kbn/embeddable-plugin/public'; +import type { EmbeddableInput } from '@kbn/embeddable-plugin/common'; import type { CoreStart, CoreSetup } from '@kbn/core/public'; import type { ObservabilityRuleTypeRegistry } from '@kbn/observability-plugin/public'; import type { ApmPluginStartDeps, ApmPluginSetupDeps } from '../plugin'; diff --git a/x-pack/solutions/security/plugins/security_solution/public/app/actions/add_to_timeline/lens/add_to_timeline.test.ts b/x-pack/solutions/security/plugins/security_solution/public/app/actions/add_to_timeline/lens/add_to_timeline.test.ts index ef920458f51dd..362fb5f9ee885 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/app/actions/add_to_timeline/lens/add_to_timeline.test.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/app/actions/add_to_timeline/lens/add_to_timeline.test.ts @@ -5,8 +5,7 @@ * 2.0. */ import { BehaviorSubject, Subject } from 'rxjs'; -import type { CellValueContext, EmbeddableInput, IEmbeddable } from '@kbn/embeddable-plugin/public'; -import { ErrorEmbeddable } from '@kbn/embeddable-plugin/public'; +import type { CellValueContext } from '@kbn/embeddable-plugin/public'; import type { SecurityAppStore } from '../../../../common/store/types'; import { createAddToTimelineLensAction, getInvestigatedValue } from './add_to_timeline'; import { KibanaServices } from '../../../../common/lib/kibana'; @@ -15,7 +14,7 @@ import type { DataProvider } from '../../../../../common/types'; import { TimelineId, EXISTS_OPERATOR } from '../../../../../common/types'; import { addProvider } from '../../../../timelines/store/actions'; import type { ActionExecutionContext } from '@kbn/ui-actions-plugin/public'; -import type { Query, Filter, AggregateQuery, TimeRange } from '@kbn/es-query'; +import type { TimeRange } from '@kbn/es-query'; import type { LensApi } from '@kbn/lens-plugin/public'; import { getLensApiMock } from '@kbn/lens-plugin/public/react_embeddable/mocks'; @@ -46,16 +45,6 @@ const getMockLensApi = ( saveToLibrary: jest.fn(async () => 'saved-id'), }); -const getMockEmbeddable = (type: string): IEmbeddable => - ({ - type, - filters$: new BehaviorSubject([]), - query$: new BehaviorSubject({ - query: 'test', - language: 'kuery', - }), - } as unknown as IEmbeddable); - const lensEmbeddable = getMockLensApi(); const columnMeta = { @@ -90,11 +79,14 @@ describe('createAddToTimelineLensAction', () => { }); describe('isCompatible', () => { - it('should return false if error embeddable', async () => { + it('should return false if lens embeddable has blocking error', async () => { expect( await addToTimelineAction.isCompatible({ ...context, - embeddable: new ErrorEmbeddable('some error', {} as EmbeddableInput), + embeddable: { + ...getMockLensApi(), + blockingError: new BehaviorSubject(new Error('some error')), + }, }) ).toEqual(false); }); @@ -103,7 +95,9 @@ describe('createAddToTimelineLensAction', () => { expect( await addToTimelineAction.isCompatible({ ...context, - embeddable: getMockEmbeddable('not_lens') as unknown as IEmbeddable, + embeddable: { + type: 'not_lens', + }, }) ).toEqual(false); }); diff --git a/x-pack/solutions/security/plugins/security_solution/public/app/actions/copy_to_clipboard/lens/copy_to_clipboard.test.ts b/x-pack/solutions/security/plugins/security_solution/public/app/actions/copy_to_clipboard/lens/copy_to_clipboard.test.ts index 0ec4e00848348..98a8b07fd127d 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/app/actions/copy_to_clipboard/lens/copy_to_clipboard.test.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/app/actions/copy_to_clipboard/lens/copy_to_clipboard.test.ts @@ -5,8 +5,7 @@ * 2.0. */ -import type { CellValueContext, EmbeddableInput, IEmbeddable } from '@kbn/embeddable-plugin/public'; -import { ErrorEmbeddable } from '@kbn/embeddable-plugin/public'; +import type { CellValueContext } from '@kbn/embeddable-plugin/public'; import type { LensApi } from '@kbn/lens-plugin/public'; import { createCopyToClipboardLensAction } from './copy_to_clipboard'; import { KibanaServices } from '../../../../common/lib/kibana'; @@ -40,13 +39,6 @@ const getMockLensApi = ( saveToLibrary: jest.fn(async () => 'saved-id'), }); -const getMockEmbeddable = (type: string): IEmbeddable => - ({ - type, - getFilters: jest.fn(), - getQuery: jest.fn(), - } as unknown as IEmbeddable); - const lensEmbeddable = getMockLensApi(); const columnMeta = { @@ -83,7 +75,10 @@ describe('createCopyToClipboardLensAction', () => { expect( await copyToClipboardAction.isCompatible({ ...context, - embeddable: new ErrorEmbeddable('some error', {} as EmbeddableInput), + embeddable: { + ...getMockLensApi(), + blockingError: new BehaviorSubject(new Error('some error')), + }, }) ).toEqual(false); }); @@ -92,7 +87,9 @@ describe('createCopyToClipboardLensAction', () => { expect( await copyToClipboardAction.isCompatible({ ...context, - embeddable: getMockEmbeddable('not_lens') as unknown as IEmbeddable, + embeddable: { + type: 'not_lens', + }, }) ).toEqual(false); }); diff --git a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts_kpis/alerts_histogram_panel/helpers.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts_kpis/alerts_histogram_panel/helpers.test.tsx index 2599b10b93a48..c590bd12bddb1 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts_kpis/alerts_histogram_panel/helpers.test.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts_kpis/alerts_histogram_panel/helpers.test.tsx @@ -5,10 +5,8 @@ * 2.0. */ import type { Action, ActionExecutionContext } from '@kbn/ui-actions-plugin/public'; -import type { Embeddable } from '@kbn/embeddable-plugin/public'; import { createResetGroupByFieldAction, showInitialLoadingSpinner } from './helpers'; -import type { LensDataTableEmbeddable } from '../../../../common/components/visualization_actions/types'; describe('helpers', () => { describe('showInitialLoadingSpinner', () => { @@ -69,13 +67,13 @@ describe('createResetGroupByFieldAction', () => { }, }, }, - } as unknown as Embeddable), + }), updateInput: jest.fn(), }; const context = { embeddable, - } as unknown as ActionExecutionContext>; + } as unknown as ActionExecutionContext; const mockCallback = jest.fn(); beforeAll(async () => { action = createResetGroupByFieldAction({ callback: mockCallback }); diff --git a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts_kpis/alerts_histogram_panel/helpers.tsx b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts_kpis/alerts_histogram_panel/helpers.tsx index 8757316038b4a..0b928864053ad 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts_kpis/alerts_histogram_panel/helpers.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts_kpis/alerts_histogram_panel/helpers.tsx @@ -6,10 +6,14 @@ */ import type { Action, ActionExecutionContext } from '@kbn/ui-actions-plugin/public'; -import type { Embeddable } from '@kbn/embeddable-plugin/public'; import { RESET_GROUP_BY_FIELDS } from '../../../../common/components/chart_settings_popover/configurations/default/translations'; import type { LensDataTableEmbeddable } from '../../../../common/components/visualization_actions/types'; +interface LegacyLensEmbeddable { + getInput: () => LensDataTableEmbeddable; + updateInput: (input: LensDataTableEmbeddable) => void; +} + /** * Returns `true` when the alerts histogram initial loading spinner should be shown * @@ -48,7 +52,7 @@ export const createResetGroupByFieldAction: CreateResetGroupByFieldAction = ({ async execute({ embeddable, }: ActionExecutionContext<{ - embeddable: Embeddable; + embeddable: LegacyLensEmbeddable; }>): Promise { callback?.();