Skip to content

Commit

Permalink
[data view management] Remove deprecated api usage (#122412)
Browse files Browse the repository at this point in the history
* removed a lot of deprecated api usage
  • Loading branch information
mattkime authored Jan 13, 2022
1 parent 0da9156 commit 1aadcd3
Show file tree
Hide file tree
Showing 39 changed files with 212 additions and 161 deletions.
1 change: 1 addition & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type {
GetFieldsOptions,
AggregationRestrictions,
IndexPatternListItem,
DataViewListItem,
} from '../common';
export {
ES_FIELD_TYPES,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data_view_management/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["management", "data", "urlForwarding", "dataViewFieldEditor", "dataViewEditor"],
"requiredPlugins": ["management", "data", "urlForwarding", "dataViewFieldEditor", "dataViewEditor", "dataViews", "fieldFormats"],
"requiredBundles": ["kibanaReact", "kibanaUtils"],
"owner": {
"name": "App Services",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { i18n } from '@kbn/i18n';
import { IndexPattern } from '../../../data/public';
import { DataView } from '../../../data_views/public';

export function getListBreadcrumbs() {
return [
Expand All @@ -32,7 +32,7 @@ export function getCreateBreadcrumbs() {
];
}

export function getEditBreadcrumbs(indexPattern: IndexPattern) {
export function getEditBreadcrumbs(indexPattern: DataView) {
return [
...getListBreadcrumbs(),
{
Expand All @@ -42,7 +42,7 @@ export function getEditBreadcrumbs(indexPattern: IndexPattern) {
];
}

export function getEditFieldBreadcrumbs(indexPattern: IndexPattern, fieldName: string) {
export function getEditFieldBreadcrumbs(indexPattern: DataView, fieldName: string) {
return [
...getEditBreadcrumbs(indexPattern),
{
Expand All @@ -51,7 +51,7 @@ export function getEditFieldBreadcrumbs(indexPattern: IndexPattern, fieldName: s
];
}

export function getCreateFieldBreadcrumbs(indexPattern: IndexPattern) {
export function getCreateFieldBreadcrumbs(indexPattern: DataView) {
return [
...getEditBreadcrumbs(indexPattern),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { RouteComponentProps, withRouter } from 'react-router-dom';

import { EuiSpacer } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { IndexPattern, IndexPatternField } from '../../../../../../plugins/data/public';
import { DataView, DataViewField } from '../../../../../../plugins/data_views/public';
import { useKibana } from '../../../../../../plugins/kibana_react/public';
import { IndexPatternManagmentContext } from '../../../types';
import { IndexHeader } from '../index_header';
Expand All @@ -20,7 +20,7 @@ import { TAB_INDEXED_FIELDS, TAB_SCRIPTED_FIELDS } from '../constants';
import { FieldEditor } from '../../field_editor';

interface CreateEditFieldProps extends RouteComponentProps {
indexPattern: IndexPattern;
indexPattern: DataView;
mode?: string;
fieldName?: string;
}
Expand All @@ -34,7 +34,7 @@ const newFieldPlaceholder = i18n.translate(

export const CreateEditField = withRouter(
({ indexPattern, mode, fieldName, history }: CreateEditFieldProps) => {
const { uiSettings, chrome, notifications, data } =
const { uiSettings, chrome, notifications, dataViews } =
useKibana<IndexPatternManagmentContext>().services;
const spec =
mode === 'edit' && fieldName
Expand All @@ -43,7 +43,7 @@ export const CreateEditField = withRouter(
scripted: true,
type: 'number',
name: undefined,
} as unknown as IndexPatternField);
} as unknown as DataViewField);

const url = `/dataView/${indexPattern.id}`;

Expand Down Expand Up @@ -76,7 +76,7 @@ export const CreateEditField = withRouter(
indexPattern={indexPattern}
spec={spec}
services={{
indexPatternService: data.indexPatterns,
indexPatternService: dataViews,
redirectAway,
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import React, { useEffect, useState } from 'react';
import { withRouter, RouteComponentProps } from 'react-router-dom';

import { IndexPattern } from '../../../../../../plugins/data/public';
import type { DataView } from '../../../../../../plugins/data_views/public';
import { getEditFieldBreadcrumbs, getCreateFieldBreadcrumbs } from '../../breadcrumbs';
import { useKibana } from '../../../../../../plugins/kibana_react/public';
import { IndexPatternManagmentContext } from '../../../types';
Expand All @@ -18,21 +18,21 @@ import { CreateEditField } from './create_edit_field';
export type CreateEditFieldContainerProps = RouteComponentProps<{ id: string; fieldName?: string }>;

const CreateEditFieldCont: React.FC<CreateEditFieldContainerProps> = ({ ...props }) => {
const { setBreadcrumbs, data } = useKibana<IndexPatternManagmentContext>().services;
const [indexPattern, setIndexPattern] = useState<IndexPattern>();
const { setBreadcrumbs, dataViews } = useKibana<IndexPatternManagmentContext>().services;
const [indexPattern, setIndexPattern] = useState<DataView>();
const fieldName =
props.match.params.fieldName && decodeURIComponent(props.match.params.fieldName);

useEffect(() => {
data.indexPatterns.get(props.match.params.id).then((ip: IndexPattern) => {
dataViews.get(props.match.params.id).then((ip: DataView) => {
setIndexPattern(ip);
if (ip) {
setBreadcrumbs(
fieldName ? getEditFieldBreadcrumbs(ip, fieldName) : getCreateFieldBreadcrumbs(ip)
);
}
});
}, [props.match.params.id, fieldName, setBreadcrumbs, data.indexPatterns]);
}, [props.match.params.id, fieldName, setBreadcrumbs, dataViews]);

if (indexPattern) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { IndexPattern, IndexPatternField } from '../../../../../plugins/data/public';
import { DataView, DataViewField } from '../../../../../plugins/data_views/public';
import { useKibana } from '../../../../../plugins/kibana_react/public';
import { IndexPatternManagmentContext } from '../../types';
import { Tabs } from './tabs';
import { IndexHeader } from './index_header';
import { getTags } from '../utils';

export interface EditIndexPatternProps extends RouteComponentProps {
indexPattern: IndexPattern;
indexPattern: DataView;
}

const mappingAPILink = i18n.translate(
Expand Down Expand Up @@ -65,10 +65,10 @@ const securitySolution = 'security-solution';

export const EditIndexPattern = withRouter(
({ indexPattern, history, location }: EditIndexPatternProps) => {
const { application, uiSettings, overlays, chrome, data } =
const { application, uiSettings, overlays, chrome, dataViews } =
useKibana<IndexPatternManagmentContext>().services;
const [fields, setFields] = useState<IndexPatternField[]>(indexPattern.getNonScriptedFields());
const [conflictedFields, setConflictedFields] = useState<IndexPatternField[]>(
const [fields, setFields] = useState<DataViewField[]>(indexPattern.getNonScriptedFields());
const [conflictedFields, setConflictedFields] = useState<DataViewField[]>(
indexPattern.fields.getAll().filter((field) => field.type === 'conflict')
);
const [defaultIndex, setDefaultIndex] = useState<string>(uiSettings.get('defaultIndex'));
Expand All @@ -93,7 +93,7 @@ export const EditIndexPattern = withRouter(
const removePattern = () => {
async function doRemove() {
if (indexPattern.id === defaultIndex) {
const indexPatterns = await data.dataViews.getIdsWithTitle();
const indexPatterns = await dataViews.getIdsWithTitle();
uiSettings.remove('defaultIndex');
const otherPatterns = filter(indexPatterns, (pattern) => {
return pattern.id !== indexPattern.id;
Expand All @@ -104,7 +104,7 @@ export const EditIndexPattern = withRouter(
}
}
if (indexPattern.id) {
Promise.resolve(data.dataViews.delete(indexPattern.id)).then(function () {
Promise.resolve(dataViews.delete(indexPattern.id)).then(function () {
history.push('');
});
}
Expand Down Expand Up @@ -201,7 +201,7 @@ export const EditIndexPattern = withRouter(
<EuiSpacer />
<Tabs
indexPattern={indexPattern}
saveIndexPattern={data.indexPatterns.updateSavedObject.bind(data.indexPatterns)}
saveIndexPattern={dataViews.updateSavedObject.bind(dataViews)}
fields={fields}
history={history}
location={location}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@

import React, { useEffect, useState } from 'react';
import { withRouter, RouteComponentProps } from 'react-router-dom';
import { IndexPattern } from '../../../../../plugins/data/public';
import { DataView } from '../../../../../plugins/data_views/public';
import { useKibana } from '../../../../../plugins/kibana_react/public';
import { IndexPatternManagmentContext } from '../../types';
import { getEditBreadcrumbs } from '../breadcrumbs';

import { EditIndexPattern } from '../edit_index_pattern';

const EditIndexPatternCont: React.FC<RouteComponentProps<{ id: string }>> = ({ ...props }) => {
const { data, setBreadcrumbs } = useKibana<IndexPatternManagmentContext>().services;
const [indexPattern, setIndexPattern] = useState<IndexPattern>();
const { dataViews, setBreadcrumbs } = useKibana<IndexPatternManagmentContext>().services;
const [indexPattern, setIndexPattern] = useState<DataView>();

useEffect(() => {
data.indexPatterns.get(props.match.params.id).then((ip: IndexPattern) => {
dataViews.get(props.match.params.id).then((ip: DataView) => {
setIndexPattern(ip);
setBreadcrumbs(getEditBreadcrumbs(ip));
});
}, [data.indexPatterns, props.match.params.id, setBreadcrumbs]);
}, [dataViews, props.match.params.id, setBreadcrumbs]);

if (indexPattern) {
return <EditIndexPattern indexPattern={indexPattern} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiButtonIcon, EuiPageHeader, EuiToolTip } from '@elastic/eui';
import { IIndexPattern } from 'src/plugins/data/public';
import { DataView } from 'src/plugins/data_views/public';

interface IndexHeaderProps {
indexPattern: IIndexPattern;
indexPattern: DataView;
defaultIndex?: string;
setDefault?: () => void;
deleteIndexPatternClick?: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React from 'react';
import { shallow } from 'enzyme';
import { IndexPattern } from 'src/plugins/data/public';
import { DataView } from 'src/plugins/data_views/public';
import { IndexedFieldItem } from '../../types';
import { Table, renderFieldName, getConflictModalContent } from './table';
import { overlayServiceMock, themeServiceMock } from 'src/core/public/mocks';
Expand All @@ -17,7 +17,7 @@ const theme = themeServiceMock.createStartContract();

const indexPattern = {
timeFieldName: 'timestamp',
} as IndexPattern;
} as DataView;

const items: IndexedFieldItem[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { toMountPoint } from '../../../../../../../kibana_react/public';

import { IIndexPattern } from '../../../../../../../data/public';
import { DataView } from '../../../../../../../data_views/public';
import { IndexedFieldItem } from '../../types';

// localized labels
Expand Down Expand Up @@ -174,7 +174,7 @@ const conflictType = i18n.translate(
);

interface IndexedFieldProps {
indexPattern: IIndexPattern;
indexPattern: DataView;
items: IndexedFieldItem[];
editField: (field: IndexedFieldItem) => void;
deleteField: (fieldName: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import { IndexPatternField, IndexPattern, IndexPatternType } from 'src/plugins/data/public';
import { DataViewField, DataView, DataViewType } from 'src/plugins/data_views/public';
import { IndexedFieldsTable } from './indexed_fields_table';
import { getFieldInfo } from '../../utils';

Expand Down Expand Up @@ -36,10 +36,10 @@ const helpers = {
const indexPattern = {
getNonScriptedFields: () => fields,
getFormatterForFieldNoDefault: () => ({ params: () => ({}) }),
} as unknown as IndexPattern;
} as unknown as DataView;

const rollupIndexPattern = {
type: IndexPatternType.ROLLUP,
type: DataViewType.ROLLUP,
typeMeta: {
params: {
'rollup-index': 'rollup',
Expand All @@ -64,12 +64,12 @@ const rollupIndexPattern = {
},
getNonScriptedFields: () => fields,
getFormatterForFieldNoDefault: () => ({ params: () => ({}) }),
} as unknown as IndexPattern;
} as unknown as DataView;

const mockFieldToIndexPatternField = (
spec: Record<string, string | string[] | boolean | undefined>
) => {
return new IndexPatternField(spec as unknown as IndexPatternField['spec']);
return new DataViewField(spec as unknown as DataViewField['spec']);
};

const fields = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
import React, { Component } from 'react';
import { createSelector } from 'reselect';
import { OverlayStart, ThemeServiceStart } from 'src/core/public';
import { IndexPatternField, IndexPattern } from '../../../../../../plugins/data/public';
import { DataViewField, DataView } from '../../../../../../plugins/data_views/public';
import { useKibana } from '../../../../../../plugins/kibana_react/public';
import { Table } from './components/table';
import { IndexedFieldItem } from './types';
import { IndexPatternManagmentContext } from '../../../types';

interface IndexedFieldsTableProps {
fields: IndexPatternField[];
indexPattern: IndexPattern;
fields: DataViewField[];
indexPattern: DataView;
fieldFilter?: string;
indexedFieldTypeFilter?: string;
helpers: {
editField: (fieldName: string) => void;
deleteField: (fieldName: string) => void;
getFieldInfo: (indexPattern: IndexPattern, field: IndexPatternField) => string[];
getFieldInfo: (indexPattern: DataView, field: DataViewField) => string[];
};
fieldWildcardMatcher: (filters: any[]) => (val: any) => boolean;
userEditPermission: boolean;
Expand Down Expand Up @@ -61,7 +61,7 @@ class IndexedFields extends Component<IndexedFieldsTableProps, IndexedFieldsTabl
}
}

mapFields(fields: IndexPatternField[]): IndexedFieldItem[] {
mapFields(fields: DataViewField[]): IndexedFieldItem[] {
const { indexPattern, fieldWildcardMatcher, helpers, userEditPermission } = this.props;
const sourceFilters =
indexPattern.sourceFilters &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

import { DataViewFieldBase } from '@kbn/es-query';
import { IndexPatternField } from '../../../../../../plugins/data/public';
import { DataViewField } from '../../../../../../plugins/data_views/public';

type IndexedFieldItemBase = Partial<IndexPatternField> & DataViewFieldBase;
type IndexedFieldItemBase = Partial<DataViewField> & DataViewFieldBase;

export interface IndexedFieldItem extends IndexedFieldItemBase {
info: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import { shallow } from 'enzyme';

import { Table } from '../table';
import { ScriptedFieldItem } from '../../types';
import { IIndexPattern } from 'src/plugins/data/public';
import { DataView } from 'src/plugins/data_views/public';

const getIndexPatternMock = (mockedFields: any = {}) => ({ ...mockedFields } as IIndexPattern);
const getIndexPatternMock = (mockedFields: any = {}) => ({ ...mockedFields } as DataView);

const items: ScriptedFieldItem[] = [
{ name: '1', lang: 'painless', script: '', isUserEditable: true },
{ name: '2', lang: 'painless', script: '', isUserEditable: false },
];

describe('Table', () => {
let indexPattern: IIndexPattern;
let indexPattern: DataView;

beforeEach(() => {
indexPattern = getIndexPatternMock({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { i18n } from '@kbn/i18n';
import { EuiInMemoryTable, EuiBasicTableColumn } from '@elastic/eui';

import { ScriptedFieldItem } from '../../types';
import { IIndexPattern } from '../../../../../../../data/public';
import { DataView } from '../../../../../../../data_views/public';

interface TableProps {
indexPattern: IIndexPattern;
indexPattern: DataView;
items: ScriptedFieldItem[];
editField: (field: ScriptedFieldItem) => void;
deleteField: (field: ScriptedFieldItem) => void;
Expand Down
Loading

0 comments on commit 1aadcd3

Please sign in to comment.