Skip to content

Commit

Permalink
[dashboard] remove DashboardExternallyAccessibleApi and DashboardPlug…
Browse files Browse the repository at this point in the history
…inInternalFunctions types (elastic#193440)

Consolidate to only exposing `DashboardApi` by removing
`DashboardExternallyAccessibleApi` and
`DashboardPluginInternalFunctions` types.

---------

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 885dfe3)
  • Loading branch information
nreese committed Sep 19, 2024
1 parent 438284e commit f8af7ec
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ export function getPageApi() {
executionContext: {
type: 'presentationContainerEmbeddableExample',
},
getAllDataViews: () => {
// TODO remove once dashboard converted to API and use `PublishesDataViews` interface
return [];
},
getPanelCount: () => {
return panels$.value.length;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { DataView } from '@kbn/data-views-plugin/public';
import { TimeRange } from '@kbn/es-query';
import {
CanAddNewPanel,
Expand Down Expand Up @@ -36,9 +35,7 @@ export type PageApi = PresentationContainer &
PublishesViewMode &
PublishesReload &
PublishesTimeRange &
PublishesUnsavedChanges & {
getAllDataViews: () => DataView[];
};
PublishesUnsavedChanges;

export interface LastSavedState {
timeRange: TimeRange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { toMountPoint } from '@kbn/react-kibana-mount';
import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';

import { DASHBOARD_CONTAINER_TYPE } from '../dashboard_container';
import { DashboardPluginInternalFunctions } from '../dashboard_container/external_api/dashboard_api';
import { DashboardApi } from '../dashboard_api/types';
import { pluginServices } from '../services/plugin_services';
import { CopyToDashboardModal } from './copy_to_dashboard_modal';
import { dashboardCopyToDashboardActionStrings } from './_dashboard_actions_strings';
Expand All @@ -41,14 +41,16 @@ export type CopyToDashboardAPI = HasType &
HasUniqueId &
HasParentApi<
{ type: typeof DASHBOARD_CONTAINER_TYPE } & PublishesSavedObjectId &
DashboardPluginInternalFunctions
Pick<DashboardApi, 'getDashboardPanelFromId'>
>;

const apiIsCompatible = (api: unknown): api is CopyToDashboardAPI => {
return (
apiHasUniqueId(api) &&
apiHasParentApi(api) &&
apiIsOfType(api.parentApi, DASHBOARD_CONTAINER_TYPE) &&
(api?.parentApi as unknown as Pick<DashboardApi, 'getDashboardPanelFromId'>)
?.getDashboardPanelFromId !== undefined &&
apiPublishesSavedObjectId(api.parentApi)
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ describe('filters notification action', () => {
embeddable: {
uuid: 'testId',
viewMode: viewModeSubject,
parentApi: {
getAllDataViews: jest.fn(),
getDashboardPanelFromId: jest.fn(),
},
filters$: filtersSubject,
query$: querySubject,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {
HasParentApi,
PublishesUnifiedSearch,
HasUniqueId,
PublishesDataViews,
} from '@kbn/presentation-publishing';
import { merge } from 'rxjs';
import { DashboardPluginInternalFunctions } from '../dashboard_container/external_api/dashboard_api';
import { pluginServices } from '../services/plugin_services';
import { FiltersNotificationPopover } from './filters_notification_popover';
import { dashboardFilterNotificationActionStrings } from './_dashboard_actions_strings';
Expand All @@ -36,7 +36,7 @@ export const BADGE_FILTERS_NOTIFICATION = 'ACTION_FILTERS_NOTIFICATION';
export type FiltersNotificationActionApi = HasUniqueId &
CanAccessViewMode &
Partial<PublishesUnifiedSearch> &
HasParentApi<DashboardPluginInternalFunctions>;
Partial<HasParentApi<Partial<PublishesDataViews>>>;

const isApiCompatible = (api: unknown | null): api is FiltersNotificationActionApi =>
Boolean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ describe('filters notification popover', () => {
api = {
uuid: 'testId',
viewMode: new BehaviorSubject<ViewMode>('edit'),
parentApi: {
getAllDataViews: jest.fn(),
getDashboardPanelFromId: jest.fn(),
},
filters$: filtersSubject,
query$: querySubject,
};
Expand All @@ -79,11 +75,6 @@ describe('filters notification popover', () => {
await waitForEuiPopoverOpen();
};

it('calls get all dataviews from the parent', async () => {
render(<FiltersNotificationPopover api={api} />);
expect(api.parentApi?.getAllDataViews).toHaveBeenCalled();
});

it('renders the filter section when given filters', async () => {
updateFilters([getMockPhraseFilter('ay', 'oh')]);
await renderAndOpenPopover();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import { css } from '@emotion/react';
import { AggregateQuery, getAggregateQueryMode, isOfQueryType } from '@kbn/es-query';
import { getEditPanelAction } from '@kbn/presentation-panel-plugin/public';
import { FilterItems } from '@kbn/unified-search-plugin/public';
import { FiltersNotificationActionApi } from './filters_notification_action';
import { useStateFromPublishingSubject } from '@kbn/presentation-publishing';
import { BehaviorSubject } from 'rxjs';
import { dashboardFilterNotificationActionStrings } from './_dashboard_actions_strings';
import { FiltersNotificationActionApi } from './filters_notification_action';

export function FiltersNotificationPopover({ api }: { api: FiltersNotificationActionApi }) {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
Expand Down Expand Up @@ -57,7 +59,9 @@ export function FiltersNotificationPopover({ api }: { api: FiltersNotificationAc
}
}, [api, setDisableEditButton]);

const dataViews = useMemo(() => api.parentApi?.getAllDataViews(), [api]);
const dataViews = useStateFromPublishingSubject(
api.parentApi?.dataViews ? api.parentApi.dataViews : new BehaviorSubject(undefined)
);

return (
<EuiPopover
Expand Down Expand Up @@ -103,7 +107,7 @@ export function FiltersNotificationPopover({ api }: { api: FiltersNotificationAc
data-test-subj={'filtersNotificationModal__filterItems'}
>
<EuiFlexGroup wrap={true} gutterSize="xs">
<FilterItems filters={filters} indexPatterns={dataViews} readOnly={true} />
<FilterItems filters={filters} indexPatterns={dataViews ?? []} readOnly={true} />
</EuiFlexGroup>
</EuiFormRow>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/dashboard/public/dashboard_api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@kbn/presentation-publishing';
import { ControlGroupApi } from '@kbn/controls-plugin/public';
import { Filter, Query, TimeRange } from '@kbn/es-query';
import { DashboardPanelMap } from '../../common';
import { DashboardPanelMap, DashboardPanelState } from '../../common';
import { SaveDashboardReturn } from '../services/dashboard_content_management/types';

export type DashboardApi = CanExpandPanels &
Expand All @@ -44,6 +44,7 @@ export type DashboardApi = CanExpandPanels &
fullScreenMode$: PublishingSubject<boolean | undefined>;
focusedPanelId$: PublishingSubject<string | undefined>;
forceRefresh: () => void;
getDashboardPanelFromId: (id: string) => Promise<DashboardPanelState>;
getPanelsState: () => DashboardPanelMap;
hasOverlays$: PublishingSubject<boolean | undefined>;
hasRunMigrations$: PublishingSubject<boolean | undefined>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import { pluginServices } from '../../services/plugin_services';
import { placePanel } from '../panel_placement';
import { runPanelPlacementStrategy } from '../panel_placement/place_new_panel_strategies';
import { DashboardViewport } from '../component/viewport/dashboard_viewport';
import { DashboardExternallyAccessibleApi } from '../external_api/dashboard_api';
import { getDashboardPanelPlacementSetting } from '../panel_placement/panel_placement_registry';
import { dashboardContainerReducers } from '../state/dashboard_container_reducers';
import { getDiffingMiddleware } from '../state/diffing/dashboard_diffing_integration';
Expand Down Expand Up @@ -137,7 +136,6 @@ export const useDashboardContainer = (): DashboardContainer => {
export class DashboardContainer
extends Container<InheritedChildInput, DashboardContainerInput>
implements
DashboardExternallyAccessibleApi,
TrackContentfulRender,
TracksQueryPerformance,
HasSaveNotification,
Expand Down Expand Up @@ -174,7 +172,6 @@ export class DashboardContainer

private domNode?: HTMLElement;
private overlayRef?: OverlayRef;
private allDataViews: DataView[] = [];

// performance monitoring
public lastLoadStartTime?: number;
Expand Down Expand Up @@ -393,7 +390,7 @@ export class DashboardContainer
})
);

this.dataViews = new BehaviorSubject<DataView[] | undefined>(this.getAllDataViews());
this.dataViews = new BehaviorSubject<DataView[] | undefined>([]);

const query$ = new BehaviorSubject<Query | AggregateQuery | undefined>(this.getInput().query);
this.query$ = query$;
Expand Down Expand Up @@ -799,20 +796,11 @@ export class DashboardContainer
dashboardContainerReady$.next(this);
};

/**
* Gets all the dataviews that are actively being used in the dashboard
* @returns An array of dataviews
*/
public getAllDataViews = () => {
return this.allDataViews;
};

/**
* Use this to set the dataviews that are used in the dashboard when they change/update
* @param newDataViews The new array of dataviews that will overwrite the old dataviews array
*/
public setAllDataViews = (newDataViews: DataView[]) => {
this.allDataViews = newDataViews;
(this.dataViews as BehaviorSubject<DataView[] | undefined>).next(newDataViews);
};

Expand Down

This file was deleted.

0 comments on commit f8af7ec

Please sign in to comment.