mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[dashboard] remove DashboardExternallyAccessibleApi and DashboardPluginInternalFunctions types (#193440)
Consolidate to only exposing `DashboardApi` by removing `DashboardExternallyAccessibleApi` and `DashboardPluginInternalFunctions` types. --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
052187ce18
commit
885dfe3017
10 changed files with 17 additions and 82 deletions
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
@ -36,9 +35,7 @@ export type PageApi = PresentationContainer &
|
|||
PublishesViewMode &
|
||||
PublishesReload &
|
||||
PublishesTimeRange &
|
||||
PublishesUnsavedChanges & {
|
||||
getAllDataViews: () => DataView[];
|
||||
};
|
||||
PublishesUnsavedChanges;
|
||||
|
||||
export interface LastSavedState {
|
||||
timeRange: TimeRange;
|
||||
|
|
|
@ -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';
|
||||
|
@ -41,7 +41,7 @@ export type CopyToDashboardAPI = HasType &
|
|||
HasUniqueId &
|
||||
HasParentApi<
|
||||
{ type: typeof DASHBOARD_CONTAINER_TYPE } & PublishesSavedObjectId &
|
||||
DashboardPluginInternalFunctions
|
||||
Pick<DashboardApi, 'getDashboardPanelFromId'>
|
||||
>;
|
||||
|
||||
const apiIsCompatible = (api: unknown): api is CopyToDashboardAPI => {
|
||||
|
@ -49,6 +49,8 @@ const apiIsCompatible = (api: unknown): api is CopyToDashboardAPI => {
|
|||
apiHasUniqueId(api) &&
|
||||
apiHasParentApi(api) &&
|
||||
apiIsOfType(api.parentApi, DASHBOARD_CONTAINER_TYPE) &&
|
||||
(api?.parentApi as unknown as Pick<DashboardApi, 'getDashboardPanelFromId'>)
|
||||
?.getDashboardPanelFromId !== undefined &&
|
||||
apiPublishesSavedObjectId(api.parentApi)
|
||||
);
|
||||
};
|
||||
|
|
|
@ -58,10 +58,6 @@ describe('filters notification action', () => {
|
|||
embeddable: {
|
||||
uuid: 'testId',
|
||||
viewMode: viewModeSubject,
|
||||
parentApi: {
|
||||
getAllDataViews: jest.fn(),
|
||||
getDashboardPanelFromId: jest.fn(),
|
||||
},
|
||||
filters$: filtersSubject,
|
||||
query$: querySubject,
|
||||
},
|
||||
|
|
|
@ -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';
|
||||
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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>
|
||||
)}
|
||||
|
|
|
@ -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 &
|
||||
|
@ -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>;
|
||||
|
|
|
@ -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';
|
||||
|
@ -137,7 +136,6 @@ export const useDashboardContainer = (): DashboardContainer => {
|
|||
export class DashboardContainer
|
||||
extends Container<InheritedChildInput, DashboardContainerInput>
|
||||
implements
|
||||
DashboardExternallyAccessibleApi,
|
||||
TrackContentfulRender,
|
||||
TracksQueryPerformance,
|
||||
HasSaveNotification,
|
||||
|
@ -174,7 +172,6 @@ export class DashboardContainer
|
|||
|
||||
private domNode?: HTMLElement;
|
||||
private overlayRef?: OverlayRef;
|
||||
private allDataViews: DataView[] = [];
|
||||
|
||||
// performance monitoring
|
||||
public lastLoadStartTime?: number;
|
||||
|
@ -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$;
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the "Elastic License
|
||||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
|
||||
* Public License v 1"; you may not use this file except in compliance with, at
|
||||
* your election, the "Elastic License 2.0", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import type { DataView } from '@kbn/data-views-plugin/public';
|
||||
import { CanDuplicatePanels, CanExpandPanels, TracksOverlays } from '@kbn/presentation-containers';
|
||||
import { HasTypeDisplayName, PublishesSavedObjectId } from '@kbn/presentation-publishing';
|
||||
import { DashboardPanelState } from '../../../common';
|
||||
import { DashboardContainer } from '../embeddable/dashboard_container';
|
||||
|
||||
export const buildApiFromDashboardContainer = (container?: DashboardContainer) => container ?? null;
|
||||
|
||||
export type DashboardExternallyAccessibleApi = HasTypeDisplayName &
|
||||
CanDuplicatePanels &
|
||||
TracksOverlays &
|
||||
PublishesSavedObjectId &
|
||||
DashboardPluginInternalFunctions &
|
||||
CanExpandPanels;
|
||||
|
||||
/**
|
||||
* An interface that holds types for the methods that Dashboard publishes which should not be used
|
||||
* outside of the Dashboard plugin. This is necessary for some actions which reside in the Dashboard plugin.
|
||||
*/
|
||||
export interface DashboardPluginInternalFunctions {
|
||||
/**
|
||||
* A temporary backdoor to allow some actions access to the Dashboard panels. This should eventually be replaced with a generic version
|
||||
* on the PresentationContainer interface.
|
||||
*/
|
||||
getDashboardPanelFromId: (id: string) => Promise<DashboardPanelState>;
|
||||
|
||||
/**
|
||||
* A temporary backdoor to allow the filters notification popover to get the data views directly from the dashboard container
|
||||
*/
|
||||
getAllDataViews: () => DataView[];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue