Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [embeddable] make presentation interface names consistent (#205279) #207881

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading