Skip to content

Commit

Permalink
[Dashboard] Remove Deprecated References (#121925) (#124914)
Browse files Browse the repository at this point in the history
Remove index pattern references. Replace data filter imports with imports from es-query package

(cherry picked from commit 8dffa53)
  • Loading branch information
ThomThomson authored Feb 8, 2022
1 parent c8f8e0e commit 6672ab1
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 96 deletions.
1 change: 1 addition & 0 deletions src/plugins/dashboard/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"version": "kibana",
"requiredPlugins": [
"data",
"dataViews",
"embeddable",
"controls",
"inspector",
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/dashboard/public/application/dashboard_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export async function mountApp({
uiSettings: coreStart.uiSettings,
scopedHistory: () => scopedHistory,
screenshotModeService: screenshotMode,
indexPatterns: dataStart.indexPatterns,
dataViews: dataStart.dataViews,
savedQueryService: dataStart.query.savedQueries,
savedObjectsClient: coreStart.savedObjects.client,
savedDashboards: dashboardStart.getSavedDashboardLoader(),
Expand Down Expand Up @@ -212,7 +212,7 @@ export async function mountApp({
.getIncomingEmbeddablePackage(DashboardConstants.DASHBOARDS_ID, false)
);
if (!hasEmbeddableIncoming) {
dataStart.indexPatterns.clearCache();
dataStart.dataViews.clearCache();
}

// dispatch synthetic hash change event to update hash history objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ import { EmbeddableFactory, ViewMode } from '../../services/embeddable';
import { dashboardStateStore, setDescription, setViewMode } from '../state';
import { DashboardContainerServices } from '../embeddable/dashboard_container';
import { createKbnUrlStateStorage, defer } from '../../../../kibana_utils/public';
import { Filter, IIndexPattern, IndexPatternsContract } from '../../services/data';
import { useDashboardAppState, UseDashboardStateProps } from './use_dashboard_app_state';
import {
getSampleDashboardInput,
getSavedDashboardMock,
makeDefaultServices,
} from '../test_helpers';
import { DataViewsContract } from '../../services/data';
import { DataView } from '../../services/data_views';
import type { Filter } from '@kbn/es-query';

interface SetupEmbeddableFactoryReturn {
finalizeEmbeddableCreation: () => void;
Expand All @@ -56,12 +58,10 @@ const createDashboardAppStateProps = (): UseDashboardStateProps => ({

const createDashboardAppStateServices = () => {
const defaults = makeDefaultServices();
const indexPatterns = {} as IndexPatternsContract;
const defaultIndexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IIndexPattern;
indexPatterns.ensureDefaultDataView = jest.fn().mockImplementation(() => Promise.resolve(true));
indexPatterns.getDefault = jest
.fn()
.mockImplementation(() => Promise.resolve(defaultIndexPattern));
const dataViews = {} as DataViewsContract;
const defaultDataView = { id: 'foo', fields: [{ name: 'bar' }] } as DataView;
dataViews.ensureDefaultDataView = jest.fn().mockImplementation(() => Promise.resolve(true));
dataViews.getDefault = jest.fn().mockImplementation(() => Promise.resolve(defaultDataView));

const data = dataPluginMock.createStartContract();
data.query.filterManager.getUpdates$ = jest.fn().mockImplementation(() => of(void 0));
Expand All @@ -71,7 +71,7 @@ const createDashboardAppStateServices = () => {
.fn()
.mockImplementation(() => of(void 0));

return { ...defaults, indexPatterns, data };
return { ...defaults, dataViews, data };
};

const setupEmbeddableFactory = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs';
import { DashboardConstants } from '../..';
import { ViewMode } from '../../services/embeddable';
import { useKibana } from '../../services/kibana_react';
import { DataView } from '../../services/data_views';
import { getNewDashboardTitle } from '../../dashboard_strings';
import { IKbnUrlStateStorage } from '../../services/kibana_utils';
import { setDashboardState, useDashboardDispatch, useDashboardSelector } from '../state';
Expand All @@ -30,7 +31,7 @@ import {
tryDestroyDashboardContainer,
syncDashboardContainerInput,
savedObjectToDashboardState,
syncDashboardIndexPatterns,
syncDashboardDataViews,
syncDashboardFilterState,
loadSavedDashboardState,
buildDashboardContainer,
Expand Down Expand Up @@ -81,7 +82,7 @@ export const useDashboardAppState = ({
core,
chrome,
embeddable,
indexPatterns,
dataViews,
usageCollection,
savedDashboards,
initializerContext,
Expand Down Expand Up @@ -121,7 +122,7 @@ export const useDashboardAppState = ({
search,
history,
embeddable,
indexPatterns,
dataViews,
notifications,
kibanaVersion,
savedDashboards,
Expand Down Expand Up @@ -234,11 +235,11 @@ export const useDashboardAppState = ({
/**
* Start syncing index patterns between the Query Service and the Dashboard Container.
*/
const indexPatternsSubscription = syncDashboardIndexPatterns({
const dataViewsSubscription = syncDashboardDataViews({
dashboardContainer,
indexPatterns: dashboardBuildContext.indexPatterns,
onUpdateIndexPatterns: (newIndexPatterns) =>
setDashboardAppState((s) => ({ ...s, indexPatterns: newIndexPatterns })),
dataViews: dashboardBuildContext.dataViews,
onUpdateDataViews: (newDataViews: DataView[]) =>
setDashboardAppState((s) => ({ ...s, dataViews: newDataViews })),
});

/**
Expand Down Expand Up @@ -339,7 +340,7 @@ export const useDashboardAppState = ({
stopWatchingAppStateInUrl();
stopSyncingDashboardFilterState();
lastSavedSubscription.unsubscribe();
indexPatternsSubscription.unsubscribe();
dataViewsSubscription.unsubscribe();
tryDestroyDashboardContainer(dashboardContainer);
setDashboardAppState((state) => ({
...state,
Expand Down Expand Up @@ -368,7 +369,7 @@ export const useDashboardAppState = ({
usageCollection,
scopedHistory,
notifications,
indexPatterns,
dataViews,
kibanaVersion,
embeddable,
docTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Subscription } from 'rxjs';
import deepEqual from 'fast-deep-equal';
import { compareFilters, COMPARE_ALL_OPTIONS, Filter } from '@kbn/es-query';
import { compareFilters, COMPARE_ALL_OPTIONS, type Filter } from '@kbn/es-query';
import { distinctUntilChanged, distinctUntilKeyChanged } from 'rxjs/operators';

import { DashboardContainer } from '..';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { xor, omit, isEmpty } from 'lodash';
import fastIsEqual from 'fast-deep-equal';
import { compareFilters, COMPARE_ALL_OPTIONS, Filter, isFilterPinned } from '@kbn/es-query';
import { compareFilters, COMPARE_ALL_OPTIONS, type Filter, isFilterPinned } from '@kbn/es-query';

import { DashboardContainerInput } from '../..';
import { controlGroupInputIsEqual } from './dashboard_control_group';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dashboard/public/application/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export { DashboardSessionStorage } from './dashboard_session_storage';
export { loadSavedDashboardState } from './load_saved_dashboard_state';
export { attemptLoadDashboardByTitle } from './load_dashboard_by_title';
export { syncDashboardFilterState } from './sync_dashboard_filter_state';
export { syncDashboardIndexPatterns } from './sync_dashboard_index_patterns';
export { syncDashboardDataViews } from './sync_dashboard_data_views';
export { syncDashboardContainerInput } from './sync_dashboard_container_input';
export { loadDashboardHistoryLocationState } from './load_dashboard_history_location_state';
export { buildDashboardContainer, tryDestroyDashboardContainer } from './build_dashboard_container';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const loadSavedDashboardState = async ({
query,
history,
notifications,
indexPatterns,
dataViews,
savedDashboards,
usageCollection,
savedDashboardId,
Expand All @@ -51,7 +51,7 @@ export const loadSavedDashboardState = async ({
notifications.toasts.addWarning(getDashboard60Warning());
return;
}
await indexPatterns.ensureDefaultDataView();
await dataViews.ensureDefaultDataView();
try {
const savedDashboard = (await savedDashboards.get({
id: savedDashboardId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import _ from 'lodash';

import { isFilterPinned } from '@kbn/es-query';
import { convertTimeToUTCString } from '.';
import { NotificationsStart } from '../../services/core';
import { DashboardSavedObject } from '../../saved_dashboards';
Expand All @@ -16,7 +17,7 @@ import { SavedObjectSaveOpts } from '../../services/saved_objects';
import { dashboardSaveToastStrings } from '../../dashboard_strings';
import { getHasTaggingCapabilitiesGuard } from './dashboard_tagging';
import { SavedObjectsTaggingApi } from '../../services/saved_objects_tagging_oss';
import { RefreshInterval, TimefilterContract, esFilters } from '../../services/data';
import { RefreshInterval, TimefilterContract } from '../../services/data';
import { convertPanelStateToSavedDashboardPanel } from '../../../common/embeddable/embeddable_saved_object_converters';
import { DashboardSessionStorage } from './dashboard_session_storage';
import { serializeControlGroupToDashboardSavedObject } from './dashboard_control_group';
Expand Down Expand Up @@ -81,9 +82,7 @@ export const saveDashboard = async ({
savedDashboard.refreshInterval = savedDashboard.timeRestore ? timeRestoreObj : undefined;

// only save unpinned filters
const unpinnedFilters = savedDashboard
.getFilters()
.filter((filter) => !esFilters.isFilterPinned(filter));
const unpinnedFilters = savedDashboard.getFilters().filter((filter) => !isFilterPinned(filter));
savedDashboard.searchSource.setField('filter', unpinnedFilters);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import _ from 'lodash';
import { Subscription } from 'rxjs';
import { debounceTime, tap } from 'rxjs/operators';

import { compareFilters, COMPARE_ALL_OPTIONS, type Filter } from '@kbn/es-query';
import { DashboardContainer } from '../embeddable';
import { esFilters, Filter, Query } from '../../services/data';
import { Query } from '../../services/data';
import { DashboardConstants, DashboardSavedObject } from '../..';
import {
setControlGroupState,
Expand Down Expand Up @@ -96,13 +97,7 @@ export const applyContainerChangesToState = ({
return;
}
const { filterManager } = query;
if (
!esFilters.compareFilters(
input.filters,
filterManager.getFilters(),
esFilters.COMPARE_ALL_OPTIONS
)
) {
if (!compareFilters(input.filters, filterManager.getFilters(), COMPARE_ALL_OPTIONS)) {
// Add filters modifies the object passed to it, hence the clone deep.
filterManager.addFilters(_.cloneDeep(input.filters));
applyFilters(latestState.query, input.filters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,51 @@ import { distinctUntilChanged, switchMap, filter, mapTo, map } from 'rxjs/operat

import { DashboardContainer } from '..';
import { isErrorEmbeddable } from '../../services/embeddable';
import { IndexPattern, IndexPatternsContract } from '../../services/data';
import { DataViewsContract } from '../../services/data';
import { DataView } from '../../services/data_views';

interface SyncDashboardIndexPatternsProps {
interface SyncDashboardDataViewsProps {
dashboardContainer: DashboardContainer;
indexPatterns: IndexPatternsContract;
onUpdateIndexPatterns: (newIndexPatterns: IndexPattern[]) => void;
dataViews: DataViewsContract;
onUpdateDataViews: (newDataViews: DataView[]) => void;
}

export const syncDashboardIndexPatterns = ({
export const syncDashboardDataViews = ({
dashboardContainer,
indexPatterns,
onUpdateIndexPatterns,
}: SyncDashboardIndexPatternsProps) => {
const updateIndexPatternsOperator = pipe(
dataViews,
onUpdateDataViews,
}: SyncDashboardDataViewsProps) => {
const updateDataViewsOperator = pipe(
filter((container: DashboardContainer) => !!container && !isErrorEmbeddable(container)),
map((container: DashboardContainer): IndexPattern[] | undefined => {
let panelIndexPatterns: IndexPattern[] = [];
map((container: DashboardContainer): DataView[] | undefined => {
let panelDataViews: DataView[] = [];

Object.values(container.getChildIds()).forEach((id) => {
const embeddableInstance = container.getChild(id);
if (isErrorEmbeddable(embeddableInstance)) return;
const embeddableIndexPatterns = (embeddableInstance.getOutput() as any).indexPatterns;
if (!embeddableIndexPatterns) return;
panelIndexPatterns.push(...embeddableIndexPatterns);
const embeddableDataViews = (
embeddableInstance.getOutput() as { indexPatterns: DataView[] }
).indexPatterns;
if (!embeddableDataViews) return;
panelDataViews.push(...embeddableDataViews);
});
if (container.controlGroup) {
panelIndexPatterns.push(...(container.controlGroup.getOutput().dataViews ?? []));
panelDataViews.push(...(container.controlGroup.getOutput().dataViews ?? []));
}
panelIndexPatterns = uniqBy(panelIndexPatterns, 'id');
panelDataViews = uniqBy(panelDataViews, 'id');

/**
* If no index patterns have been returned yet, and there is at least one embeddable which
* hasn't yet loaded, defer the loading of the default index pattern by returning undefined.
*/
if (
panelIndexPatterns.length === 0 &&
panelDataViews.length === 0 &&
Object.keys(container.getOutput().embeddableLoaded).length > 0 &&
Object.values(container.getOutput().embeddableLoaded).some((value) => value === false)
) {
return;
}
return panelIndexPatterns;
return panelDataViews;
}),
distinctUntilChanged((a, b) =>
deepEqual(
Expand All @@ -63,29 +66,29 @@ export const syncDashboardIndexPatterns = ({
)
),
// using switchMap for previous task cancellation
switchMap((panelIndexPatterns?: IndexPattern[]) => {
switchMap((panelDataViews?: DataView[]) => {
return new Observable((observer) => {
if (!panelIndexPatterns) return;
if (panelIndexPatterns.length > 0) {
if (!panelDataViews) return;
if (panelDataViews.length > 0) {
if (observer.closed) return;
onUpdateIndexPatterns(panelIndexPatterns);
onUpdateDataViews(panelDataViews);
observer.complete();
} else {
indexPatterns.getDefault().then((defaultIndexPattern) => {
dataViews.getDefault().then((defaultDataView) => {
if (observer.closed) return;
onUpdateIndexPatterns([defaultIndexPattern as IndexPattern]);
onUpdateDataViews([defaultDataView as DataView]);
observer.complete();
});
}
});
})
);

const indexPatternSources = [dashboardContainer.getOutput$()];
const dataViewSources = [dashboardContainer.getOutput$()];
if (dashboardContainer.controlGroup)
indexPatternSources.push(dashboardContainer.controlGroup.getOutput$());
dataViewSources.push(dashboardContainer.controlGroup.getOutput$());

return combineLatest(indexPatternSources)
.pipe(mapTo(dashboardContainer), updateIndexPatternsOperator)
return combineLatest(dataViewSources)
.pipe(mapTo(dashboardContainer), updateDataViewsOperator)
.subscribe();
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import { getDashboardListItemLink } from './get_dashboard_list_item_link';
import { ApplicationStart } from 'kibana/public';
import { esFilters } from '../../../../data/public';
import { createHashHistory } from 'history';
import { createKbnUrlStateStorage } from '../../../../kibana_utils/public';
import { GLOBAL_STATE_STORAGE_KEY } from '../../url_generator';
import { FilterStateStore } from '@kbn/es-query';

const DASHBOARD_ID = '13823000-99b9-11ea-9eb6-d9e8adceb647';

Expand Down Expand Up @@ -118,7 +118,7 @@ describe('when global filters change', () => {
},
query: { query: 'q1' },
$state: {
store: esFilters.FilterStateStore.GLOBAL_STATE,
store: FilterStateStore.GLOBAL_STATE,
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { UrlForwardingStart } from '../../../../url_forwarding/public';
import { NavigationPublicPluginStart } from '../../services/navigation';
import { DashboardAppServices, DashboardAppCapabilities } from '../../types';
import { embeddablePluginMock } from '../../../../embeddable/public/mocks';
import { IndexPatternsContract, SavedQueryService } from '../../services/data';
import { DataViewsContract, SavedQueryService } from '../../services/data';
import { savedObjectsPluginMock } from '../../../../saved_objects/public/mocks';
import { screenshotModePluginMock } from '../../../../screenshot_mode/public/mocks';
import { visualizationsPluginMock } from '../../../../visualizations/public/mocks';
Expand Down Expand Up @@ -83,7 +83,7 @@ export function makeDefaultServices(): DashboardAppServices {
savedObjectsClient: core.savedObjects.client,
dashboardCapabilities: defaultCapabilities,
data: dataPluginMock.createStartContract(),
indexPatterns: {} as IndexPatternsContract,
dataViews: {} as DataViewsContract,
savedQueryService: {} as SavedQueryService,
scopedHistory: () => ({} as ScopedHistory),
setHeaderActionMenu: (mountPoint) => {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ export function DashboardTopNav({
showDatePicker,
showFilterBar,
setMenuMountPoint: embedSettings ? undefined : setHeaderActionMenu,
indexPatterns: dashboardAppState.indexPatterns,
indexPatterns: dashboardAppState.dataViews,
showSaveQuery: dashboardCapabilities.saveQuery,
useDefaultBehaviors: true,
savedQuery: state.savedQuery,
Expand Down
Loading

0 comments on commit 6672ab1

Please sign in to comment.