From 972817620e82fa9f75e81786cb3a3f0d6c186d2d Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 3 Dec 2024 00:44:13 +1100 Subject: [PATCH] [8.x] [Lens][Embeddable] Expose the `parentApi` via the embeddable API (#202006) (#202445) # Backport This will backport the following commits from `main` to `8.x`: - [[Lens][Embeddable] Expose the `parentApi` via the embeddable API (#202006)](https://github.com/elastic/kibana/pull/202006) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Marco Liberati --- .../initializers/initialize_dashboard_services.ts | 10 ++++++++-- x-pack/plugins/lens/public/react_embeddable/types.ts | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/lens/public/react_embeddable/initializers/initialize_dashboard_services.ts b/x-pack/plugins/lens/public/react_embeddable/initializers/initialize_dashboard_services.ts index bf203f5faf32a..67a5d3a89a1c2 100644 --- a/x-pack/plugins/lens/public/react_embeddable/initializers/initialize_dashboard_services.ts +++ b/x-pack/plugins/lens/public/react_embeddable/initializers/initialize_dashboard_services.ts @@ -16,7 +16,7 @@ import { getUnchangingComparator, initializeTitles, } from '@kbn/presentation-publishing'; -import { apiPublishesSettings } from '@kbn/presentation-containers'; +import { apiIsPresentationContainer, apiPublishesSettings } from '@kbn/presentation-containers'; import { buildObservableVariable, isTextBasedLanguage } from '../helper'; import type { LensComponentProps, @@ -27,6 +27,7 @@ import type { LensSharedProps, IntegrationCallbacks, LensInternalApi, + LensApi, } from '../types'; import { apiHasLensComponentProps } from '../type_guards'; import { StateManagementConfig } from './initialize_state_management'; @@ -39,9 +40,12 @@ export interface DashboardServicesConfig { PublishesWritablePanelDescription & HasInPlaceLibraryTransforms & HasLibraryTransforms & + Pick & Pick; serialize: () => SerializedProps; - comparators: StateComparators; + comparators: StateComparators< + SerializedProps & Pick & { isNewPanel?: boolean } + >; cleanup: () => void; } @@ -78,6 +82,7 @@ export function initializeDashboardServices( return { api: { + parentApi: apiIsPresentationContainer(parentApi) ? parentApi : undefined, defaultPanelTitle: defaultPanelTitle$, defaultPanelDescription: defaultPanelDescription$, ...titlesApi, @@ -178,6 +183,7 @@ export function initializeDashboardServices( overrides: overridesComparator, disableTriggers: disabledTriggersComparator, isNewPanel: getUnchangingComparator<{ isNewPanel?: boolean }, 'isNewPanel'>(), + parentApi: getUnchangingComparator, 'parentApi'>(), }, cleanup: noop, }; diff --git a/x-pack/plugins/lens/public/react_embeddable/types.ts b/x-pack/plugins/lens/public/react_embeddable/types.ts index 058affe7f8d2f..c860c543570c1 100644 --- a/x-pack/plugins/lens/public/react_embeddable/types.ts +++ b/x-pack/plugins/lens/public/react_embeddable/types.ts @@ -17,6 +17,7 @@ import type { HasEditCapabilities, HasInPlaceLibraryTransforms, HasLibraryTransforms, + HasParentApi, HasSupportedTriggers, PublishesBlockingError, PublishesDataLoading, @@ -63,6 +64,7 @@ import type { AllowedGaugeOverrides } from '@kbn/expression-gauge-plugin/common' import type { AllowedPartitionOverrides } from '@kbn/expression-partition-vis-plugin/common'; import type { AllowedXYOverrides } from '@kbn/expression-xy-plugin/common'; import type { Action } from '@kbn/ui-actions-plugin/public'; +import { PresentationContainer } from '@kbn/presentation-containers'; import type { LegacyMetricState } from '../../common'; import type { LensDocument } from '../persistence'; import type { LensInspector } from '../lens_inspector_service'; @@ -379,6 +381,8 @@ export type LensApi = Simplify< HasLibraryTransforms & // Let the container know the view mode PublishesViewMode & + // forward the parentApi, note that will be exposed only if it satisfy the PresentationContainer interface + Partial> & // Let the container know the saved object id PublishesSavedObjectId & // Lens specific API methods: