Skip to content

Commit

Permalink
[Lens][Embeddable] Expose the parentApi via the embeddable API (#20…
Browse files Browse the repository at this point in the history
…2006)

## Summary

Fixes #199736

This PR exposes the `parentApi` when it satisfy the
`PresentationContainer` type: this allows api consumers (i.e. dashboard
actions) to access the full container context for complex evaluation of
an action (i.e. are there other panels? what types are they made of?
etc...).

I've limited it to `PresentationContainer` as this was the original
intent of the feature request (and avoids type casting). If it needs to
be extended more another follow up can be done.
  • Loading branch information
dej611 authored Dec 2, 2024
1 parent f6fa94f commit a18be1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +27,7 @@ import type {
LensSharedProps,
IntegrationCallbacks,
LensInternalApi,
LensApi,
} from '../types';
import { apiHasLensComponentProps } from '../type_guards';
import { StateManagementConfig } from './initialize_state_management';
Expand All @@ -39,9 +40,12 @@ export interface DashboardServicesConfig {
PublishesWritablePanelDescription &
HasInPlaceLibraryTransforms &
HasLibraryTransforms<LensRuntimeState> &
Pick<LensApi, 'parentApi'> &
Pick<IntegrationCallbacks, 'updateOverrides' | 'getTriggerCompatibleActions'>;
serialize: () => SerializedProps;
comparators: StateComparators<SerializedProps & { isNewPanel?: boolean }>;
comparators: StateComparators<
SerializedProps & Pick<LensApi, 'parentApi'> & { isNewPanel?: boolean }
>;
cleanup: () => void;
}

Expand Down Expand Up @@ -78,6 +82,7 @@ export function initializeDashboardServices(

return {
api: {
parentApi: apiIsPresentationContainer(parentApi) ? parentApi : undefined,
defaultPanelTitle: defaultPanelTitle$,
defaultPanelDescription: defaultPanelDescription$,
...titlesApi,
Expand Down Expand Up @@ -178,6 +183,7 @@ export function initializeDashboardServices(
overrides: overridesComparator,
disableTriggers: disabledTriggersComparator,
isNewPanel: getUnchangingComparator<{ isNewPanel?: boolean }, 'isNewPanel'>(),
parentApi: getUnchangingComparator<Pick<LensApi, 'parentApi'>, 'parentApi'>(),
},
cleanup: noop,
};
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/lens/public/react_embeddable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
HasEditCapabilities,
HasInPlaceLibraryTransforms,
HasLibraryTransforms,
HasParentApi,
HasSupportedTriggers,
PublishesBlockingError,
PublishesDataLoading,
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -379,6 +381,8 @@ export type LensApi = Simplify<
HasLibraryTransforms<LensRuntimeState> &
// Let the container know the view mode
PublishesViewMode &
// forward the parentApi, note that will be exposed only if it satisfy the PresentationContainer interface
Partial<HasParentApi<PresentationContainer>> &
// Let the container know the saved object id
PublishesSavedObjectId &
// Lens specific API methods:
Expand Down

0 comments on commit a18be1f

Please sign in to comment.