diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.expandshorthand.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.expandshorthand.md new file mode 100644 index 00000000000000..71835e6d28763c --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.expandshorthand.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [expandShorthand](./kibana-plugin-plugins-data-public.expandshorthand.md) + +## expandShorthand variable + + +Signature: + +```typescript +expandShorthand: (sh: Record) => Record +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec._deserialize.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec._deserialize.md new file mode 100644 index 00000000000000..3e8b0abec529ce --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec._deserialize.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) > [\_deserialize](./kibana-plugin-plugins-data-public.fieldmappingspec._deserialize.md) + +## FieldMappingSpec.\_deserialize property + +Signature: + +```typescript +_deserialize?: (mapping: string) => any | undefined; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec._serialize.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec._serialize.md new file mode 100644 index 00000000000000..d0aaf7ddd0c172 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec._serialize.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) > [\_serialize](./kibana-plugin-plugins-data-public.fieldmappingspec._serialize.md) + +## FieldMappingSpec.\_serialize property + +Signature: + +```typescript +_serialize?: (mapping: any) => string | undefined; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec.md new file mode 100644 index 00000000000000..38ebe60df99a12 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) + +## FieldMappingSpec interface + + +Signature: + +```typescript +export interface FieldMappingSpec +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [\_deserialize](./kibana-plugin-plugins-data-public.fieldmappingspec._deserialize.md) | (mapping: string) => any | undefined | | +| [\_serialize](./kibana-plugin-plugins-data-public.fieldmappingspec._serialize.md) | (mapping: any) => string | undefined | | +| [type](./kibana-plugin-plugins-data-public.fieldmappingspec.type.md) | ES_FIELD_TYPES | | + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec.type.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec.type.md new file mode 100644 index 00000000000000..73cff623dc7f26 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldmappingspec.type.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) > [type](./kibana-plugin-plugins-data-public.fieldmappingspec.type.md) + +## FieldMappingSpec.type property + +Signature: + +```typescript +type: ES_FIELD_TYPES; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md index 60302286cbd728..880acdc8956d49 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md @@ -7,5 +7,5 @@ Signature: ```typescript -getIndexPatternFieldListCreator: ({ fieldFormats, toastNotifications, }: FieldListDependencies) => CreateIndexPatternFieldList +getIndexPatternFieldListCreator: ({ fieldFormats, onNotification, }: FieldListDependencies) => CreateIndexPatternFieldList ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md index 6256709e2ee368..b81a23f853e1cd 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md @@ -9,7 +9,7 @@ Constructs a new instance of the `IndexPattern` class Signature: ```typescript -constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: PatternCache); +constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: PatternCache, fieldFormats: FieldFormatsStartCommon, onNotification: OnNotification, onError: OnError, onUnsupportedTimePattern: OnUnsupportedTimePattern); ``` ## Parameters @@ -21,4 +21,8 @@ constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObj | savedObjectsClient | SavedObjectsClientContract | | | apiClient | IIndexPatternsApiClient | | | patternCache | PatternCache | | +| fieldFormats | FieldFormatsStartCommon | | +| onNotification | OnNotification | | +| onError | OnError | | +| onUnsupportedTimePattern | OnUnsupportedTimePattern | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md index 589069e63e7c98..d43082c79970e9 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md @@ -14,7 +14,7 @@ export declare class IndexPattern implements IIndexPattern | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(id, getConfig, savedObjectsClient, apiClient, patternCache)](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the IndexPattern class | +| [(constructor)(id, getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, onUnsupportedTimePattern)](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the IndexPattern class | ## Properties diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md index 8ee9acc684fb1c..e1e0d58ce38c10 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md @@ -9,15 +9,15 @@ Constructs a new instance of the `Field` class Signature: ```typescript -constructor(indexPattern: IndexPattern, spec: FieldSpec | Field, shortDotsEnable: boolean, { fieldFormats, toastNotifications }: FieldDependencies); +constructor(indexPattern: IIndexPattern, spec: FieldSpec | Field, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies); ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| indexPattern | IndexPattern | | +| indexPattern | IIndexPattern | | | spec | FieldSpec | Field | | | shortDotsEnable | boolean | | -| { fieldFormats, toastNotifications } | FieldDependencies | | +| { fieldFormats, onNotification } | FieldDependencies | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md index d1a1ee0905c6e3..4acaaa8c0dc2cc 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md @@ -7,5 +7,5 @@ Signature: ```typescript -indexPattern?: IndexPattern; +indexPattern?: IIndexPattern; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md index 1d3cfa9305c188..8fa1ee0d72e54d 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md @@ -14,7 +14,7 @@ export declare class Field implements IFieldType | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(indexPattern, spec, shortDotsEnable, { fieldFormats, toastNotifications })](./kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md) | | Constructs a new instance of the Field class | +| [(constructor)(indexPattern, spec, shortDotsEnable, { fieldFormats, onNotification })](./kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md) | | Constructs a new instance of the Field class | ## Properties @@ -28,7 +28,7 @@ export declare class Field implements IFieldType | [esTypes](./kibana-plugin-plugins-data-public.indexpatternfield.estypes.md) | | string[] | | | [filterable](./kibana-plugin-plugins-data-public.indexpatternfield.filterable.md) | | boolean | | | [format](./kibana-plugin-plugins-data-public.indexpatternfield.format.md) | | any | | -| [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) | | IndexPattern | | +| [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) | | IIndexPattern | | | [lang](./kibana-plugin-plugins-data-public.indexpatternfield.lang.md) | | string | | | [name](./kibana-plugin-plugins-data-public.indexpatternfield.name.md) | | string | | | [readFromDocValues](./kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md) | | boolean | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.mappingobject.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.mappingobject.md new file mode 100644 index 00000000000000..b1f33c8e8546d4 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.mappingobject.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [MappingObject](./kibana-plugin-plugins-data-public.mappingobject.md) + +## MappingObject type + + +Signature: + +```typescript +export declare type MappingObject = Record; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index bc1eb9100e85cf..f62479f02926e5 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -54,6 +54,7 @@ | [EsQueryConfig](./kibana-plugin-plugins-data-public.esqueryconfig.md) | | | [FetchOptions](./kibana-plugin-plugins-data-public.fetchoptions.md) | | | [FieldFormatConfig](./kibana-plugin-plugins-data-public.fieldformatconfig.md) | | +| [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) | | | [Filter](./kibana-plugin-plugins-data-public.filter.md) | | | [IDataPluginServices](./kibana-plugin-plugins-data-public.idatapluginservices.md) | | | [IEsSearchRequest](./kibana-plugin-plugins-data-public.iessearchrequest.md) | | @@ -101,6 +102,7 @@ | [esFilters](./kibana-plugin-plugins-data-public.esfilters.md) | | | [esKuery](./kibana-plugin-plugins-data-public.eskuery.md) | | | [esQuery](./kibana-plugin-plugins-data-public.esquery.md) | | +| [expandShorthand](./kibana-plugin-plugins-data-public.expandshorthand.md) | | | [extractSearchSourceReferences](./kibana-plugin-plugins-data-public.extractsearchsourcereferences.md) | | | [fieldFormats](./kibana-plugin-plugins-data-public.fieldformats.md) | | | [FilterBar](./kibana-plugin-plugins-data-public.filterbar.md) | | @@ -141,6 +143,7 @@ | [ISearch](./kibana-plugin-plugins-data-public.isearch.md) | | | [ISearchGeneric](./kibana-plugin-plugins-data-public.isearchgeneric.md) | | | [ISearchSource](./kibana-plugin-plugins-data-public.isearchsource.md) | \* | +| [MappingObject](./kibana-plugin-plugins-data-public.mappingobject.md) | | | [MatchAllFilter](./kibana-plugin-plugins-data-public.matchallfilter.md) | | | [ParsedInterval](./kibana-plugin-plugins-data-public.parsedinterval.md) | | | [PhraseFilter](./kibana-plugin-plugins-data-public.phrasefilter.md) | | diff --git a/src/plugins/data/common/field_formats/index.ts b/src/plugins/data/common/field_formats/index.ts index b64e115fd55ff2..5c67073c07dd54 100644 --- a/src/plugins/data/common/field_formats/index.ts +++ b/src/plugins/data/common/field_formats/index.ts @@ -54,4 +54,5 @@ export { // Used in data plugin only FieldFormatInstanceType, IFieldFormat, + FieldFormatsStartCommon, } from './types'; diff --git a/src/plugins/data/common/field_formats/types.ts b/src/plugins/data/common/field_formats/types.ts index 5f11c7fe094bcd..6f773378de08d2 100644 --- a/src/plugins/data/common/field_formats/types.ts +++ b/src/plugins/data/common/field_formats/types.ts @@ -17,6 +17,7 @@ * under the License. */ import { FieldFormat } from './field_format'; +import { FieldFormatsRegistry } from './field_formats_registry'; /** @public **/ export type FieldFormatsContentType = 'html' | 'text'; @@ -99,3 +100,5 @@ export interface IFieldFormatMetaParams { basePath?: string; }; } + +export type FieldFormatsStartCommon = Omit; diff --git a/src/plugins/kibana_utils/public/field_mapping/index.ts b/src/plugins/data/common/field_mapping/index.ts similarity index 100% rename from src/plugins/kibana_utils/public/field_mapping/index.ts rename to src/plugins/data/common/field_mapping/index.ts diff --git a/src/plugins/kibana_utils/public/field_mapping/mapping_setup.test.ts b/src/plugins/data/common/field_mapping/mapping_setup.test.ts similarity index 97% rename from src/plugins/kibana_utils/public/field_mapping/mapping_setup.test.ts rename to src/plugins/data/common/field_mapping/mapping_setup.test.ts index ca40685db0ebf1..e57699e879a878 100644 --- a/src/plugins/kibana_utils/public/field_mapping/mapping_setup.test.ts +++ b/src/plugins/data/common/field_mapping/mapping_setup.test.ts @@ -18,7 +18,7 @@ */ import { expandShorthand } from './mapping_setup'; -import { ES_FIELD_TYPES } from '../../../data/public'; +import { ES_FIELD_TYPES } from '../../../data/common'; describe('mapping_setup', () => { it('allows shortcuts for field types by just setting the value to the type name', () => { diff --git a/src/plugins/kibana_utils/public/field_mapping/mapping_setup.ts b/src/plugins/data/common/field_mapping/mapping_setup.ts similarity index 100% rename from src/plugins/kibana_utils/public/field_mapping/mapping_setup.ts rename to src/plugins/data/common/field_mapping/mapping_setup.ts diff --git a/src/plugins/kibana_utils/public/field_mapping/types.ts b/src/plugins/data/common/field_mapping/types.ts similarity index 95% rename from src/plugins/kibana_utils/public/field_mapping/types.ts rename to src/plugins/data/common/field_mapping/types.ts index f3fb9b000e45a5..973a58d3baec4e 100644 --- a/src/plugins/kibana_utils/public/field_mapping/types.ts +++ b/src/plugins/data/common/field_mapping/types.ts @@ -17,7 +17,7 @@ * under the License. */ -import { ES_FIELD_TYPES } from '../../../data/public'; +import { ES_FIELD_TYPES } from '../../../data/common'; /** @public */ export interface FieldMappingSpec { diff --git a/src/plugins/data/common/index.ts b/src/plugins/data/common/index.ts index e4a663a1599f12..adbd93d518fc7d 100644 --- a/src/plugins/data/common/index.ts +++ b/src/plugins/data/common/index.ts @@ -27,3 +27,4 @@ export * from './search'; export * from './search/aggs'; export * from './types'; export * from './utils'; +export * from './field_mapping'; diff --git a/src/plugins/data/public/index_patterns/fields/__snapshots__/field.test.ts.snap b/src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap similarity index 100% rename from src/plugins/data/public/index_patterns/fields/__snapshots__/field.test.ts.snap rename to src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap diff --git a/src/plugins/data/public/index_patterns/fields/field.test.ts b/src/plugins/data/common/index_patterns/fields/field.test.ts similarity index 94% rename from src/plugins/data/public/index_patterns/fields/field.test.ts rename to src/plugins/data/common/index_patterns/fields/field.test.ts index 18252b159d98d6..711c176fed9ccb 100644 --- a/src/plugins/data/public/index_patterns/fields/field.test.ts +++ b/src/plugins/data/common/index_patterns/fields/field.test.ts @@ -18,9 +18,8 @@ */ import { Field } from './field'; -import { IndexPattern } from '..'; -import { notificationServiceMock } from '../../../../../core/public/mocks'; -import { FieldFormatsStart } from '../../field_formats'; +import { IndexPattern } from '../index_patterns'; +import { FieldFormatsStartCommon } from '../..'; import { KBN_FIELD_TYPES } from '../../../common'; describe('Field', function () { @@ -34,8 +33,8 @@ describe('Field', function () { { ...fieldValues, ...values }, false, { - fieldFormats: {} as FieldFormatsStart, - toastNotifications: notificationServiceMock.createStartContract().toasts, + fieldFormats: {} as FieldFormatsStartCommon, + onNotification: () => {}, } ); } @@ -215,8 +214,8 @@ describe('Field', function () { it('exports the property to JSON', () => { const field = new Field({ fieldFormatMap: { name: {} } } as IndexPattern, fieldValues, false, { - fieldFormats: {} as FieldFormatsStart, - toastNotifications: notificationServiceMock.createStartContract().toasts, + fieldFormats: {} as FieldFormatsStartCommon, + onNotification: () => {}, }); expect(flatten(field)).toMatchSnapshot(); }); diff --git a/src/plugins/data/public/index_patterns/fields/field.ts b/src/plugins/data/common/index_patterns/fields/field.ts similarity index 89% rename from src/plugins/data/public/index_patterns/fields/field.ts rename to src/plugins/data/common/index_patterns/fields/field.ts index 625df17d62e0dc..c53e3f2b1f621f 100644 --- a/src/plugins/data/public/index_patterns/fields/field.ts +++ b/src/plugins/data/common/index_patterns/fields/field.ts @@ -18,10 +18,9 @@ */ import { i18n } from '@kbn/i18n'; -import { ToastsStart } from 'kibana/public'; // @ts-ignore import { ObjDefine } from './obj_define'; -import { IndexPattern } from '../index_patterns'; +import { IIndexPattern } from '../../types'; import { IFieldType, getKbnFieldType, @@ -29,13 +28,14 @@ import { FieldFormat, shortenDottedString, } from '../../../common'; -import { FieldFormatsStart } from '../../field_formats'; +import { OnNotification } from '../types'; +import { FieldFormatsStartCommon } from '../../field_formats'; export type FieldSpec = Record; interface FieldDependencies { - fieldFormats: FieldFormatsStart; - toastNotifications: ToastsStart; + fieldFormats: FieldFormatsStartCommon; + onNotification: OnNotification; } export class Field implements IFieldType { @@ -55,17 +55,17 @@ export class Field implements IFieldType { scripted?: boolean; subType?: IFieldSubType; displayName?: string; - indexPattern?: IndexPattern; + indexPattern?: IIndexPattern; readFromDocValues?: boolean; format: any; $$spec: FieldSpec; conflictDescriptions?: Record; constructor( - indexPattern: IndexPattern, + indexPattern: IIndexPattern, spec: FieldSpec | Field, shortDotsEnable: boolean, - { fieldFormats, toastNotifications }: FieldDependencies + { fieldFormats, onNotification }: FieldDependencies ) { // unwrap old instances of Field if (spec instanceof Field) spec = spec.$$spec; @@ -90,11 +90,7 @@ export class Field implements IFieldType { values: { name: spec.name, title: indexPattern.title }, defaultMessage: 'Field {name} in indexPattern {title} is using an unknown field type.', }); - - toastNotifications.addDanger({ - title, - text, - }); + onNotification({ title, text, color: 'danger', iconType: 'alert' }); } if (!type) type = getKbnFieldType('unknown'); @@ -103,7 +99,7 @@ export class Field implements IFieldType { if (!FieldFormat.isInstanceOfFieldFormat(format)) { format = - indexPattern.fieldFormatMap[spec.name] || + (indexPattern.fieldFormatMap && indexPattern.fieldFormatMap[spec.name]) || fieldFormats.getDefaultInstance(spec.type, spec.esTypes); } diff --git a/src/plugins/data/public/index_patterns/fields/field_list.ts b/src/plugins/data/common/index_patterns/fields/field_list.ts similarity index 87% rename from src/plugins/data/public/index_patterns/fields/field_list.ts rename to src/plugins/data/common/index_patterns/fields/field_list.ts index 1aef0b1ccadaa0..173a629863a716 100644 --- a/src/plugins/data/public/index_patterns/fields/field_list.ts +++ b/src/plugins/data/common/index_patterns/fields/field_list.ts @@ -18,17 +18,17 @@ */ import { findIndex } from 'lodash'; -import { ToastsStart } from 'kibana/public'; -import { IndexPattern } from '../index_patterns'; +import { IIndexPattern } from '../../types'; import { IFieldType } from '../../../common'; import { Field, FieldSpec } from './field'; -import { FieldFormatsStart } from '../../field_formats'; +import { OnNotification } from '../types'; +import { FieldFormatsStartCommon } from '../../field_formats'; type FieldMap = Map; interface FieldListDependencies { - fieldFormats: FieldFormatsStart; - toastNotifications: ToastsStart; + fieldFormats: FieldFormatsStartCommon; + onNotification: OnNotification; } export interface IIndexPatternFieldList extends Array { @@ -40,19 +40,19 @@ export interface IIndexPatternFieldList extends Array { } export type CreateIndexPatternFieldList = ( - indexPattern: IndexPattern, + indexPattern: IIndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean ) => IIndexPatternFieldList; export const getIndexPatternFieldListCreator = ({ fieldFormats, - toastNotifications, + onNotification, }: FieldListDependencies): CreateIndexPatternFieldList => (...fieldListParams) => { class FieldList extends Array implements IIndexPatternFieldList { private byName: FieldMap = new Map(); private groups: Map = new Map(); - private indexPattern: IndexPattern; + private indexPattern: IIndexPattern; private shortDotsEnable: boolean; private setByName = (field: Field) => this.byName.set(field.name, field); private setByGroup = (field: Field) => { @@ -63,7 +63,7 @@ export const getIndexPatternFieldListCreator = ({ }; private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name); - constructor(indexPattern: IndexPattern, specs: FieldSpec[] = [], shortDotsEnable = false) { + constructor(indexPattern: IIndexPattern, specs: FieldSpec[] = [], shortDotsEnable = false) { super(); this.indexPattern = indexPattern; this.shortDotsEnable = shortDotsEnable; @@ -76,7 +76,7 @@ export const getIndexPatternFieldListCreator = ({ add = (field: FieldSpec) => { const newField = new Field(this.indexPattern, field, this.shortDotsEnable, { fieldFormats, - toastNotifications, + onNotification, }); this.push(newField); this.setByName(newField); @@ -94,7 +94,7 @@ export const getIndexPatternFieldListCreator = ({ update = (field: FieldSpec) => { const newField = new Field(this.indexPattern, field, this.shortDotsEnable, { fieldFormats, - toastNotifications, + onNotification, }); const index = this.findIndex((f) => f.name === newField.name); this.splice(index, 1, newField); diff --git a/src/plugins/data/common/index_patterns/fields/index.ts b/src/plugins/data/common/index_patterns/fields/index.ts index 5b6fef3e51fa9b..1b7c87d556f592 100644 --- a/src/plugins/data/common/index_patterns/fields/index.ts +++ b/src/plugins/data/common/index_patterns/fields/index.ts @@ -19,3 +19,5 @@ export * from './types'; export { isFilterable, isNestedField } from './utils'; +export * from './field_list'; +export * from './field'; diff --git a/src/plugins/data/public/index_patterns/fields/obj_define.js b/src/plugins/data/common/index_patterns/fields/obj_define.js similarity index 100% rename from src/plugins/data/public/index_patterns/fields/obj_define.js rename to src/plugins/data/common/index_patterns/fields/obj_define.js diff --git a/src/plugins/data/public/index_patterns/fields/obj_define.test.js b/src/plugins/data/common/index_patterns/fields/obj_define.test.js similarity index 100% rename from src/plugins/data/public/index_patterns/fields/obj_define.test.js rename to src/plugins/data/common/index_patterns/fields/obj_define.test.js diff --git a/src/plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts b/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts similarity index 91% rename from src/plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts rename to src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts index f47cd000b7ba09..775b559b9fec5e 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts @@ -17,8 +17,7 @@ * under the License. */ -import { IndexPattern } from './index_pattern'; -import { GetFieldsOptions, IIndexPatternsApiClient } from './index_patterns_api_client'; +import { GetFieldsOptions, IIndexPatternsApiClient, IndexPattern } from '.'; /** @internal */ export const createFieldsFetcher = ( diff --git a/src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts b/src/plugins/data/common/index_patterns/index_patterns/_pattern_cache.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts rename to src/plugins/data/common/index_patterns/index_patterns/_pattern_cache.ts diff --git a/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts new file mode 100644 index 00000000000000..2737627bf1977b --- /dev/null +++ b/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts @@ -0,0 +1,57 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { contains } from 'lodash'; +import { CoreStart } from 'kibana/public'; +import { IndexPatternsContract } from './index_patterns'; + +export type EnsureDefaultIndexPattern = () => Promise | undefined; + +export const createEnsureDefaultIndexPattern = ( + uiSettings: CoreStart['uiSettings'], + onRedirectNoIndexPattern: () => Promise | void +) => { + /** + * Checks whether a default index pattern is set and exists and defines + * one otherwise. + */ + return async function ensureDefaultIndexPattern(this: IndexPatternsContract) { + const patterns = await this.getIds(); + let defaultId = uiSettings.get('defaultIndex'); + let defined = !!defaultId; + const exists = contains(patterns, defaultId); + + if (defined && !exists) { + uiSettings.remove('defaultIndex'); + defaultId = defined = false; + } + + if (defined) { + return; + } + + // If there is any index pattern created, set the first as default + if (patterns.length >= 1) { + defaultId = patterns[0]; + uiSettings.set('defaultIndex', defaultId); + } else { + return onRedirectNoIndexPattern(); + } + }; +}; diff --git a/src/plugins/data/public/index_patterns/index_patterns/flatten_hit.ts b/src/plugins/data/common/index_patterns/index_patterns/flatten_hit.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/flatten_hit.ts rename to src/plugins/data/common/index_patterns/index_patterns/flatten_hit.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/format_hit.ts b/src/plugins/data/common/index_patterns/index_patterns/format_hit.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/format_hit.ts rename to src/plugins/data/common/index_patterns/index_patterns/format_hit.ts diff --git a/src/plugins/data/public/index_patterns/fields/index.ts b/src/plugins/data/common/index_patterns/index_patterns/index.ts similarity index 77% rename from src/plugins/data/public/index_patterns/fields/index.ts rename to src/plugins/data/common/index_patterns/index_patterns/index.ts index 1644e23a163a63..5fae08f3bb7755 100644 --- a/src/plugins/data/public/index_patterns/fields/index.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index.ts @@ -17,5 +17,10 @@ * under the License. */ -export * from './field_list'; -export * from './field'; +export * from './index_patterns_api_client'; +export * from './types'; +export * from './_pattern_cache'; +export * from './flatten_hit'; +export * from './format_hit'; +export * from './index_pattern'; +export * from './index_patterns'; diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts similarity index 93% rename from src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts rename to src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts index 84135bb5d1e2bd..c137d86d86d079 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts @@ -19,24 +19,19 @@ import { defaults, pluck, last, get } from 'lodash'; -jest.mock('../../../../kibana_utils/public/history'); import { IndexPattern } from './index_pattern'; -import { DuplicateField } from '../../../../kibana_utils/public'; +import { DuplicateField } from '../../../../kibana_utils/common'; // @ts-ignore import mockLogStashFields from '../../../../../fixtures/logstash_fields'; // @ts-ignore import { stubbedSavedObjectIndexPattern } from '../../../../../fixtures/stubbed_saved_object_index_pattern'; import { Field } from '../fields'; -import { setNotifications, setFieldFormats } from '../../services'; -// Temporary disable eslint, will be removed after moving to new platform folder -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { notificationServiceMock } from '../../../../../core/public/notifications/notifications_service.mock'; -import { FieldFormatsStart } from '../../field_formats'; +import { FieldFormatsStartCommon } from '../../field_formats'; -jest.mock('../../../../kibana_utils/public', () => { - const originalModule = jest.requireActual('../../../../kibana_utils/public'); +jest.mock('../../field_mapping', () => { + const originalModule = jest.requireActual('../../field_mapping'); return { ...originalModule, @@ -107,7 +102,11 @@ function create(id: string, payload?: any): Promise { (cfg: any) => config.get(cfg), savedObjectsClient as any, apiClient, - patternCache + patternCache, + ({ getDefaultInstance: () => {}, getType: () => {} } as unknown) as FieldFormatsStartCommon, + () => {}, + () => {}, + () => {} ); setDocsourcePayload(id, payload); @@ -121,18 +120,11 @@ function setDocsourcePayload(id: string | null, providedPayload: any) { describe('IndexPattern', () => { const indexPatternId = 'test-pattern'; - const notifications = notificationServiceMock.createStartContract(); let indexPattern: IndexPattern; // create an indexPattern instance for each test beforeEach(() => { - setNotifications(notifications); - setFieldFormats(({ - getDefaultInstance: jest.fn(), - deserialize: jest.fn() as any, - } as unknown) as FieldFormatsStart); - return create(indexPatternId).then((pattern: IndexPattern) => { indexPattern = pattern; }); @@ -377,7 +369,11 @@ describe('IndexPattern', () => { (cfg: any) => config.get(cfg), savedObjectsClient as any, apiClient, - patternCache + patternCache, + ({ getDefaultInstance: () => {}, getType: () => {} } as unknown) as FieldFormatsStartCommon, + () => {}, + () => {}, + () => {} ); await pattern.init(); @@ -389,7 +385,11 @@ describe('IndexPattern', () => { (cfg: any) => config.get(cfg), savedObjectsClient as any, apiClient, - patternCache + patternCache, + ({ getDefaultInstance: () => {}, getType: () => {} } as unknown) as FieldFormatsStartCommon, + () => {}, + () => {}, + () => {} ); await samePattern.init(); diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts similarity index 84% rename from src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx rename to src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index 2dc9330b1a4612..572d1d70356cab 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -19,19 +19,9 @@ import _, { each, reject } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { FormattedMessage } from '@kbn/i18n/react'; -import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; -import React from 'react'; import { SavedObjectsClientContract } from 'src/core/public'; -import { - DuplicateField, - SavedObjectNotFound, - expandShorthand, - FieldMappingSpec, - MappingObject, -} from '../../../../kibana_utils/public'; -import { toMountPoint } from '../../../../kibana_react/public'; +import { DuplicateField, SavedObjectNotFound } from '../../../../kibana_utils/common'; import { ES_FIELD_TYPES, @@ -46,10 +36,12 @@ import { Field, IIndexPatternFieldList, getIndexPatternFieldListCreator } from ' import { createFieldsFetcher } from './_fields_fetcher'; import { formatHitProvider } from './format_hit'; import { flattenHitWrapper } from './flatten_hit'; -import { IIndexPatternsApiClient } from './index_patterns_api_client'; -import { getNotifications, getFieldFormats, getHttp } from '../../services'; -import { TypeMeta } from './types'; +import { IIndexPatternsApiClient } from '.'; +import { TypeMeta } from '.'; +import { OnNotification, OnError, OnUnsupportedTimePattern } from '../types'; +import { FieldFormatsStartCommon } from '../../field_formats'; import { PatternCache } from './_pattern_cache'; +import { expandShorthand, FieldMappingSpec, MappingObject } from '../../field_mapping'; const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; const type = 'index-pattern'; @@ -78,6 +70,10 @@ export class IndexPattern implements IIndexPattern { private originalBody: { [key: string]: any } = {}; public fieldsFetcher: any; // probably want to factor out any direct usage and change to private private shortDotsEnable: boolean = false; + private fieldFormats: FieldFormatsStartCommon; + private onNotification: OnNotification; + private onError: OnError; + private onUnsupportedTimePattern: OnUnsupportedTimePattern; private apiClient: IIndexPatternsApiClient; private mapping: MappingObject = expandShorthand({ @@ -107,7 +103,11 @@ export class IndexPattern implements IIndexPattern { getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, - patternCache: PatternCache + patternCache: PatternCache, + fieldFormats: FieldFormatsStartCommon, + onNotification: OnNotification, + onError: OnError, + onUnsupportedTimePattern: OnUnsupportedTimePattern ) { this.id = id; this.savedObjectsClient = savedObjectsClient; @@ -115,13 +115,17 @@ export class IndexPattern implements IIndexPattern { // instead of storing config we rather store the getter only as np uiSettingsClient has circular references // which cause problems when being consumed from angular this.getConfig = getConfig; + this.fieldFormats = fieldFormats; + this.onNotification = onNotification; + this.onError = onError; + this.onUnsupportedTimePattern = onUnsupportedTimePattern; this.shortDotsEnable = this.getConfig(UI_SETTINGS.SHORT_DOTS_ENABLE); this.metaFields = this.getConfig(UI_SETTINGS.META_FIELDS); this.createFieldList = getIndexPatternFieldListCreator({ - fieldFormats: getFieldFormats(), - toastNotifications: getNotifications().toasts, + fieldFormats, + onNotification, }); this.fields = this.createFieldList(this, [], this.shortDotsEnable); @@ -134,7 +138,7 @@ export class IndexPattern implements IIndexPattern { this.flattenHit = flattenHitWrapper(this, this.getConfig(UI_SETTINGS.META_FIELDS)); this.formatHit = formatHitProvider( this, - getFieldFormats().getDefaultInstance(KBN_FIELD_TYPES.STRING) + fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.STRING) ); this.formatField = this.formatHit.formatField; } @@ -146,7 +150,7 @@ export class IndexPattern implements IIndexPattern { } private deserializeFieldFormatMap(mapping: any) { - const FieldFormat = getFieldFormats().getType(mapping.id); + const FieldFormat = this.fieldFormats.getType(mapping.id); return FieldFormat && new FieldFormat(mapping.params, this.getConfig); } @@ -206,48 +210,10 @@ export class IndexPattern implements IIndexPattern { } if (this.isUnsupportedTimePattern()) { - const warningTitle = i18n.translate('data.indexPatterns.warningTitle', { - defaultMessage: 'Support for time interval index patterns removed', - }); - - const warningText = i18n.translate('data.indexPatterns.warningText', { - defaultMessage: - 'Currently querying all indices matching {index}. {title} should be migrated to a wildcard-based index pattern.', - values: { - title: this.title, - index: this.getIndex(), - }, - }); - - // kbnUrl was added to this service in #35262 before it was de-angularized, and merged in a PR - // directly against the 7.x branch. Index patterns were de-angularized in #39247, and in order - // to preserve the functionality from #35262 we need to get the injector here just for kbnUrl. - // This has all been removed as of 8.0. - - // 2019-12-01 The usage of kbnUrl had to be removed due to the transition to NP. - // It's now temporarily replaced by a simple replace of the single argument used by all URLs. - // Once kbnUrl is migrated to NP, this can be updated. - const editUrl = `/app/kibana#/management/kibana/index_patterns/${this.id! || ''}`; - - const { toasts } = getNotifications(); - - toasts.addWarning({ - title: warningTitle, - text: toMountPoint( -
-

