diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts index 2cf038cd5bd47..628b1999b1c23 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts @@ -19,7 +19,7 @@ // @ts-ignore import { fieldFormats } from 'ui/registry/field_formats'; -import { toastNotifications } from 'ui/notify'; +import { NotificationsSetup } from 'kibana/public'; import { i18n } from '@kbn/i18n'; // @ts-ignore import { ObjDefine } from './obj_define'; @@ -80,7 +80,8 @@ export class Field implements FieldType { constructor( indexPattern: IndexPattern, spec: FieldSpec | Field, - shortDotsEnable: boolean = false + shortDotsEnable: boolean = false, + notifications: NotificationsSetup ) { // unwrap old instances of Field if (spec instanceof Field) spec = spec.$$spec; @@ -106,7 +107,7 @@ export class Field implements FieldType { defaultMessage: 'Field {name} in indexPattern {title} is using an unknown field type.', }); - toastNotifications.addDanger({ + notifications.toasts.addDanger({ title, text, }); diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts index d167714f76b16..2fa7a92063107 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts @@ -18,16 +18,22 @@ */ import { IndexedArray } from 'ui/indexed_array'; +import { NotificationsSetup } from 'kibana/public'; import { IndexPattern } from '../index_patterns'; import { Field, FieldSpec } from './field'; export class FieldList extends IndexedArray { - constructor(indexPattern: IndexPattern, specs: FieldSpec[], shortDotsEnable = false) { + constructor( + indexPattern: IndexPattern, + specs: FieldSpec[], + shortDotsEnable = false, + notifications: NotificationsSetup + ) { super({ index: ['name'], group: ['type'], initialSet: specs.map(function(field) { - return new Field(indexPattern, field, shortDotsEnable); + return new Field(indexPattern, field, shortDotsEnable, notifications); }), }); } diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts index d87f9ed1a87f9..f8df2ed29fbde 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts @@ -105,6 +105,18 @@ const apiClient = { getFieldsForWildcard: jest.fn(), }; +const notifications = { + toasts: { + addDanger: jest.fn(), + addError: jest.fn(), + add: jest.fn(), + addWarning: jest.fn(), + addSuccess: jest.fn(), + remove: jest.fn(), + get$: jest.fn(), + }, +}; + // helper function to create index patterns function create(id: string, payload?: any): Promise { const indexPattern = new IndexPattern( @@ -112,7 +124,8 @@ function create(id: string, payload?: any): Promise { (cfg: any) => config.get(cfg), savedObjectsClient as any, apiClient, - patternCache + patternCache, + notifications ); setDocsourcePayload(id, payload); @@ -374,7 +387,8 @@ describe('IndexPattern', () => { (cfg: any) => config.get(cfg), savedObjectsClient as any, apiClient, - patternCache + patternCache, + notifications ); await pattern.init(); @@ -386,7 +400,8 @@ describe('IndexPattern', () => { (cfg: any) => config.get(cfg), savedObjectsClient as any, apiClient, - patternCache + patternCache, + notifications ); await samePattern.init(); diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx index f82f4da4a14a6..95692b88276e7 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx @@ -29,7 +29,7 @@ import { fieldFormats } from 'ui/registry/field_formats'; import { expandShorthand } from 'ui/utils/mapping_setup'; import { toastNotifications } from 'ui/notify'; import { findObjectByTitle } from 'ui/saved_objects'; -import { SavedObjectsClientContract } from 'src/core/public'; +import { NotificationsSetup, SavedObjectsClientContract } from 'src/core/public'; import { SavedObjectNotFound, DuplicateField } from '../../../../../../plugins/kibana_utils/public'; import { IndexPatternMissingIndices } from '../errors'; @@ -76,6 +76,7 @@ export class IndexPattern implements StaticIndexPattern { public formatField: any; public flattenHit: any; public metaFields: string[]; + public notifications: NotificationsSetup; private version: string | undefined; private savedObjectsClient: SavedObjectsClientContract; @@ -113,7 +114,8 @@ export class IndexPattern implements StaticIndexPattern { getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, - patternCache: any + patternCache: any, + notifications: NotificationsSetup ) { this.id = id; this.savedObjectsClient = savedObjectsClient; @@ -121,11 +123,12 @@ export class IndexPattern implements StaticIndexPattern { // 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.notifications = notifications; this.shortDotsEnable = this.getConfig('shortDots:enable'); this.metaFields = this.getConfig('metaFields'); - this.fields = new FieldList(this, [], this.shortDotsEnable); + this.fields = new FieldList(this, [], this.shortDotsEnable, notifications); this.fieldsFetcher = createFieldsFetcher(this, apiClient, this.getConfig('metaFields')); this.flattenHit = flattenHitWrapper(this, this.getConfig('metaFields')); this.formatHit = formatHitProvider(this, fieldFormats.getDefaultInstance('string')); @@ -145,7 +148,7 @@ export class IndexPattern implements StaticIndexPattern { private initFields(input?: any) { const newValue = input || this.fields; - this.fields = new FieldList(this, newValue, this.shortDotsEnable); + this.fields = new FieldList(this, newValue, this.shortDotsEnable, this.notifications); } private isFieldRefreshRequired(): boolean { @@ -333,16 +336,21 @@ export class IndexPattern implements StaticIndexPattern { } this.fields.push( - new Field(this, { - name, - script, - fieldType, - scripted: true, - lang, - aggregatable: true, - filterable: true, - searchable: true, - }) + new Field( + this, + { + name, + script, + fieldType, + scripted: true, + lang, + aggregatable: true, + filterable: true, + searchable: true, + }, + false, + this.notifications + ) ); await this.save(); @@ -455,7 +463,8 @@ export class IndexPattern implements StaticIndexPattern { this.getConfig, this.savedObjectsClient, this.patternCache, - this.fieldsFetcher + this.fieldsFetcher, + this.notifications ); await duplicatePattern.destroy(); } @@ -508,7 +517,8 @@ export class IndexPattern implements StaticIndexPattern { this.getConfig, this.savedObjectsClient, this.patternCache, - this.fieldsFetcher + this.fieldsFetcher, + this.notifications ); return samePattern.init().then(() => { // What keys changed from now and what the server returned diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts index 9330fb312c225..d2deaa92e2b40 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts @@ -23,6 +23,7 @@ import { SavedObjectsClientContract, UiSettingsClientContract, HttpServiceBase, + NotificationsSetup, } from 'kibana/public'; jest.mock('../errors', () => ({ @@ -70,8 +71,9 @@ describe('IndexPatterns', () => { const savedObjectsClient = {} as SavedObjectsClientContract; const uiSettings = {} as UiSettingsClientContract; const http = {} as HttpServiceBase; + const notifications = {} as NotificationsSetup; - indexPatterns = new IndexPatterns(uiSettings, savedObjectsClient, http); + indexPatterns = new IndexPatterns(uiSettings, savedObjectsClient, http, notifications); }); test('does cache gets for the same id', () => { diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts index 21bbdb22e6d9e..fc5ef6cb75355 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts @@ -23,6 +23,7 @@ import { SimpleSavedObject, UiSettingsClientContract, HttpServiceBase, + NotificationsSetup, } from 'src/core/public'; // @ts-ignore import { fieldFormats } from 'ui/registry/field_formats'; @@ -40,13 +41,16 @@ export class IndexPatterns { private savedObjectsClient: SavedObjectsClientContract; private savedObjectsCache?: Array>> | null; private apiClient: IndexPatternsApiClient; + private notifications: NotificationsSetup; constructor( config: UiSettingsClientContract, savedObjectsClient: SavedObjectsClientContract, - http: HttpServiceBase + http: HttpServiceBase, + notifications: NotificationsSetup ) { this.apiClient = new IndexPatternsApiClient(http); + this.notifications = notifications; this.config = config; this.savedObjectsClient = savedObjectsClient; @@ -129,7 +133,8 @@ export class IndexPatterns { (cfg: any) => this.config.get(cfg), this.savedObjectsClient, this.apiClient, - indexPatternCache + indexPatternCache, + this.notifications ).init(); }; } diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts index 84fb65d0f2303..fefa71ec91d0d 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts @@ -21,6 +21,7 @@ import { UiSettingsClientContract, SavedObjectsClientContract, HttpServiceBase, + NotificationsSetup, } from 'src/core/public'; import { Field, FieldList, FieldType } from './fields'; import { createFlattenHitWrapper } from './index_patterns'; @@ -36,6 +37,7 @@ export interface IndexPatternDependencies { uiSettings: UiSettingsClientContract; savedObjectsClient: SavedObjectsClientContract; http: HttpServiceBase; + notifications: NotificationsSetup; } /** @@ -44,12 +46,12 @@ export interface IndexPatternDependencies { * @internal */ export class IndexPatternsService { - public setup({ uiSettings, savedObjectsClient, http }: IndexPatternDependencies) { + public setup({ uiSettings, savedObjectsClient, http, notifications }: IndexPatternDependencies) { return { FieldList, flattenHitWrapper: createFlattenHitWrapper(), formatHitProvider, - indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient, http), + indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient, http, notifications), IndexPatternSelect: createIndexPatternSelect(savedObjectsClient), __LEGACY: { // For BWC we must temporarily export the class implementation of Field, diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index 549342c0da9d4..00f7322d725ad 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -17,7 +17,7 @@ * under the License. */ -import { CoreSetup, CoreStart, Plugin } from '../../../../core/public'; +import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { SearchService, SearchSetup, createSearchBar, StatetfulSearchBarProps } from './search'; import { QueryService, QuerySetup } from './query'; import { FilterService, FilterSetup } from './filter'; @@ -96,13 +96,14 @@ export class DataPlugin private setupApi!: DataSetup; public setup(core: CoreSetup, { __LEGACY }: DataPluginSetupDependencies): DataSetup { - const { uiSettings, http } = core; + const { uiSettings, http, notifications } = core; const savedObjectsClient = __LEGACY.savedObjectsClient; const indexPatternsService = this.indexPatterns.setup({ uiSettings, savedObjectsClient, http, + notifications, }); const timefilterService = this.timefilter.setup({ diff --git a/src/legacy/core_plugins/data/public/shim/legacy_module.ts b/src/legacy/core_plugins/data/public/shim/legacy_module.ts index fea9409b2ec68..32b88720a4579 100644 --- a/src/legacy/core_plugins/data/public/shim/legacy_module.ts +++ b/src/legacy/core_plugins/data/public/shim/legacy_module.ts @@ -112,7 +112,8 @@ export const initLegacyModule = once((): void => { _service = new IndexPatterns( npStart.core.uiSettings, npStart.core.savedObjects.client, - npStart.core.http + npStart.core.http, + npStart.core.notifications ); return _service; });