Skip to content

Commit

Permalink
remove old types
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Sep 19, 2024
1 parent 798a26f commit 46d02d7
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 68 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 @@ -36,9 +36,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 @@ -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 @@ -26,8 +26,11 @@ 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 { DataView } from '@kbn/data-views-plugin/public';
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 +60,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<DataView[]>([])
);

return (
<EuiPopover
Expand Down Expand Up @@ -103,7 +108,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 46d02d7

Please sign in to comment.