Skip to content

Commit

Permalink
[8.x] [embeddable] make presentation interface names consistent (#205279
Browse files Browse the repository at this point in the history
) (#207881)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT [{"author":{"name":"Nathan
Reese","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-22T16:46:01Z","message":"[embeddable]
make presentation interface names consistent (#205279)\n\nPR cleans up
presentation interface names for consistentency\r\n* adds `# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT suffix to all observables. For example, `dataLoading`
=>\r\n`dataLoading# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT \r\n* removes `Panel` naming convention from interface
names since an api\r\nmay not be a panel, an api may be a dashboard. For
example,\r\n`PublisesPanelTitle` => `PublishesTitle`\r\n\r\n#### Note to
Reviewers\r\nPay special attention to any place where your application
creates an\r\nuntyped API. In the example below, there is no typescript
violation when\r\nthe parent returns `dataLoading` instead of
`dataLoading# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT since the\r\nparent is not typed as `PublishesDataLoading`.
Please check for\r\ninstances like
these.\r\n\r\n```\r\n<ReactEmbeddableRenderer\r\n getParentApi={() =>
{\r\n dataLoading: new BehaviorSubject()\r\n
}}\r\n/>\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"05916056cdc84c0f59392046aa4ffc7d16e083f9","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Embedding","Team:Presentation","release_note:skip","Feature:Drilldowns","v9.0.0","Team:obs-ux-infra_services","Team:obs-ux-management","project:embeddableRebuild","backport:version","v8.18.0"],"title":"[embeddable]
make presentation interface names
consistent","number":205279,"url":"https://github.com/elastic/kibana/pull/205279","mergeCommit":{"message":"[embeddable]
make presentation interface names consistent (#205279)\n\nPR cleans up
presentation interface names for consistentency\r\n* adds `# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT suffix to all observables. For example, `dataLoading`
=>\r\n`dataLoading# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT \r\n* removes `Panel` naming convention from interface
names since an api\r\nmay not be a panel, an api may be a dashboard. For
example,\r\n`PublisesPanelTitle` => `PublishesTitle`\r\n\r\n#### Note to
Reviewers\r\nPay special attention to any place where your application
creates an\r\nuntyped API. In the example below, there is no typescript
violation when\r\nthe parent returns `dataLoading` instead of
`dataLoading# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT since the\r\nparent is not typed as `PublishesDataLoading`.
Please check for\r\ninstances like
these.\r\n\r\n```\r\n<ReactEmbeddableRenderer\r\n getParentApi={() =>
{\r\n dataLoading: new BehaviorSubject()\r\n
}}\r\n/>\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"05916056cdc84c0f59392046aa4ffc7d16e083f9"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205279","number":205279,"mergeCommit":{"message":"[embeddable]
make presentation interface names consistent (#205279)\n\nPR cleans up
presentation interface names for consistentency\r\n* adds `# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT suffix to all observables. For example, `dataLoading`
=>\r\n`dataLoading# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT \r\n* removes `Panel` naming convention from interface
names since an api\r\nmay not be a panel, an api may be a dashboard. For
example,\r\n`PublisesPanelTitle` => `PublishesTitle`\r\n\r\n#### Note to
Reviewers\r\nPay special attention to any place where your application
creates an\r\nuntyped API. In the example below, there is no typescript
violation when\r\nthe parent returns `dataLoading` instead of
`dataLoading# Backport

This will backport the following commits from `main` to `8.x`:
- [[embeddable] make presentation interface names consistent
(#205279)](#205279)

<!--- Backport version: 9.6.4 -->

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

<!--BACKPORT since the\r\nparent is not typed as `PublishesDataLoading`.
Please check for\r\ninstances like
these.\r\n\r\n```\r\n<ReactEmbeddableRenderer\r\n getParentApi={() =>
{\r\n dataLoading: new BehaviorSubject()\r\n
}}\r\n/>\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"05916056cdc84c0f59392046aa4ffc7d16e083f9"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
nreese authored Jan 22, 2025
1 parent f47f4da commit c39e129
Show file tree
Hide file tree
Showing 229 changed files with 1,265 additions and 1,299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const EditExample = () => {
INPUT_KEY,
JSON.stringify({
...controlGroupAPI.snapshotRuntimeState(),
disabledActions: controlGroupAPI.disabledActionIds.getValue(), // not part of runtime
disabledActions: controlGroupAPI.disabledActionIds$.getValue(), // not part of runtime
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ export const ReactControlExample = ({
const children$ = new BehaviorSubject<{ [key: string]: unknown }>({});

return {
dataLoading: dataLoading$,
dataLoading$,
unifiedSearchFilters$,
viewMode: viewMode$,
viewMode$,
filters$,
query$,
timeRange$,
Expand Down Expand Up @@ -149,7 +149,7 @@ export const ReactControlExample = ({
useEffect(() => {
const subscription = combineCompatibleChildrenApis<PublishesDataLoading, boolean | undefined>(
dashboardApi,
'dataLoading',
'dataLoading$',
apiPublishesDataLoading,
undefined,
// flatten method
Expand Down Expand Up @@ -249,7 +249,7 @@ export const ReactControlExample = ({
if (!controlGroupApi) {
return;
}
const subscription = controlGroupApi.unsavedChanges.subscribe((nextUnsavedChanges) => {
const subscription = controlGroupApi.unsavedChanges$.subscribe((nextUnsavedChanges) => {
if (!nextUnsavedChanges) {
clearControlGroupRuntimeState();
setUnsavedChanges(undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const PresentationContainerExample = ({ uiActions }: { uiActions: UiActio
}, [cleanUp]);

const [dataLoading, panels, timeRange] = useBatchedPublishingSubjects(
pageApi.dataLoading,
pageApi.dataLoading$,
componentApi.panels$,
pageApi.timeRange$
);
Expand Down Expand Up @@ -95,7 +95,7 @@ export const PresentationContainerExample = ({ uiActions }: { uiActions: UiActio
<TopNav
onSave={componentApi.onSave}
resetUnsavedChanges={pageApi.resetUnsavedChanges}
unsavedChanges$={pageApi.unsavedChanges}
unsavedChanges$={pageApi.unsavedChanges$}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { PublishesUnsavedChanges } from '@kbn/presentation-publishing';
interface Props {
onSave: () => Promise<void>;
resetUnsavedChanges: () => void;
unsavedChanges$: PublishesUnsavedChanges['unsavedChanges'];
unsavedChanges$: PublishesUnsavedChanges['unsavedChanges$'];
}

export function TopNav(props: Props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function getPageApi() {
boolean | undefined
>(
{ children$ },
'dataLoading',
'dataLoading$',
apiPublishesDataLoading,
undefined,
// flatten method
Expand Down Expand Up @@ -193,7 +193,7 @@ export function getPageApi() {
},
canRemovePanels: () => true,
children$,
dataLoading: dataLoading$,
dataLoading$,
executionContext: {
type: 'presentationContainerEmbeddableExample',
},
Expand All @@ -210,7 +210,7 @@ export function getPageApi() {
children$.next(omit(children$.value, id));
},
saveNotification$,
viewMode: new BehaviorSubject<ViewMode>('edit'),
viewMode$: new BehaviorSubject<ViewMode>('edit'),
/**
* return last saved embeddable state
*/
Expand Down Expand Up @@ -252,7 +252,7 @@ export function getPageApi() {
return true;
},
timeRange$,
unsavedChanges: unsavedChanges$ as PublishingSubject<object | undefined>,
unsavedChanges$: unsavedChanges$ as PublishingSubject<object | undefined>,
} as PageApi,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const RenderExamples = () => {
const [api, setApi] = useState<SearchApi | null>(null);
const [hidePanelChrome, setHidePanelChrome] = useState<boolean>(false);
const [dataLoading, timeRange] = useBatchedOptionalPublishingSubjects(
api?.dataLoading,
api?.dataLoading$,
parentApi.timeRange$
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export const StateManagementExample = ({ uiActions }: { uiActions: UiActionsStar
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);

useEffect(() => {
if (!bookApi || !bookApi.unsavedChanges) {
if (!bookApi || !bookApi.unsavedChanges$) {
return;
}
const subscription = bookApi.unsavedChanges.subscribe((unsavedChanges) => {
const subscription = bookApi.unsavedChanges$.subscribe((unsavedChanges) => {
setHasUnsavedChanges(unsavedChanges !== undefined);
unsavedChangesSessionStorage.save(unsavedChanges ?? {});
});
Expand Down Expand Up @@ -158,7 +158,7 @@ export const StateManagementExample = ({ uiActions }: { uiActions: UiActionsStar
return unsavedChangesSessionStorage.load();
},
saveNotification$,
viewMode: new BehaviorSubject<ViewMode>('edit'),
viewMode$: new BehaviorSubject<ViewMode>('edit'),
};
}}
onApiAvailable={(api) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const initializeDataTableQueries = async (
dataView$.next(defaultDataView);
return;
}
const dataViewSubscription = dataViewProvider.dataViews.subscribe((dataViews) => {
const dataViewSubscription = dataViewProvider.dataViews$.subscribe((dataViews) => {
dataView$.next(dataViews?.[0] ?? defaultDataView);
});
return () => dataViewSubscription.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import {
initializeTimeRange,
initializeTitles,
initializeTitleManager,
useBatchedPublishingSubjects,
} from '@kbn/presentation-publishing';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
Expand All @@ -40,8 +40,8 @@ export const getDataTableFactory = (
buildEmbeddable: async (state, buildApi, uuid, parentApi) => {
const storage = new Storage(localStorage);
const timeRange = initializeTimeRange(state);
const queryLoading$ = new BehaviorSubject<boolean | undefined>(true);
const { titlesApi, titleComparators, serializeTitles } = initializeTitles(state);
const dataLoading$ = new BehaviorSubject<boolean | undefined>(true);
const titleManager = initializeTitleManager(state);
const allServices: UnifiedDataTableProps['services'] = {
...services,
storage,
Expand All @@ -53,18 +53,18 @@ export const getDataTableFactory = (
const api = buildApi(
{
...timeRange.api,
...titlesApi,
dataLoading: queryLoading$,
...titleManager.api,
dataLoading$,
serializeState: () => {
return {
rawState: { ...serializeTitles(), ...timeRange.serialize() },
rawState: { ...titleManager.serialize(), ...timeRange.serialize() },
};
},
},
{ ...titleComparators, ...timeRange.comparators }
{ ...titleManager.comparators, ...timeRange.comparators }
);

const queryService = await initializeDataTableQueries(services, api, queryLoading$);
const queryService = await initializeDataTableQueries(services, api, dataLoading$);

// Create the React Embeddable component
return {
Expand All @@ -74,7 +74,7 @@ export const getDataTableFactory = (
const [fields, rows, loading, dataView] = useBatchedPublishingSubjects(
queryService.fields$,
queryService.rows$,
queryLoading$,
dataLoading$,
queryService.dataView$
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { css } from '@emotion/react';
import { ReactEmbeddableFactory } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import {
initializeTitles,
initializeTitleManager,
useInheritedViewMode,
useStateFromPublishingSubject,
} from '@kbn/presentation-publishing';
Expand Down Expand Up @@ -41,7 +41,7 @@ export const markdownEmbeddableFactory: ReactEmbeddableFactory<
/**
* initialize state (source of truth)
*/
const { titlesApi, titleComparators, serializeTitles } = initializeTitles(state);
const titleManager = initializeTitleManager(state);
const content$ = new BehaviorSubject(state.content);

/**
Expand All @@ -51,11 +51,11 @@ export const markdownEmbeddableFactory: ReactEmbeddableFactory<
*/
const api = buildApi(
{
...titlesApi,
...titleManager.api,
serializeState: () => {
return {
rawState: {
...serializeTitles(),
...titleManager.serialize(),
content: content$.getValue(),
},
};
Expand All @@ -70,7 +70,7 @@ export const markdownEmbeddableFactory: ReactEmbeddableFactory<
*/
{
content: [content$, (value) => content$.next(value)],
...titleComparators,
...titleManager.comparators,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { DataView } from '@kbn/data-views-plugin/common';
import { DATA_VIEW_SAVED_OBJECT_TYPE } from '@kbn/data-views-plugin/public';
import { ReactEmbeddableFactory } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import { initializeTitles, useBatchedPublishingSubjects } from '@kbn/presentation-publishing';
import { initializeTitleManager, useBatchedPublishingSubjects } from '@kbn/presentation-publishing';
import { LazyDataViewPicker, withSuspense } from '@kbn/presentation-util-plugin/public';
import { euiThemeVars } from '@kbn/ui-theme';
import {
Expand Down Expand Up @@ -70,7 +70,7 @@ export const getFieldListFactory = (
},
buildEmbeddable: async (initialState, buildApi) => {
const subscriptions = new Subscription();
const { titlesApi, titleComparators, serializeTitles } = initializeTitles(initialState);
const titleManager = initializeTitleManager(initialState);

// set up data views
const [allDataViews, defaultDataViewId] = await Promise.all([
Expand Down Expand Up @@ -106,8 +106,8 @@ export const getFieldListFactory = (

const api = buildApi(
{
...titlesApi,
dataViews: dataViews$,
...titleManager.api,
dataViews$,
selectedFields: selectedFieldNames$,
serializeState: () => {
const dataViewId = selectedDataViewId$.getValue();
Expand All @@ -122,7 +122,7 @@ export const getFieldListFactory = (
: [];
return {
rawState: {
...serializeTitles(),
...titleManager.serialize(),
// here we skip serializing the dataViewId, because the reference contains that information.
selectedFieldNames: selectedFieldNames$.getValue(),
},
Expand All @@ -131,7 +131,7 @@ export const getFieldListFactory = (
},
},
{
...titleComparators,
...titleManager.comparators,
dataViewId: [selectedDataViewId$, (value) => selectedDataViewId$.next(value)],
selectedFieldNames: [
selectedFieldNames$,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { i18n } from '@kbn/i18n';
import {
apiHasParentApi,
getUnchangingComparator,
initializeTitles,
initializeTitleManager,
SerializedTitles,
SerializedPanelState,
useBatchedPublishingSubjects,
Expand Down Expand Up @@ -74,7 +74,7 @@ export const getSavedBookEmbeddableFactory = (core: CoreStart) => {
};
},
buildEmbeddable: async (state, buildApi) => {
const { titlesApi, titleComparators, serializeTitles } = initializeTitles(state);
const titleManager = initializeTitleManager(state);
const bookAttributesManager = stateManagerFromAttributes(state);
const isByReference = Boolean(state.savedBookId);

Expand All @@ -83,21 +83,21 @@ export const getSavedBookEmbeddableFactory = (core: CoreStart) => {
// if this book is currently by reference, we serialize the reference only.
const bookByReferenceState: BookByReferenceSerializedState = {
savedBookId: newId ?? state.savedBookId!,
...serializeTitles(),
...titleManager.serialize(),
};
return { rawState: bookByReferenceState };
}
// if this book is currently by value, we serialize the entire state.
const bookByValueState: BookByValueSerializedState = {
attributes: serializeBookAttributes(bookAttributesManager),
...serializeTitles(),
...titleManager.serialize(),
};
return { rawState: bookByValueState };
};

const api = buildApi(
{
...titlesApi,
...titleManager.api,
onEdit: async () => {
openSavedBookEditor({
attributesManager: bookAttributesManager,
Expand Down Expand Up @@ -145,7 +145,7 @@ export const getSavedBookEmbeddableFactory = (core: CoreStart) => {
{
savedBookId: getUnchangingComparator(), // saved book id will not change over the lifetime of the embeddable.
...bookAttributesManager.comparators,
...titleComparators,
...titleManager.comparators,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export const getSearchEmbeddableFactory = (services: Services) => {
const api = buildApi(
{
...timeRange.api,
blockingError: blockingError$,
dataViews: dataViews$,
dataLoading: dataLoading$,
blockingError$,
dataViews$,
dataLoading$,
serializeState: () => {
return {
rawState: {
Expand Down
6 changes: 3 additions & 3 deletions examples/grid_example/public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const GridExample = ({

const mockDashboardApi = useMockDashboardApi({ savedState: savedState.current });
const [viewMode, expandedPanelId] = useBatchedPublishingSubjects(
mockDashboardApi.viewMode,
mockDashboardApi.expandedPanelId
mockDashboardApi.viewMode$,
mockDashboardApi.expandedPanelId$
);

useEffect(() => {
Expand Down Expand Up @@ -244,7 +244,7 @@ export const GridExample = ({
]}
idSelected={viewMode}
onChange={(id) => {
mockDashboardApi.viewMode.next(id);
mockDashboardApi.viewMode$.next(id);
}}
/>
</EuiFormRow>
Expand Down
4 changes: 2 additions & 2 deletions examples/grid_example/public/use_mock_dashboard_api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export const useMockDashboardApi = ({
}),
filters$: new BehaviorSubject([]),
query$: new BehaviorSubject(''),
viewMode: new BehaviorSubject('edit'),
viewMode$: new BehaviorSubject('edit'),
panels$,
rows$: new BehaviorSubject<MockedDashboardRowMap>(savedState.rows),
expandedPanelId: expandedPanelId$,
expandedPanelId$,
expandPanel: (id: string) => {
if (expandedPanelId$.getValue()) {
expandedPanelId$.next(undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const DualDashboardsExample = () => {
const [secondDashboardApi, setSecondDashboardApi] = useState<DashboardApi | undefined>();

const ButtonControls = ({ dashboardApi }: { dashboardApi: DashboardApi }) => {
const viewMode = useStateFromPublishingSubject(dashboardApi.viewMode);
const viewMode = useStateFromPublishingSubject(dashboardApi.viewMode$);

return (
<EuiButtonGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('GetCsvReportPanelAction', () => {
}),
hasTimeRange: () => true,
parentApi: {
viewMode: new BehaviorSubject('view'),
viewMode$: new BehaviorSubject('view'),
},
},
} as EmbeddableApiContext;
Expand Down
Loading

0 comments on commit c39e129

Please sign in to comment.