Skip to content

Commit

Permalink
[8.x] [Lens][Embeddable] Expose the `parentApi` via the emb…
Browse files Browse the repository at this point in the history
…eddable 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)](#202006)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marco
Liberati","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-02T11:53:34Z","message":"[Lens][Embeddable]
Expose the `parentApi` via the embeddable API (#202006)\n\n##
Summary\r\n\r\nFixes #199736\r\n\r\nThis PR exposes the `parentApi` when
it satisfy the\r\n`PresentationContainer` type: this allows api
consumers (i.e. dashboard\r\nactions) to access the full container
context for complex evaluation of\r\nan action (i.e. are there other
panels? what types are they made of?\r\netc...).\r\n\r\nI've limited it
to `PresentationContainer` as this was the original\r\nintent of the
feature request (and avoids type casting). If it needs to\r\nbe extended
more another follow up can be
done.","sha":"a18be1fb1719b6a1eb77b2da4d4d6b685ea02b37","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Visualizations","release_note:skip","Feature:Lens","v9.0.0","backport:prev-minor"],"title":"[Lens][Embeddable]
Expose the `parentApi` via the embeddable
API","number":202006,"url":"https://github.com/elastic/kibana/pull/202006","mergeCommit":{"message":"[Lens][Embeddable]
Expose the `parentApi` via the embeddable API (#202006)\n\n##
Summary\r\n\r\nFixes #199736\r\n\r\nThis PR exposes the `parentApi` when
it satisfy the\r\n`PresentationContainer` type: this allows api
consumers (i.e. dashboard\r\nactions) to access the full container
context for complex evaluation of\r\nan action (i.e. are there other
panels? what types are they made of?\r\netc...).\r\n\r\nI've limited it
to `PresentationContainer` as this was the original\r\nintent of the
feature request (and avoids type casting). If it needs to\r\nbe extended
more another follow up can be
done.","sha":"a18be1fb1719b6a1eb77b2da4d4d6b685ea02b37"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202006","number":202006,"mergeCommit":{"message":"[Lens][Embeddable]
Expose the `parentApi` via the embeddable API (#202006)\n\n##
Summary\r\n\r\nFixes #199736\r\n\r\nThis PR exposes the `parentApi` when
it satisfy the\r\n`PresentationContainer` type: this allows api
consumers (i.e. dashboard\r\nactions) to access the full container
context for complex evaluation of\r\nan action (i.e. are there other
panels? what types are they made of?\r\netc...).\r\n\r\nI've limited it
to `PresentationContainer` as this was the original\r\nintent of the
feature request (and avoids type casting). If it needs to\r\nbe extended
more another follow up can be
done.","sha":"a18be1fb1719b6a1eb77b2da4d4d6b685ea02b37"}}]}] BACKPORT-->

Co-authored-by: Marco Liberati <[email protected]>
  • Loading branch information
kibanamachine and dej611 authored Dec 2, 2024
1 parent 50c0d92 commit 9728176
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 9728176

Please sign in to comment.