From ee6719226b4e0444c50fbeb9ee452b02762064b8 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 28 Jan 2022 13:36:03 -0600 Subject: [PATCH 1/3] address deprecated apis --- src/plugins/data/common/index.ts | 2 -- src/plugins/data/common/kbn_field_types/index.ts | 15 +-------------- src/plugins/data/public/index.ts | 9 +-------- src/plugins/data/server/index.ts | 2 +- .../data_view_editor_flyout_content.tsx | 6 +++--- .../data_view_flyout_content_container.tsx | 6 +++--- .../data_view_editor/public/shared_imports.ts | 3 +-- .../field_format_editor/field_format_editor.tsx | 2 +- .../data_views/common/data_views/data_views.ts | 8 +------- src/plugins/data_views/common/fields/types.ts | 2 +- src/plugins/data_views/common/index.ts | 4 ++-- src/plugins/data_views/public/index.ts | 8 +++++++- .../server/deprecations/scripted_fields.ts | 4 ++-- src/plugins/data_views/server/utils.ts | 8 ++++---- 14 files changed, 28 insertions(+), 51 deletions(-) diff --git a/src/plugins/data/common/index.ts b/src/plugins/data/common/index.ts index 9a58b73d2c49c..404249d56d638 100644 --- a/src/plugins/data/common/index.ts +++ b/src/plugins/data/common/index.ts @@ -54,7 +54,6 @@ export type { export type { IndexPatternsContract, DataViewsContract, - IndexPatternListItem, DataViewListItem, } from '../../data_views/common'; export { @@ -68,7 +67,6 @@ export { DataViewField, IndexPatternField, DataViewType, - IndexPatternType, IndexPatternsService, DataViewsService, IndexPattern, diff --git a/src/plugins/data/common/kbn_field_types/index.ts b/src/plugins/data/common/kbn_field_types/index.ts index 26fd3abd232d4..f01401948dec8 100644 --- a/src/plugins/data/common/kbn_field_types/index.ts +++ b/src/plugins/data/common/kbn_field_types/index.ts @@ -8,19 +8,12 @@ // NOTE: trick to mark exports as deprecated (only for constants and types, but not for interfaces, classes or enums) import { - castEsToKbnFieldTypeName as oldCastEsToKbnFieldTypeName, getFilterableKbnTypeNames as oldGetFilterableKbnTypeNames, getKbnFieldType as oldGetKbnFieldType, getKbnTypeNames as oldGetKbnTypeNames, KbnFieldType, } from '@kbn/field-types'; -/** - * @deprecated Import from the "@kbn/field-types" package directly instead. - * @removeBy 8.1 - */ -const castEsToKbnFieldTypeName = oldCastEsToKbnFieldTypeName; - /** * @deprecated Import from the "@kbn/field-types" package directly instead. * @removeBy 8.1 @@ -39,10 +32,4 @@ const getKbnFieldType = oldGetKbnFieldType; */ const getKbnTypeNames = oldGetKbnTypeNames; -export { - castEsToKbnFieldTypeName, - getKbnFieldType, - getKbnTypeNames, - getFilterableKbnTypeNames, - KbnFieldType, -}; +export { getKbnFieldType, getKbnTypeNames, getFilterableKbnTypeNames, KbnFieldType }; diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index ec380a0845985..7037af5ce54b1 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -82,7 +82,6 @@ export type { IndexPatternLoadExpressionFunctionDefinition, GetFieldsOptions, AggregationRestrictions, - IndexPatternListItem, DataViewListItem, } from '../common'; export { @@ -90,7 +89,6 @@ export { KBN_FIELD_TYPES, UI_SETTINGS, fieldList, - IndexPatternType, DuplicateDataViewError, } from '../common'; @@ -295,12 +293,7 @@ export type { export type { AggsStart } from './search/aggs'; -export { - getTime, - // kbn field types - castEsToKbnFieldTypeName, - getKbnTypeNames, -} from '../common'; +export { getTime, getKbnTypeNames } from '../common'; export { isTimeRange, isQuery } from '../common'; diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index 939d4a9fa3237..87c41cf76a359 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -106,7 +106,7 @@ export const search = { */ export type { TimeRange } from '../common'; -export { castEsToKbnFieldTypeName, getTime, parseInterval } from '../common'; +export { getTime, parseInterval } from '../common'; /** * Static code to be shared externally diff --git a/src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx b/src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx index 3c62d6f5eb8c4..c28b03de77adc 100644 --- a/src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx +++ b/src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx @@ -13,7 +13,7 @@ import memoizeOne from 'memoize-one'; import { DataViewField } from '../../../data_views/public'; import { - IndexPatternSpec, + DataViewSpec, Form, useForm, useFormData, @@ -51,7 +51,7 @@ export interface Props { /** * Handler for the "save" footer button */ - onSave: (indexPatternSpec: IndexPatternSpec) => void; + onSave: (indexPatternSpec: DataViewSpec) => void; /** * Handler for the "cancel" footer button */ @@ -84,7 +84,7 @@ const IndexPatternEditorFlyoutContentComponent = ({ return; } - const indexPatternStub: IndexPatternSpec = { + const indexPatternStub: DataViewSpec = { title: formData.title, timeFieldName: formData.timestampField?.value, id: formData.id, diff --git a/src/plugins/data_view_editor/public/components/data_view_flyout_content_container.tsx b/src/plugins/data_view_editor/public/components/data_view_flyout_content_container.tsx index bf42582db8e3f..2fe95d753bb09 100644 --- a/src/plugins/data_view_editor/public/components/data_view_flyout_content_container.tsx +++ b/src/plugins/data_view_editor/public/components/data_view_flyout_content_container.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { IndexPatternSpec, useKibana } from '../shared_imports'; +import { DataViewSpec, useKibana } from '../shared_imports'; import { IndexPatternEditorFlyoutContent } from './data_view_editor_flyout_content'; import { DataViewEditorContext, DataViewEditorProps } from '../types'; @@ -23,9 +23,9 @@ const IndexPatternFlyoutContentContainer = ({ services: { dataViews, notifications }, } = useKibana(); - const onSaveClick = async (indexPatternSpec: IndexPatternSpec) => { + const onSaveClick = async (dataViewSpec: DataViewSpec) => { try { - const indexPattern = await dataViews.createAndSave(indexPatternSpec); + const indexPattern = await dataViews.createAndSave(dataViewSpec); const message = i18n.translate('indexPatternEditor.saved', { defaultMessage: "Saved '{indexPatternTitle}'", diff --git a/src/plugins/data_view_editor/public/shared_imports.ts b/src/plugins/data_view_editor/public/shared_imports.ts index 02204bb1c176f..82fc33f5834d4 100644 --- a/src/plugins/data_view_editor/public/shared_imports.ts +++ b/src/plugins/data_view_editor/public/shared_imports.ts @@ -8,12 +8,11 @@ export type { DataPublicPluginStart, - IndexPatternSpec, GetFieldsOptions, IndexPatternAggRestrictions, } from '../../data/public'; export { IndexPattern, IndexPatternField } from '../../data/public'; -export { DataView } from '../../data_views/public'; +export { DataView, DataViewSpec } from '../../data_views/public'; export { createKibanaReactContext, diff --git a/src/plugins/data_view_field_editor/public/components/field_format_editor/field_format_editor.tsx b/src/plugins/data_view_field_editor/public/components/field_format_editor/field_format_editor.tsx index 3879abeab2f58..c55385e152bcf 100644 --- a/src/plugins/data_view_field_editor/public/components/field_format_editor/field_format_editor.tsx +++ b/src/plugins/data_view_field_editor/public/components/field_format_editor/field_format_editor.tsx @@ -19,7 +19,7 @@ import { } from 'src/plugins/data/public'; import type { FieldFormatInstanceType } from 'src/plugins/field_formats/common'; import { CoreStart } from 'src/core/public'; -import { castEsToKbnFieldTypeName } from '../../../../data/public'; +import { castEsToKbnFieldTypeName } from '@kbn/field-types'; import { FormatEditor } from './format_editor'; import { FormatEditorServiceStart } from '../../service'; import { FieldFormatConfig } from '../../types'; diff --git a/src/plugins/data_views/common/data_views/data_views.ts b/src/plugins/data_views/common/data_views/data_views.ts index 26e1683b60006..ddd7989eb5990 100644 --- a/src/plugins/data_views/common/data_views/data_views.ts +++ b/src/plugins/data_views/common/data_views/data_views.ts @@ -53,12 +53,6 @@ export interface DataViewListItem { typeMeta?: TypeMeta; } -/** - * @deprecated Use DataViewListItem. All index pattern interfaces were renamed. - */ - -export type IndexPatternListItem = DataViewListItem; - export interface DataViewsServiceDeps { uiSettings: UiSettingsCommon; savedObjectsClient: SavedObjectsClientCommon; @@ -173,7 +167,7 @@ export class DataViewsService { * Get list of index pattern ids with titles * @param refresh Force refresh of index pattern list */ - getIdsWithTitle = async (refresh: boolean = false): Promise => { + getIdsWithTitle = async (refresh: boolean = false): Promise => { if (!this.savedObjectsCache || refresh) { await this.refreshSavedObjectsCache(); } diff --git a/src/plugins/data_views/common/fields/types.ts b/src/plugins/data_views/common/fields/types.ts index 2bd1cf5834548..b68f5db4f2cdc 100644 --- a/src/plugins/data_views/common/fields/types.ts +++ b/src/plugins/data_views/common/fields/types.ts @@ -10,7 +10,7 @@ import { FieldSpec, DataView } from '..'; /** * @deprecated Use {@link IndexPatternField} - * @removeBy 8.1 + * @removeBy 8.2 */ export interface IFieldType extends DataViewFieldBase { count?: number; diff --git a/src/plugins/data_views/common/index.ts b/src/plugins/data_views/common/index.ts index 7253091e8115b..4de8e98acef39 100644 --- a/src/plugins/data_views/common/index.ts +++ b/src/plugins/data_views/common/index.ts @@ -54,10 +54,10 @@ export type { IndexPatternSpec, SourceFilter, } from './types'; -export { DataViewType, IndexPatternType } from './types'; +export { DataViewType } from './types'; export type { IndexPatternsContract, DataViewsContract } from './data_views'; export { IndexPatternsService, DataViewsService } from './data_views'; -export type { IndexPatternListItem, DataViewListItem, TimeBasedDataView } from './data_views'; +export type { DataViewListItem, TimeBasedDataView } from './data_views'; export { IndexPattern, DataView } from './data_views'; export { DuplicateDataViewError, diff --git a/src/plugins/data_views/public/index.ts b/src/plugins/data_views/public/index.ts index 9cb07d4f3c54f..dd365a303c295 100644 --- a/src/plugins/data_views/public/index.ts +++ b/src/plugins/data_views/public/index.ts @@ -16,7 +16,13 @@ export { export { onRedirectNoIndexPattern } from './data_views'; export type { IIndexPatternFieldList, TypeMeta } from '../common'; -export { IndexPatternField, DataViewField, DataViewType, META_FIELDS } from '../common'; +export { + IndexPatternField, + DataViewField, + DataViewType, + META_FIELDS, + DataViewSpec, +} from '../common'; export type { IndexPatternsContract } from './data_views'; export type { DataViewListItem } from './data_views'; diff --git a/src/plugins/data_views/server/deprecations/scripted_fields.ts b/src/plugins/data_views/server/deprecations/scripted_fields.ts index 684115a19299a..0d668466ff099 100644 --- a/src/plugins/data_views/server/deprecations/scripted_fields.ts +++ b/src/plugins/data_views/server/deprecations/scripted_fields.ts @@ -13,9 +13,9 @@ import { RegisterDeprecationsConfig, } from 'kibana/server'; import { i18n } from '@kbn/i18n'; -import { IndexPatternAttributes } from '../../common'; +import { DataViewAttributes } from '../../common'; -type IndexPatternAttributesWithFields = Pick; +type IndexPatternAttributesWithFields = Pick; export const createScriptedFieldsDeprecationsConfig: ( core: CoreSetup diff --git a/src/plugins/data_views/server/utils.ts b/src/plugins/data_views/server/utils.ts index bb7d23f832233..a3b6aeb5e8c26 100644 --- a/src/plugins/data_views/server/utils.ts +++ b/src/plugins/data_views/server/utils.ts @@ -10,13 +10,13 @@ import { SavedObjectsClientContract } from 'kibana/server'; import { IFieldType, DATA_VIEW_SAVED_OBJECT_TYPE, - IndexPatternAttributes, + DataViewAttributes, SavedObject, } from '../common'; export const getFieldByName = ( fieldName: string, - indexPattern: SavedObject + indexPattern: SavedObject ): IFieldType | undefined => { const fields: IFieldType[] = indexPattern && JSON.parse(indexPattern.attributes.fields); const field = fields && fields.find((f) => f.name === fieldName); @@ -27,8 +27,8 @@ export const getFieldByName = ( export const findIndexPatternById = async ( savedObjectsClient: SavedObjectsClientContract, index: string -): Promise | undefined> => { - const savedObjectsResponse = await savedObjectsClient.find({ +): Promise | undefined> => { + const savedObjectsResponse = await savedObjectsClient.find({ type: DATA_VIEW_SAVED_OBJECT_TYPE, fields: ['fields'], search: `"${index}"`, From 6fd707911c49e7755a891afb3d483eeb6b14b3a7 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 28 Jan 2022 15:29:47 -0600 Subject: [PATCH 2/3] lint fixes --- packages/kbn-optimizer/limits.yml | 2 +- src/plugins/data_view_editor/public/shared_imports.ts | 3 ++- src/plugins/data_views/public/index.ts | 9 ++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 5ad540f982d61..3e5b2c77d1839 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -112,7 +112,7 @@ pageLoadAssetSize: uiActionsEnhanced: 38494 urlDrilldown: 30063 dataViewEditor: 12000 - dataViewFieldEditor: 20000 + dataViewFieldEditor: 27000 dataViewManagement: 5000 reporting: 57003 visTypeHeatmap: 25340 diff --git a/src/plugins/data_view_editor/public/shared_imports.ts b/src/plugins/data_view_editor/public/shared_imports.ts index 82fc33f5834d4..cca695bc9a95e 100644 --- a/src/plugins/data_view_editor/public/shared_imports.ts +++ b/src/plugins/data_view_editor/public/shared_imports.ts @@ -12,7 +12,8 @@ export type { IndexPatternAggRestrictions, } from '../../data/public'; export { IndexPattern, IndexPatternField } from '../../data/public'; -export { DataView, DataViewSpec } from '../../data_views/public'; +export type { DataViewSpec } from '../../data_views/public'; +export { DataView } from '../../data_views/public'; export { createKibanaReactContext, diff --git a/src/plugins/data_views/public/index.ts b/src/plugins/data_views/public/index.ts index dd365a303c295..11b3edaa09628 100644 --- a/src/plugins/data_views/public/index.ts +++ b/src/plugins/data_views/public/index.ts @@ -16,13 +16,8 @@ export { export { onRedirectNoIndexPattern } from './data_views'; export type { IIndexPatternFieldList, TypeMeta } from '../common'; -export { - IndexPatternField, - DataViewField, - DataViewType, - META_FIELDS, - DataViewSpec, -} from '../common'; +export type { DataViewSpec } from '../common'; +export { IndexPatternField, DataViewField, DataViewType, META_FIELDS } from '../common'; export type { IndexPatternsContract } from './data_views'; export type { DataViewListItem } from './data_views'; From 15b6c5eb5369451d46be7858eb8ff057dbfc7942 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sat, 29 Jan 2022 21:29:57 -0600 Subject: [PATCH 3/3] remove iindexpattern usage --- .../scripted_field_table.test.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/data_view_management/public/components/edit_index_pattern/scripted_fields_table/scripted_field_table.test.tsx b/src/plugins/data_view_management/public/components/edit_index_pattern/scripted_fields_table/scripted_field_table.test.tsx index d797da7221575..aa74ae8c78fae 100644 --- a/src/plugins/data_view_management/public/components/edit_index_pattern/scripted_fields_table/scripted_field_table.test.tsx +++ b/src/plugins/data_view_management/public/components/edit_index_pattern/scripted_fields_table/scripted_field_table.test.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { shallow, ShallowWrapper } from 'enzyme'; import { ScriptedFieldsTable } from '../scripted_fields_table'; -import { IIndexPattern, IndexPattern } from '../../../../../../plugins/data/common'; +import { DataView } from '../../../../../../plugins/data_views/public'; jest.mock('@elastic/eui', () => ({ EuiTitle: 'eui-title', @@ -40,10 +40,10 @@ const helpers = { getRouteHref: () => '#', }; -const getIndexPatternMock = (mockedFields: any = {}) => ({ ...mockedFields } as IIndexPattern); +const getIndexPatternMock = (mockedFields: any = {}) => ({ ...mockedFields } as DataView); describe('ScriptedFieldsTable', () => { - let indexPattern: IndexPattern; + let indexPattern: DataView; beforeEach(() => { indexPattern = getIndexPatternMock({ @@ -56,7 +56,7 @@ describe('ScriptedFieldsTable', () => { script: 'z++', }, ], - }) as IndexPattern; + }) as DataView; }); test('should render normally', async () => { @@ -112,7 +112,7 @@ describe('ScriptedFieldsTable', () => { { isUserEditable: true, name: 'JustATest', lang: 'painless', script: 'z++' }, { isUserEditable: true, name: 'Bad', lang: 'somethingElse', script: 'z++' }, ], - }) as IndexPattern + }) as DataView } painlessDocLink={'painlessDoc'} helpers={helpers} @@ -137,7 +137,7 @@ describe('ScriptedFieldsTable', () => { indexPattern={ getIndexPatternMock({ getScriptedFields: () => [], - }) as IndexPattern + }) as DataView } painlessDocLink={'painlessDoc'} helpers={helpers} @@ -184,7 +184,7 @@ describe('ScriptedFieldsTable', () => { { ...indexPattern, removeScriptedField, - } as unknown as IndexPattern + } as unknown as DataView } helpers={helpers} painlessDocLink={'painlessDoc'}