Skip to content

Commit 556518f

Browse files
[8.19] [embeddable] update DefaultPresentationPanelApi to define parentApi as unknown (#218668) (#218838)
# Backport This will backport the following commits from `main` to `8.19`: - [[embeddable] update DefaultPresentationPanelApi to define parentApi as unknown (#218668)](#218668) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Nathan Reese","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-22T14:54:50Z","message":"[embeddable] update DefaultPresentationPanelApi to define parentApi as unknown (#218668)\n\nDefaultPresentationPanelApi should define parentApi as unknown.\n\n`ReactEmbeddableRenderer` renders panels with `PresentationPanel`.\n`PresentationPanel` takes `api: DefaultPresentationPanelApi` as a prop\nand `DefaultPresentationPanelApi` should not define ParentApi type more\nprecisely then its defined in `ReactEmbeddableRenderer`.\n`ReactEmbeddableRenderer` defines parent as `ParentApi extends\nHasSerializedChildState<SerializedState> =\nHasSerializedChildState<SerializedState>`.\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"678b53a1a784f33b2b0cb28186df1123e30b5d77","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Presentation","release_note:skip","backport:version","v9.1.0","v8.19.0"],"title":"[embeddable] update DefaultPresentationPanelApi to define parentApi as unknown","number":218668,"url":"https://github.com/elastic/kibana/pull/218668","mergeCommit":{"message":"[embeddable] update DefaultPresentationPanelApi to define parentApi as unknown (#218668)\n\nDefaultPresentationPanelApi should define parentApi as unknown.\n\n`ReactEmbeddableRenderer` renders panels with `PresentationPanel`.\n`PresentationPanel` takes `api: DefaultPresentationPanelApi` as a prop\nand `DefaultPresentationPanelApi` should not define ParentApi type more\nprecisely then its defined in `ReactEmbeddableRenderer`.\n`ReactEmbeddableRenderer` defines parent as `ParentApi extends\nHasSerializedChildState<SerializedState> =\nHasSerializedChildState<SerializedState>`.\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"678b53a1a784f33b2b0cb28186df1123e30b5d77"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218668","number":218668,"mergeCommit":{"message":"[embeddable] update DefaultPresentationPanelApi to define parentApi as unknown (#218668)\n\nDefaultPresentationPanelApi should define parentApi as unknown.\n\n`ReactEmbeddableRenderer` renders panels with `PresentationPanel`.\n`PresentationPanel` takes `api: DefaultPresentationPanelApi` as a prop\nand `DefaultPresentationPanelApi` should not define ParentApi type more\nprecisely then its defined in `ReactEmbeddableRenderer`.\n`ReactEmbeddableRenderer` defines parent as `ParentApi extends\nHasSerializedChildState<SerializedState> =\nHasSerializedChildState<SerializedState>`.\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"678b53a1a784f33b2b0cb28186df1123e30b5d77"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Nathan Reese <[email protected]>
1 parent 0bbce26 commit 556518f

File tree

8 files changed

+16
-24
lines changed

8 files changed

+16
-24
lines changed

examples/embeddable_examples/public/react_embeddables/saved_book/saved_book_react_embeddable.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
useBatchedPublishingSubjects,
3030
} from '@kbn/presentation-publishing';
3131
import React from 'react';
32-
import { PresentationContainer } from '@kbn/presentation-containers';
32+
import { PresentationContainer, apiIsPresentationContainer } from '@kbn/presentation-containers';
3333
import { serializeBookAttributes, stateManagerFromAttributes } from './book_state';
3434
import { SAVED_BOOK_ID } from './constants';
3535
import { openSavedBookEditor } from './saved_book_editor';
@@ -116,8 +116,11 @@ export const getSavedBookEmbeddableFactory = (core: CoreStart) => {
116116
const nextIsByReference = Boolean(result.savedBookId);
117117

118118
// if the by reference state has changed during this edit, reinitialize the panel.
119-
if (nextIsByReference !== isByReference) {
120-
api.parentApi?.replacePanel<BookSerializedState>(api.uuid, {
119+
if (
120+
nextIsByReference !== isByReference &&
121+
apiIsPresentationContainer(api.parentApi)
122+
) {
123+
api.parentApi.replacePanel<BookSerializedState>(api.uuid, {
121124
serializedState: serializeBook(nextIsByReference, result.savedBookId),
122125
panelType: api.type,
123126
});

src/platform/packages/shared/presentation/presentation_publishing/interfaces/can_access_view_mode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ export const apiCanAccessViewMode = (api: unknown): api is CanAccessViewMode =>
2828
* A function which will get the view mode from the API or the parent API. if this api has a view mode AND its
2929
* parent has a view mode, we consider the APIs version the source of truth.
3030
*/
31-
export const getInheritedViewMode = (api?: CanAccessViewMode) => {
31+
export const getInheritedViewMode = (api?: unknown) => {
3232
if (apiPublishesViewMode(api)) return api.viewMode$.getValue();
3333
if (apiHasParentApi(api) && apiPublishesViewMode(api.parentApi)) {
3434
return api.parentApi.viewMode$.getValue();
3535
}
3636
};
3737

38-
export const getViewModeSubject = (api?: CanAccessViewMode) => {
38+
export const getViewModeSubject = (api?: unknown) => {
3939
if (apiPublishesViewMode(api)) return api.viewMode$;
4040
if (apiHasParentApi(api) && apiPublishesViewMode(api.parentApi)) {
4141
return api.parentApi.viewMode$;

src/platform/plugins/private/links/public/embeddable/links_embeddable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from '@kbn/presentation-publishing';
2222
import { css } from '@emotion/react';
2323

24+
import { apiIsPresentationContainer } from '@kbn/presentation-containers';
2425
import {
2526
CONTENT_ID,
2627
DASHBOARD_LINK_TYPE,
@@ -181,14 +182,14 @@ export const getLinksEmbeddableFactory = () => {
181182

182183
// if the by reference state has changed during this edit, reinitialize the panel.
183184
const nextIsByReference = Boolean(newState?.savedObjectId);
184-
if (nextIsByReference !== isByReference) {
185+
if (nextIsByReference !== isByReference && apiIsPresentationContainer(api.parentApi)) {
185186
const serializedState = serializeLinksState(
186187
nextIsByReference,
187188
newState?.savedObjectId
188189
);
189190
(serializedState.rawState as SerializedTitles).title = newState.title;
190191

191-
api.parentApi?.replacePanel<LinksSerializedState>(api.uuid, {
192+
api.parentApi.replacePanel<LinksSerializedState>(api.uuid, {
192193
serializedState,
193194
panelType: api.type,
194195
});

src/platform/plugins/private/presentation_panel/public/panel_component/panel_header/presentation_panel_hover_actions.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { css } from '@emotion/react';
3737
import {
3838
apiCanLockHoverActions,
3939
EmbeddableApiContext,
40+
PublishesTitle,
4041
useBatchedOptionalPublishingSubjects,
4142
ViewMode,
4243
} from '@kbn/presentation-publishing';
@@ -141,7 +142,7 @@ export const PresentationPanelHoverActions = ({
141142
api?.description$,
142143
api?.hideTitle$,
143144
api?.hasLockedHoverActions$,
144-
api?.parentApi?.hideTitle$
145+
(api?.parentApi as Partial<PublishesTitle>)?.hideTitle$
145146
);
146147

147148
const hideTitle = hidePanelTitle || parentHideTitle;

src/platform/plugins/private/presentation_panel/public/panel_component/presentation_panel_internal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { EuiErrorBoundary, EuiFlexGroup, EuiPanel, htmlIdGenerator } from '@elas
1111
import { css } from '@emotion/react';
1212
import { PanelLoader } from '@kbn/panel-loader';
1313
import {
14+
PublishesTitle,
1415
apiHasParentApi,
1516
apiPublishesViewMode,
1617
useBatchedOptionalPublishingSubjects,
@@ -72,7 +73,7 @@ export const PresentationPanelInternal = <
7273
api?.defaultTitle$,
7374
api?.defaultDescription$,
7475
viewModeSubject,
75-
api?.parentApi?.hideTitle$
76+
(api?.parentApi as Partial<PublishesTitle>)?.hideTitle$
7677
);
7778
const viewMode = rawViewMode ?? 'view';
7879

src/platform/plugins/private/presentation_panel/public/panel_component/types.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { PresentationContainer } from '@kbn/presentation-containers';
1110
import {
1211
CanLockHoverActions,
1312
HasParentApi,
@@ -17,7 +16,6 @@ import {
1716
PublishesDisabledActionIds,
1817
PublishesDescription,
1918
PublishesTitle,
20-
PublishesViewMode,
2119
} from '@kbn/presentation-publishing';
2220
import { UiActionsService } from '@kbn/ui-actions-plugin/public';
2321
import { MaybePromise } from '@kbn/utility-types';
@@ -79,9 +77,7 @@ export interface DefaultPresentationPanelApi
7977
PublishesBlockingError &
8078
PublishesDescription &
8179
PublishesDisabledActionIds &
82-
HasParentApi<
83-
PresentationContainer & Partial<Pick<PublishesTitle, 'hideTitle$'> & PublishesViewMode>
84-
> &
80+
HasParentApi &
8581
CanLockHoverActions
8682
> {}
8783

x-pack/platform/plugins/shared/lens/public/react_embeddable/data_loader.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ async function expectRerenderOnDataLoader(
117117
onBrushEnd: jest.fn(),
118118
onFilter: jest.fn(),
119119
onTableRowClick: jest.fn(),
120-
// Make TS happy
121-
removePanel: jest.fn(),
122-
replacePanel: jest.fn(),
123-
getPanelCount: jest.fn(),
124-
children$: new BehaviorSubject({}),
125-
addNewPanel: jest.fn(),
126120
...parentApiOverrides,
127121
};
128122
const api: LensApi = {

x-pack/platform/plugins/shared/lens/public/react_embeddable/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import type { ESQLControlVariable } from '@kbn/esql-types';
1717
import type {
1818
HasEditCapabilities,
1919
HasLibraryTransforms,
20-
HasParentApi,
2120
HasSupportedTriggers,
2221
PublishesBlockingError,
2322
PublishesDataLoading,
@@ -64,7 +63,6 @@ import type { AllowedGaugeOverrides } from '@kbn/expression-gauge-plugin/common'
6463
import type { AllowedPartitionOverrides } from '@kbn/expression-partition-vis-plugin/common';
6564
import type { AllowedXYOverrides } from '@kbn/expression-xy-plugin/common';
6665
import type { Action } from '@kbn/ui-actions-plugin/public';
67-
import { PresentationContainer } from '@kbn/presentation-containers';
6866
import { PublishesSearchSession } from '@kbn/presentation-publishing/interfaces/fetch/publishes_search_session';
6967
import type { LegacyMetricState } from '../../common';
7068
import type { LensDocument } from '../persistence';
@@ -401,8 +399,6 @@ export type LensApi = Simplify<
401399
HasLibraryTransforms<LensSerializedState, LensSerializedState> &
402400
// Let the container know the view mode
403401
PublishesViewMode &
404-
// forward the parentApi, note that will be exposed only if it satisfy the PresentationContainer interface
405-
Partial<HasParentApi<PresentationContainer>> &
406402
// Let the container know the saved object id
407403
PublishesSavedObjectId &
408404
// Lens specific API methods:

0 commit comments

Comments
 (0)