{warningText}

- - - - - - - -
- ), + this.onUnsupportedTimePattern({ + id: this.id as string, + title: this.title, + index: this.getIndex(), }); } @@ -361,8 +327,8 @@ export class IndexPattern implements IIndexPattern { }, false, { - fieldFormats: getFieldFormats(), - toastNotifications: getNotifications().toasts, + fieldFormats: this.fieldFormats, + onNotification: this.onNotification, } ) ); @@ -488,8 +454,13 @@ export class IndexPattern implements IIndexPattern { this.getConfig, this.savedObjectsClient, this.apiClient, - this.patternCache + this.patternCache, + this.fieldFormats, + this.onNotification, + this.onError, + this.onUnsupportedTimePattern ); + await duplicatePattern.destroy(); } @@ -537,7 +508,11 @@ export class IndexPattern implements IIndexPattern { this.getConfig, this.savedObjectsClient, this.apiClient, - this.patternCache + this.patternCache, + this.fieldFormats, + this.onNotification, + this.onError, + this.onUnsupportedTimePattern ); return samePattern.init().then(() => { // What keys changed from now and what the server returned @@ -562,14 +537,12 @@ export class IndexPattern implements IIndexPattern { } if (unresolvedCollision) { - const message = i18n.translate('data.indexPatterns.unableWriteLabel', { + const title = i18n.translate('data.indexPatterns.unableWriteLabel', { defaultMessage: 'Unable to write index pattern! Refresh the page to get the most up to date changes for this index pattern.', }); - const { toasts } = getNotifications(); - - toasts.addDanger(message); + this.onNotification({ title, color: 'danger' }); throw err; } @@ -607,15 +580,13 @@ export class IndexPattern implements IIndexPattern { // we still want to notify the user that there is a problem // but we do not want to potentially make any pages unusable // so do not rethrow the error here - const { toasts } = getNotifications(); if (err instanceof IndexPatternMissingIndices) { - toasts.addDanger((err as any).message); - + this.onNotification({ title: (err as any).message, color: 'danger', iconType: 'alert' }); return []; } - toasts.addError(err, { + this.onError(err, { title: i18n.translate('data.indexPatterns.fetchFieldErrorTitle', { defaultMessage: 'Error fetching fields for index pattern {title} (ID: {id})', values: { diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts similarity index 90% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts rename to src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts index fc0be270e9c506..c6d48569a347f7 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts @@ -21,11 +21,11 @@ import { IndexPatternsService } from './index_patterns'; import { SavedObjectsClientContract, SavedObjectsFindResponsePublic } from 'kibana/public'; import { coreMock, httpServiceMock } from '../../../../../core/public/mocks'; -import { fieldFormatsServiceMock } from '../../field_formats/mocks'; +import { fieldFormatsMock } from '../../field_formats/mocks'; const core = coreMock.createStart(); const http = httpServiceMock.createStartContract(); -const fieldFormats = fieldFormatsServiceMock.createStartContract(); +const fieldFormats = fieldFormatsMock; jest.mock('./index_pattern', () => { class IndexPattern { @@ -62,7 +62,16 @@ describe('IndexPatterns', () => { }) as Promise> ); - indexPatterns = new IndexPatternsService(core, savedObjectsClient, http, fieldFormats); + indexPatterns = new IndexPatternsService( + core.uiSettings, + savedObjectsClient, + http, + fieldFormats, + () => {}, + () => {}, + () => {}, + () => {} + ); }); test('does cache gets for the same id', async () => { diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts similarity index 82% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts rename to src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index 32b31d4f2758d5..264be38ecaebe7 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -25,9 +25,9 @@ import { CoreStart, } from 'src/core/public'; -import { createIndexPatternCache } from './_pattern_cache'; +import { createIndexPatternCache } from '.'; import { IndexPattern } from './index_pattern'; -import { IndexPatternsApiClient, GetFieldsOptions } from './index_patterns_api_client'; +import { IndexPatternsApiClient, GetFieldsOptions } from '.'; import { createEnsureDefaultIndexPattern, EnsureDefaultIndexPattern, @@ -38,7 +38,8 @@ import { Field, FieldSpec, } from '../fields'; -import { FieldFormatsStart } from '../../field_formats'; +import { OnNotification, OnError, OnUnsupportedTimePattern } from '../types'; +import { FieldFormatsStartCommon } from '../../field_formats'; const indexPatternCache = createIndexPatternCache(); @@ -53,6 +54,10 @@ export class IndexPatternsService { private savedObjectsClient: SavedObjectsClientContract; private savedObjectsCache?: Array> | null; private apiClient: IndexPatternsApiClient; + private fieldFormats: FieldFormatsStartCommon; + private onNotification: OnNotification; + private onError: OnError; + private onUnsupportedTimePattern: OnUnsupportedTimePattern; ensureDefaultIndexPattern: EnsureDefaultIndexPattern; createFieldList: CreateIndexPatternFieldList; createField: ( @@ -62,23 +67,34 @@ export class IndexPatternsService { ) => Field; constructor( - core: CoreStart, + uiSettings: CoreStart['uiSettings'], savedObjectsClient: SavedObjectsClientContract, http: HttpStart, - fieldFormats: FieldFormatsStart + fieldFormats: FieldFormatsStartCommon, + onNotification: OnNotification, + onError: OnError, + onRedirectNoIndexPattern: () => void, + onUnsupportedTimePattern: OnUnsupportedTimePattern ) { this.apiClient = new IndexPatternsApiClient(http); - this.config = core.uiSettings; + this.config = uiSettings; this.savedObjectsClient = savedObjectsClient; - this.ensureDefaultIndexPattern = createEnsureDefaultIndexPattern(core); + this.fieldFormats = fieldFormats; + this.onNotification = onNotification; + this.onError = onError; + this.onUnsupportedTimePattern = onUnsupportedTimePattern; + this.ensureDefaultIndexPattern = createEnsureDefaultIndexPattern( + uiSettings, + onRedirectNoIndexPattern + ); this.createFieldList = getIndexPatternFieldListCreator({ fieldFormats, - toastNotifications: core.notifications.toasts, + onNotification, }); this.createField = (indexPattern, spec, shortDotsEnable) => { return new Field(indexPattern, spec, shortDotsEnable, { fieldFormats, - toastNotifications: core.notifications.toasts, + onNotification, }); }; } @@ -178,7 +194,11 @@ export class IndexPatternsService { (cfg: any) => this.config.get(cfg), this.savedObjectsClient, this.apiClient, - indexPatternCache + indexPatternCache, + this.fieldFormats, + this.onNotification, + this.onError, + this.onUnsupportedTimePattern ); return indexPattern.init(); diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts rename to src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.test.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts rename to src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.test.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts rename to src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/types.ts b/src/plugins/data/common/index_patterns/index_patterns/types.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/types.ts rename to src/plugins/data/common/index_patterns/index_patterns/types.ts diff --git a/src/plugins/data/public/index_patterns/lib/errors.ts b/src/plugins/data/common/index_patterns/lib/errors.ts similarity index 100% rename from src/plugins/data/public/index_patterns/lib/errors.ts rename to src/plugins/data/common/index_patterns/lib/errors.ts diff --git a/src/plugins/data/public/index_patterns/lib/get_from_saved_object.ts b/src/plugins/data/common/index_patterns/lib/get_from_saved_object.ts similarity index 100% rename from src/plugins/data/public/index_patterns/lib/get_from_saved_object.ts rename to src/plugins/data/common/index_patterns/lib/get_from_saved_object.ts diff --git a/src/plugins/data/public/index_patterns/lib/get_title.ts b/src/plugins/data/common/index_patterns/lib/get_title.ts similarity index 100% rename from src/plugins/data/public/index_patterns/lib/get_title.ts rename to src/plugins/data/common/index_patterns/lib/get_title.ts diff --git a/src/plugins/data/public/index_patterns/lib/index.ts b/src/plugins/data/common/index_patterns/lib/index.ts similarity index 99% rename from src/plugins/data/public/index_patterns/lib/index.ts rename to src/plugins/data/common/index_patterns/lib/index.ts index 2893096c4af9d4..d9eccb6685ded7 100644 --- a/src/plugins/data/public/index_patterns/lib/index.ts +++ b/src/plugins/data/common/index_patterns/lib/index.ts @@ -17,9 +17,10 @@ * under the License. */ -export { getTitle } from './get_title'; -export * from './types'; -export { validateIndexPattern } from './validate_index_pattern'; export { IndexPatternMissingIndices } from './errors'; +export { getTitle } from './get_title'; export { getFromSavedObject } from './get_from_saved_object'; export { isDefault } from './is_default'; + +export * from './types'; +export { validateIndexPattern } from './validate_index_pattern'; diff --git a/src/plugins/data/public/index_patterns/lib/is_default.ts b/src/plugins/data/common/index_patterns/lib/is_default.ts similarity index 100% rename from src/plugins/data/public/index_patterns/lib/is_default.ts rename to src/plugins/data/common/index_patterns/lib/is_default.ts diff --git a/src/plugins/data/public/index_patterns/lib/types.ts b/src/plugins/data/common/index_patterns/lib/types.ts similarity index 100% rename from src/plugins/data/public/index_patterns/lib/types.ts rename to src/plugins/data/common/index_patterns/lib/types.ts diff --git a/src/plugins/data/public/index_patterns/lib/validate_index_pattern.test.ts b/src/plugins/data/common/index_patterns/lib/validate_index_pattern.test.ts similarity index 100% rename from src/plugins/data/public/index_patterns/lib/validate_index_pattern.test.ts rename to src/plugins/data/common/index_patterns/lib/validate_index_pattern.test.ts diff --git a/src/plugins/data/public/index_patterns/lib/validate_index_pattern.ts b/src/plugins/data/common/index_patterns/lib/validate_index_pattern.ts similarity index 100% rename from src/plugins/data/public/index_patterns/lib/validate_index_pattern.ts rename to src/plugins/data/common/index_patterns/lib/validate_index_pattern.ts diff --git a/src/plugins/data/common/index_patterns/types.ts b/src/plugins/data/common/index_patterns/types.ts index a9e8652a09a5e4..1849db63108430 100644 --- a/src/plugins/data/common/index_patterns/types.ts +++ b/src/plugins/data/common/index_patterns/types.ts @@ -17,6 +17,7 @@ * under the License. */ +import { ToastInputFields, ErrorToastOptions } from 'src/core/public/notifications'; import { IFieldType } from './fields'; export interface IIndexPattern { @@ -48,3 +49,15 @@ export interface IndexPatternAttributes { typeMeta: string; timeFieldName?: string; } + +export type OnNotification = (toastInputFields: ToastInputFields) => void; +export type OnError = (error: Error, toastInputFields: ErrorToastOptions) => void; +export type OnUnsupportedTimePattern = ({ + id, + title, + index, +}: { + id: string; + title: string; + index: string; +}) => void; diff --git a/src/plugins/data/public/index_patterns/utils.ts b/src/plugins/data/common/index_patterns/utils.ts similarity index 100% rename from src/plugins/data/public/index_patterns/utils.ts rename to src/plugins/data/common/index_patterns/utils.ts diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index c80a6684ce56ba..e57b02784ca9e2 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -443,6 +443,8 @@ export { getKbnTypeNames, } from '../common'; +export * from '../common/field_mapping'; + /* * Plugin setup */ diff --git a/src/plugins/data/public/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index.ts index 58c2cae1de0f38..86d1e632b267db 100644 --- a/src/plugins/data/public/index_patterns/index.ts +++ b/src/plugins/data/public/index_patterns/index.ts @@ -25,10 +25,19 @@ export { validateIndexPattern, getFromSavedObject, isDefault, -} from './lib'; -export { flattenHitWrapper, formatHitProvider } from './index_patterns'; +} from '../../common/index_patterns/lib'; +export { + flattenHitWrapper, + formatHitProvider, + onRedirectNoIndexPattern, + onUnsupportedTimePattern, +} from './index_patterns'; -export { getIndexPatternFieldListCreator, Field, IIndexPatternFieldList } from './fields'; +export { + getIndexPatternFieldListCreator, + Field, + IIndexPatternFieldList, +} from '../../common/index_patterns'; // TODO: figure out how to replace IndexPatterns in get_inner_angular. export { diff --git a/src/plugins/data/public/index_patterns/index_patterns/ensure_default_index_pattern.tsx b/src/plugins/data/public/index_patterns/index_patterns/ensure_default_index_pattern.tsx deleted file mode 100644 index 2088bd8c925df9..00000000000000 --- a/src/plugins/data/public/index_patterns/index_patterns/ensure_default_index_pattern.tsx +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { contains } from 'lodash'; -import React from 'react'; -import { History } from 'history'; -import { i18n } from '@kbn/i18n'; -import { EuiCallOut } from '@elastic/eui'; -import { CoreStart } from 'kibana/public'; -import { toMountPoint } from '../../../../kibana_react/public'; -import { IndexPatternsContract } from './index_patterns'; - -export type EnsureDefaultIndexPattern = (history: History) => Promise | undefined; - -export const createEnsureDefaultIndexPattern = (core: CoreStart) => { - let bannerId: string; - let timeoutId: NodeJS.Timeout | undefined; - - /** - * Checks whether a default index pattern is set and exists and defines - * one otherwise. - * - * If there are no index patterns, redirect to management page and show - * banner. In this case the promise returned from this function will never - * resolve to wait for the URL change to happen. - */ - return async function ensureDefaultIndexPattern(this: IndexPatternsContract, history: History) { - const patterns = await this.getIds(); - let defaultId = core.uiSettings.get('defaultIndex'); - let defined = !!defaultId; - const exists = contains(patterns, defaultId); - - if (defined && !exists) { - core.uiSettings.remove('defaultIndex'); - defaultId = defined = false; - } - - if (defined) { - return; - } - - // If there is any index pattern created, set the first as default - if (patterns.length >= 1) { - defaultId = patterns[0]; - core.uiSettings.set('defaultIndex', defaultId); - } else { - const canManageIndexPatterns = core.application.capabilities.management.kibana.index_patterns; - const redirectTarget = canManageIndexPatterns ? '/management/kibana/indexPatterns' : '/home'; - - if (timeoutId) { - clearTimeout(timeoutId); - } - - const bannerMessage = i18n.translate( - 'data.indexPatterns.ensureDefaultIndexPattern.bannerLabel', - { - defaultMessage: - "In order to visualize and explore data in Kibana, you'll need to create an index pattern to retrieve data from Elasticsearch.", - } - ); - - // Avoid being hostile to new users who don't have an index pattern setup yet - // give them a friendly info message instead of a terse error message - bannerId = core.overlays.banners.replace( - bannerId, - toMountPoint() - ); - - // hide the message after the user has had a chance to acknowledge it -- so it doesn't permanently stick around - timeoutId = setTimeout(() => { - core.overlays.banners.remove(bannerId); - timeoutId = undefined; - }, 15000); - - if (redirectTarget === '/home') { - core.application.navigateToApp('home'); - } else { - core.application.navigateToApp('management', { - path: `/kibana/indexPatterns?bannerMessage=${bannerMessage}`, - }); - } - - // return never-resolving promise to stop resolving and wait for the url change - return new Promise(() => {}); - } - }; -}; diff --git a/src/plugins/data/public/index_patterns/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index_patterns/index.ts index fca82025cdc66d..2f9c156c8d6db3 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index.ts @@ -17,9 +17,6 @@ * under the License. */ -export * from './flatten_hit'; -export * from './format_hit'; -export * from './index_pattern'; -export * from './index_patterns'; -export * from './index_patterns_api_client'; -export * from './types'; +export * from '../../../common/index_patterns/index_patterns'; +export * from './redirect_no_index_pattern'; +export * from './on_unsupported_time_pattern'; diff --git a/src/plugins/data/public/index_patterns/index_patterns/on_unsupported_time_pattern.tsx b/src/plugins/data/public/index_patterns/index_patterns/on_unsupported_time_pattern.tsx new file mode 100644 index 00000000000000..e635809059cda7 --- /dev/null +++ b/src/plugins/data/public/index_patterns/index_patterns/on_unsupported_time_pattern.tsx @@ -0,0 +1,75 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import React from 'react'; +import { CoreStart } from 'kibana/public'; +import { toMountPoint } from '../../../../kibana_react/public'; + +export const onUnsupportedTimePattern = ( + toasts: CoreStart['notifications']['toasts'], + navigateToApp: CoreStart['application']['navigateToApp'] +) => ({ id, title, index }: { id: string; title: string; index: string }) => { + const warningTitle = i18n.translate('data.indexPatterns.warningTitle', { + defaultMessage: 'Support for time interval index patterns removed', + }); + + const warningText = i18n.translate('data.indexPatterns.warningText', { + defaultMessage: + 'Currently querying all indices matching {index}. {title} should be migrated to a wildcard-based index pattern.', + values: { title, index }, + }); + + // kbnUrl was added to this service in #35262 before it was de-angularized, and merged in a PR + // directly against the 7.x branch. Index patterns were de-angularized in #39247, and in order + // to preserve the functionality from #35262 we need to get the injector here just for kbnUrl. + // This has all been removed as of 8.0. + + // 2019-12-01 The usage of kbnUrl had to be removed due to the transition to NP. + // It's now temporarily replaced by a simple replace of the single argument used by all URLs. + // Once kbnUrl is migrated to NP, this can be updated. + + toasts.addWarning({ + title: warningTitle, + text: toMountPoint( +
+

{warningText}

+ + + + navigateToApp('management', { + path: `/kibana/index_patterns/index_pattern/${id! || ''}`, + }) + } + > + + + + +
+ ), + }); +}; diff --git a/src/plugins/data/public/index_patterns/index_patterns/redirect_no_index_pattern.tsx b/src/plugins/data/public/index_patterns/index_patterns/redirect_no_index_pattern.tsx new file mode 100644 index 00000000000000..e32a8e023cf402 --- /dev/null +++ b/src/plugins/data/public/index_patterns/index_patterns/redirect_no_index_pattern.tsx @@ -0,0 +1,69 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { EuiCallOut } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import React from 'react'; +import { CoreStart } from 'kibana/public'; +import { toMountPoint } from '../../../../kibana_react/public'; + +let bannerId: string; + +export const onRedirectNoIndexPattern = ( + capabilities: CoreStart['application']['capabilities'], + navigateToApp: CoreStart['application']['navigateToApp'], + overlays: CoreStart['overlays'] +) => () => { + const canManageIndexPatterns = capabilities.management.kibana.index_patterns; + const redirectTarget = canManageIndexPatterns ? '/management/kibana/indexPatterns' : '/home'; + let timeoutId: NodeJS.Timeout | undefined; + + if (timeoutId) { + clearTimeout(timeoutId); + } + + const bannerMessage = i18n.translate('data.indexPatterns.ensureDefaultIndexPattern.bannerLabel', { + defaultMessage: + "In order to visualize and explore data in Kibana, you'll need to create an index pattern to retrieve data from Elasticsearch.", + }); + + // Avoid being hostile to new users who don't have an index pattern setup yet + // give them a friendly info message instead of a terse error message + bannerId = overlays.banners.replace( + bannerId, + toMountPoint() + ); + + // hide the message after the user has had a chance to acknowledge it -- so it doesn't permanently stick around + timeoutId = setTimeout(() => { + overlays.banners.remove(bannerId); + timeoutId = undefined; + }, 15000); + + if (redirectTarget === '/home') { + navigateToApp('home'); + } else { + navigateToApp('management', { + path: `/kibana/indexPatterns?bannerMessage=${bannerMessage}`, + }); + } + + // return never-resolving promise to stop resolving and wait for the url change + return new Promise(() => {}); +}; diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index 06b5cbdfdfdfb5..5ef85718dfcee2 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -40,7 +40,11 @@ import { SearchService } from './search/search_service'; import { FieldFormatsService } from './field_formats'; import { QueryService } from './query'; import { createIndexPatternSelect } from './ui/index_pattern_select'; -import { IndexPatternsService } from './index_patterns'; +import { + IndexPatternsService, + onRedirectNoIndexPattern, + onUnsupportedTimePattern, +} from './index_patterns'; import { setFieldFormats, setHttp, @@ -154,7 +158,7 @@ export class DataPublicPlugin implements Plugin { + notifications.toasts.add(toastInputFields); + }, + notifications.toasts.addError, + onRedirectNoIndexPattern(application.capabilities, application.navigateToApp, overlays), + onUnsupportedTimePattern(notifications.toasts, application.navigateToApp) + ); setIndexPatterns(indexPatterns); const query = this.queryService.start(savedObjects); diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 02281b73ee7f35..c343a46be0c45d 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -46,6 +46,7 @@ import { DeleteDocumentParams } from 'elasticsearch'; import { DeleteScriptParams } from 'elasticsearch'; import { DeleteTemplateParams } from 'elasticsearch'; import { Ensure } from '@kbn/utility-types'; +import { ErrorToastOptions } from 'src/core/public/notifications'; import { EuiButtonEmptyProps } from '@elastic/eui'; import { EuiComboBoxProps } from '@elastic/eui'; import { EuiConfirmModalProps } from '@elastic/eui'; @@ -170,6 +171,7 @@ import { TasksGetParams } from 'elasticsearch'; import { TasksListParams } from 'elasticsearch'; import { TermvectorsParams } from 'elasticsearch'; import { Toast } from 'kibana/public'; +import { ToastInputFields } from 'src/core/public/notifications'; import { ToastsStart } from 'kibana/public'; import { TypeOf } from '@kbn/config-schema'; import { UiActionsSetup } from 'src/plugins/ui_actions/public'; @@ -523,6 +525,11 @@ export type ExistsFilter = Filter & { exists?: FilterExistsProperty; }; +// Warning: (ae-forgotten-export) The symbol "ShorthandFieldMapObject" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export const expandShorthand: (sh: Record) => Record; + // Warning: (ae-forgotten-export) The symbol "SavedObjectReference" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "extractReferences" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -649,6 +656,16 @@ export type FieldFormatsContentType = 'html' | 'text'; // @public (undocumented) export type FieldFormatsGetConfigFn = (key: string, defaultOverride?: T) => T; +// @public (undocumented) +export interface FieldMappingSpec { + // (undocumented) + _deserialize?: (mapping: string) => any | undefined; + // (undocumented) + _serialize?: (mapping: any) => string | undefined; + // (undocumented) + type: ES_FIELD_TYPES; +} + // Warning: (ae-missing-release-tag) "Filter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -726,7 +743,7 @@ export function getEsPreference(uiSettings: IUiSettingsClient_2, sessionId?: str // Warning: (ae-missing-release-tag) "getIndexPatternFieldListCreator" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const getIndexPatternFieldListCreator: ({ fieldFormats, toastNotifications, }: FieldListDependencies) => CreateIndexPatternFieldList; +export const getIndexPatternFieldListCreator: ({ fieldFormats, onNotification, }: FieldListDependencies) => CreateIndexPatternFieldList; // Warning: (ae-missing-release-tag) "getKbnTypeNames" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -965,7 +982,11 @@ export type IMetricAggType = MetricAggType; export class IndexPattern implements IIndexPattern { // Warning: (ae-forgotten-export) The symbol "IIndexPatternsApiClient" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "PatternCache" needs to be exported by the entry point index.d.ts - constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: PatternCache); + // Warning: (ae-forgotten-export) The symbol "FieldFormatsStartCommon" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "OnNotification" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "OnError" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "OnUnsupportedTimePattern" needs to be exported by the entry point index.d.ts + constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: PatternCache, fieldFormats: FieldFormatsStartCommon, onNotification: OnNotification, onError: OnError, onUnsupportedTimePattern: OnUnsupportedTimePattern); // (undocumented) [key: string]: any; // (undocumented) @@ -1101,7 +1122,7 @@ export class IndexPatternField implements IFieldType { // (undocumented) $$spec: FieldSpec; // Warning: (ae-forgotten-export) The symbol "FieldDependencies" needs to be exported by the entry point index.d.ts - constructor(indexPattern: IndexPattern, spec: FieldSpec | IndexPatternField, shortDotsEnable: boolean, { fieldFormats, toastNotifications }: FieldDependencies); + constructor(indexPattern: IIndexPattern, spec: FieldSpec | IndexPatternField, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies); // (undocumented) aggregatable?: boolean; // (undocumented) @@ -1117,7 +1138,7 @@ export class IndexPatternField implements IFieldType { // (undocumented) format: any; // (undocumented) - indexPattern?: IndexPattern; + indexPattern?: IIndexPattern; // (undocumented) lang?: string; // (undocumented) @@ -1326,6 +1347,9 @@ export interface KueryNode { type: keyof NodeTypes; } +// @public (undocumented) +export type MappingObject = Record; + // Warning: (ae-missing-release-tag) "MatchAllFilter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) diff --git a/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx b/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx index 6eb4f82a940b1e..20e3fdae5ce5f9 100644 --- a/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx +++ b/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx @@ -24,7 +24,7 @@ import { Required } from '@kbn/utility-types'; import { EuiComboBox, EuiComboBoxProps } from '@elastic/eui'; import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../core/public'; -import { getTitle } from '../../index_patterns/lib'; +import { getTitle } from '../../../common/index_patterns/lib'; export type IndexPatternSelectProps = Required< // Omit, 'isLoading' | 'onSearchChange' | 'options' | 'selectedOptions' | 'append' | 'prepend' | 'sortMatchesBy'>, diff --git a/src/plugins/kibana_utils/public/errors/errors.test.ts b/src/plugins/kibana_utils/common/errors/errors.test.ts similarity index 100% rename from src/plugins/kibana_utils/public/errors/errors.test.ts rename to src/plugins/kibana_utils/common/errors/errors.test.ts diff --git a/src/plugins/kibana_utils/public/errors/errors.ts b/src/plugins/kibana_utils/common/errors/errors.ts similarity index 100% rename from src/plugins/kibana_utils/public/errors/errors.ts rename to src/plugins/kibana_utils/common/errors/errors.ts diff --git a/src/plugins/kibana_utils/public/errors/index.ts b/src/plugins/kibana_utils/common/errors/index.ts similarity index 100% rename from src/plugins/kibana_utils/public/errors/index.ts rename to src/plugins/kibana_utils/common/errors/index.ts diff --git a/src/plugins/kibana_utils/common/index.ts b/src/plugins/kibana_utils/common/index.ts index 87b625ef9a64f5..99daed98dbe640 100644 --- a/src/plugins/kibana_utils/common/index.ts +++ b/src/plugins/kibana_utils/common/index.ts @@ -22,6 +22,7 @@ export * from './of'; export * from './ui'; export * from './state_containers'; export * from './typed_json'; +export * from './errors'; export { createGetterSetter, Get, Set } from './create_getter_setter'; export { distinctUntilChangedWithInitialValue } from './distinct_until_changed_with_initial_value'; export { url } from './url'; diff --git a/src/plugins/kibana_utils/public/history/redirect_when_missing.tsx b/src/plugins/kibana_utils/public/history/redirect_when_missing.tsx index cffb7ff4549a84..d8121b656deeb5 100644 --- a/src/plugins/kibana_utils/public/history/redirect_when_missing.tsx +++ b/src/plugins/kibana_utils/public/history/redirect_when_missing.tsx @@ -24,7 +24,7 @@ import ReactDOM from 'react-dom'; import ReactMarkdown from 'react-markdown'; import { ApplicationStart, HttpStart, ToastsSetup } from 'kibana/public'; -import { SavedObjectNotFound } from '../errors'; +import { SavedObjectNotFound } from '..'; interface Mapping { [key: string]: string | { app: string; path: string }; diff --git a/src/plugins/kibana_utils/public/index.ts b/src/plugins/kibana_utils/public/index.ts index 3d8a4414de70c8..6f61e2c228970d 100644 --- a/src/plugins/kibana_utils/public/index.ts +++ b/src/plugins/kibana_utils/public/index.ts @@ -34,8 +34,7 @@ export { defaultFeedbackMessage, } from '../common'; export * from './core'; -export * from './errors'; -export * from './field_mapping'; +export * from '../common/errors'; export * from './field_wildcard'; export * from './parse'; export * from './render_complete'; diff --git a/src/plugins/saved_objects/public/saved_object/helpers/apply_es_resp.ts b/src/plugins/saved_objects/public/saved_object/helpers/apply_es_resp.ts index 9d0e25132271c3..47390c7dc9104a 100644 --- a/src/plugins/saved_objects/public/saved_object/helpers/apply_es_resp.ts +++ b/src/plugins/saved_objects/public/saved_object/helpers/apply_es_resp.ts @@ -18,11 +18,12 @@ */ import _ from 'lodash'; import { EsResponse, SavedObject, SavedObjectConfig, SavedObjectKibanaServices } from '../../types'; -import { expandShorthand, SavedObjectNotFound } from '../../../../kibana_utils/public'; +import { SavedObjectNotFound } from '../../../../kibana_utils/public'; import { IndexPattern, injectSearchSourceReferences, parseSearchSourceJSON, + expandShorthand, } from '../../../../data/public'; /** diff --git a/src/plugins/saved_objects/public/saved_object/helpers/serialize_saved_object.ts b/src/plugins/saved_objects/public/saved_object/helpers/serialize_saved_object.ts index acb371b8af9c2c..24e467ad18ac4b 100644 --- a/src/plugins/saved_objects/public/saved_object/helpers/serialize_saved_object.ts +++ b/src/plugins/saved_objects/public/saved_object/helpers/serialize_saved_object.ts @@ -18,8 +18,7 @@ */ import _ from 'lodash'; import { SavedObject, SavedObjectConfig } from '../../types'; -import { expandShorthand } from '../../../../kibana_utils/public'; -import { extractSearchSourceReferences } from '../../../../data/public'; +import { extractSearchSourceReferences, expandShorthand } from '../../../../data/public'; export function serializeSavedObject(savedObject: SavedObject, config: SavedObjectConfig) { // mapping definition for the fields that this object will expose