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

[Graph] Clean up deprecated APIs #128579

Merged
merged 4 commits into from
Mar 29, 2022
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
4 changes: 2 additions & 2 deletions x-pack/plugins/graph/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from 'kibana/public';
import ReactDOM from 'react-dom';
import React from 'react';
import { DataPlugin, IndexPatternsContract } from '../../../../src/plugins/data/public';
import { DataPlugin, DataViewsContract } from '../../../../src/plugins/data/public';
import { LicensingPluginStart } from '../../licensing/public';
import { checkLicense } from '../common/check_license';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../src/plugins/navigation/public';
Expand Down Expand Up @@ -52,7 +52,7 @@ export interface GraphDependencies {
licensing: LicensingPluginStart;
chrome: ChromeStart;
toastNotifications: ToastsStart;
indexPatterns: IndexPatternsContract;
indexPatterns: DataViewsContract;
data: ReturnType<DataPlugin['start']>;
savedObjectsClient: SavedObjectsClientContract;
addBasePath: (url: string) => string;
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/graph/public/components/inspect_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import React, { useMemo, useState } from 'react';
import { EuiTab, EuiTabs, EuiText } from '@elastic/eui';
import { monaco, XJsonLang } from '@kbn/monaco';
import { FormattedMessage } from '@kbn/i18n-react';
import { IndexPattern } from '../../../../../src/plugins/data/public';
import { CodeEditor } from '../../../../../src/plugins/kibana_react/public';
import type { DataView } from '../../../../../src/plugins/data_views/public';

interface InspectPanelProps {
showInspect: boolean;
indexPattern?: IndexPattern;
indexPattern?: DataView;
lastRequest?: string;
lastResponse?: string;
}
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/graph/public/components/search_bar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
SavedObjectsStart,
} from 'kibana/public';
import { act } from 'react-dom/test-utils';
import { IndexPattern, QueryStringInput } from '../../../../../src/plugins/data/public';
import { QueryStringInput } from '../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../src/plugins/data_views/public';

import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public';
import { I18nProvider, InjectedIntl } from '@kbn/i18n-react';
Expand Down Expand Up @@ -87,12 +88,12 @@ describe('search_bar', () => {
const defaultProps = {
isLoading: false,
indexPatternProvider: {
get: jest.fn(() => Promise.resolve({ fields: [] } as unknown as IndexPattern)),
get: jest.fn(() => Promise.resolve({ fields: [] } as unknown as DataView)),
},
confirmWipeWorkspace: (callback: () => void) => {
callback();
},
onIndexPatternChange: (indexPattern?: IndexPattern) => {
onIndexPatternChange: (indexPattern?: DataView) => {
instance.setProps({
...defaultProps,
currentIndexPattern: indexPattern,
Expand Down
15 changes: 6 additions & 9 deletions x-pack/plugins/graph/public/components/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { useState, useEffect } from 'react';

import { i18n } from '@kbn/i18n';
import { connect } from 'react-redux';
import { toElasticsearchQuery, fromKueryExpression } from '@kbn/es-query';
import { IndexPatternSavedObject, IndexPatternProvider, WorkspaceField } from '../types';
import { openSourceModal } from '../services/source_modal';
import {
Expand All @@ -23,19 +24,18 @@ import {

import { useKibana } from '../../../../../src/plugins/kibana_react/public';
import {
IndexPattern,
QueryStringInput,
IDataPluginServices,
Query,
esKuery,
} from '../../../../../src/plugins/data/public';
import { TooltipWrapper } from './tooltip_wrapper';
import type { DataView } from '../../../../../src/plugins/data_views/public';

export interface SearchBarProps {
isLoading: boolean;
urlQuery: string | null;
currentIndexPattern?: IndexPattern;
onIndexPatternChange: (indexPattern?: IndexPattern) => void;
currentIndexPattern?: DataView;
onIndexPatternChange: (indexPattern?: DataView) => void;
confirmWipeWorkspace: (
onConfirm: () => void,
text?: string,
Expand All @@ -51,12 +51,9 @@ export interface SearchBarStateProps {
submit: (searchTerm: string) => void;
}

function queryToString(query: Query, indexPattern: IndexPattern) {
function queryToString(query: Query, indexPattern: DataView) {
if (query.language === 'kuery' && typeof query.query === 'string') {
const dsl = esKuery.toElasticsearchQuery(
esKuery.fromKueryExpression(query.query as string),
indexPattern
);
const dsl = toElasticsearchQuery(fromKueryExpression(query.query as string), indexPattern);
// JSON representation of query will be handled by existing logic.
// TODO clean this up and handle it in the data fetch layer once
// it moved to typescript.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
workspaceInitializedSelector,
} from '../../state_management';
import { FieldManager } from '../field_manager';
import { IndexPattern } from '../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../src/plugins/data_views/public';
import {
ControlType,
IndexPatternProvider,
Expand Down Expand Up @@ -89,7 +89,7 @@ export const WorkspaceLayoutComponent = ({
sharingSavedObjectProps,
spaces,
}: WorkspaceLayoutProps & WorkspaceLayoutStateProps) => {
const [currentIndexPattern, setCurrentIndexPattern] = useState<IndexPattern>();
const [currentIndexPattern, setCurrentIndexPattern] = useState<DataView>();
const [showInspect, setShowInspect] = useState(false);
const [pickerOpen, setPickerOpen] = useState(false);
const [mergeCandidates, setMergeCandidates] = useState<TermIntersect[]>([]);
Expand All @@ -112,7 +112,7 @@ export const WorkspaceLayoutComponent = ({
}, []);

const onIndexPatternChange = useCallback(
(indexPattern?: IndexPattern) => setCurrentIndexPattern(indexPattern),
(indexPattern?: DataView) => setCurrentIndexPattern(indexPattern),
[]
);

Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/graph/public/services/index_pattern_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

import { IndexPatternProvider } from '../types';
import { IndexPattern } from '../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../src/plugins/data_views/public';

export function createCachedIndexPatternProvider(
indexPatternGetter: (id: string) => Promise<IndexPattern>
indexPatternGetter: (id: string) => Promise<DataView>
): IndexPatternProvider {
const cache = new Map<string, IndexPattern>();
const cache = new Map<string, DataView>();

return {
get: async (id: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GraphWorkspaceSavedObject, IndexPatternSavedObject, Workspace } from '.
import { migrateLegacyIndexPatternRef, savedWorkspaceToAppState, mapFields } from './deserialize';
import { createWorkspace } from '../../services/workspace/graph_client_workspace';
import { outlinkEncoders } from '../../helpers/outlink_encoders';
import { IndexPattern } from '../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../src/plugins/data_views/public';

describe('deserialize', () => {
let savedWorkspace: GraphWorkspaceSavedObject;
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('deserialize', () => {
{ name: 'field2', type: 'string', aggregatable: true, isMapped: true },
{ name: 'field3', type: 'string', aggregatable: true, isMapped: true },
],
} as IndexPattern,
} as DataView,
workspace
);
}
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('deserialize', () => {
{ name: 'runtimeField', type: 'string', aggregatable: true, isMapped: false },
{ name: 'field3', type: 'string', aggregatable: true, isMapped: true },
],
} as IndexPattern;
} as DataView;
expect(mapFields(indexPattern).map(({ name }) => name)).toEqual([
'field1',
'field2',
Expand Down
15 changes: 5 additions & 10 deletions x-pack/plugins/graph/public/services/persistence/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ import {
colorChoices,
iconChoicesByClass,
} from '../../helpers/style_choices';
import {
IndexPattern,
indexPatterns as indexPatternsUtils,
} from '../../../../../../src/plugins/data/public';
import { indexPatterns as indexPatternsUtils } from '../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../src/plugins/data_views/public';

const defaultAdvancedSettings: AdvancedSettings = {
useSignificance: true,
Expand Down Expand Up @@ -98,7 +96,7 @@ export function lookupIndexPatternId(savedWorkspace: GraphWorkspaceSavedObject)
}

// returns all graph fields mapped out of the index pattern
export function mapFields(indexPattern: IndexPattern): WorkspaceField[] {
export function mapFields(indexPattern: DataView): WorkspaceField[] {
const blockedFieldNames = ['_id', '_index', '_score', '_source', '_type'];
const defaultHopSize = 5;

Expand Down Expand Up @@ -131,10 +129,7 @@ export function mapFields(indexPattern: IndexPattern): WorkspaceField[] {
});
}

function getFieldsWithWorkspaceSettings(
indexPattern: IndexPattern,
selectedFields: SerializedField[]
) {
function getFieldsWithWorkspaceSettings(indexPattern: DataView, selectedFields: SerializedField[]) {
const allFields = mapFields(indexPattern);

// merge in selected information into all fields
Expand Down Expand Up @@ -216,7 +211,7 @@ export function makeNodeId(field: string, term: string) {

export function savedWorkspaceToAppState(
savedWorkspace: GraphWorkspaceSavedObject,
indexPattern: IndexPattern,
indexPattern: DataView,
workspaceInstance: Workspace
): {
urlTemplates: UrlTemplate[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
setDatasource,
requestDatasource,
} from './datasource';
import { IndexPattern } from '../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../src/plugins/data_views/public';

/**
* Saga loading field information when the datasource is switched. This will overwrite current settings
Expand All @@ -34,7 +34,7 @@ export const datasourceSaga = ({
}: GraphStoreDependencies) => {
function* fetchFields(action: Action<IndexpatternDatasource>) {
try {
const indexPattern: IndexPattern = yield call(indexPatternProvider.get, action.payload.id);
const indexPattern: DataView = yield call(indexPatternProvider.get, action.payload.id);
yield put(loadFields(mapFields(indexPattern)));
yield put(datasourceLoaded());
const advancedSettings = settingsSelector(yield select());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { datasourceSelector, requestDatasource } from './datasource';
import { datasourceSaga } from './datasource.sagas';
import { fieldsSelector } from './fields';
import { updateSettings } from './advanced_settings';
import { IndexPattern } from '../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../src/plugins/data_views/public';

const waitForPromise = () => new Promise((r) => setTimeout(r));

Expand All @@ -27,7 +27,7 @@ describe('datasource saga', () => {
Promise.resolve({
title: 'test-pattern',
getNonScriptedFields: () => [{ name: 'field1', type: 'string', isMapped: true }],
} as IndexPattern)
} as DataView)
),
},
},
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/graph/public/state_management/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { createStore, applyMiddleware, AnyAction } from 'redux';
import { ChromeStart } from 'kibana/public';
import { GraphStoreDependencies, createRootReducer, GraphStore, GraphState } from './store';
import { Workspace } from '../types';
import { IndexPattern } from '../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../src/plugins/data_views/public';

export interface MockedGraphEnvironment {
store: GraphStore;
Expand Down Expand Up @@ -63,7 +63,7 @@ export function createMockGraphStore({
if (id === 'missing-dataview') {
throw Error('No data view with this id');
}
return { id: '123', title: 'test-pattern' } as unknown as IndexPattern;
return { id: '123', title: 'test-pattern' } as unknown as DataView;
}),
},
I18nContext: jest
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/graph/public/state_management/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { updateMetaData, metaDataSelector } from './meta_data';
import { openSaveModal, SaveWorkspaceHandler } from '../services/save_modal';
import { getEditPath } from '../services/url';
import { saveSavedWorkspace } from '../helpers/saved_workspace_utils';
import type { IndexPattern } from '../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../src/plugins/data_views/public';

export interface LoadSavedWorkspacePayload {
indexPatterns: IndexPatternSavedObject[];
Expand Down Expand Up @@ -68,7 +68,7 @@ export const loadingSaga = ({
const selectedIndexPatternId = lookupIndexPatternId(savedWorkspace);
let indexPattern;
try {
indexPattern = (yield call(indexPatternProvider.get, selectedIndexPatternId)) as IndexPattern;
indexPattern = (yield call(indexPatternProvider.get, selectedIndexPatternId)) as DataView;
} catch (e) {
notifications.toasts.addDanger(
i18n.translate('xpack.graph.loadWorkspace.missingDataViewErrorMessage', {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/graph/public/types/app_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { SimpleSavedObject } from 'src/core/public';
import { FontawesomeIcon } from '../helpers/style_choices';
import { OutlinkEncoder } from '../helpers/outlink_encoders';
import type { IndexPattern } from '../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../src/plugins/data_views/public';

export interface UrlTemplate {
url: string;
Expand Down Expand Up @@ -41,5 +41,5 @@ export interface AdvancedSettings {
export type IndexPatternSavedObject = SimpleSavedObject<{ title: string }>;

export interface IndexPatternProvider {
get(id: string): Promise<IndexPattern>;
get(id: string): Promise<DataView>;
}