Skip to content

Commit

Permalink
moved notifications to the getInternalStartServices
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa committed Apr 4, 2020
1 parent 14df4e5 commit 43750da
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
setSearchService,
setUiSettings,
getFieldFormats,
getNotifications,
} from './services';
import { createSearchBar } from './ui/search_bar/create_search_bar';
import { esaggs } from './search/expressions';
Expand Down Expand Up @@ -104,6 +105,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli

const getInternalStartServices: GetInternalStartServicesFn = () => ({
fieldFormats: getFieldFormats(),
notifications: getNotifications(),
});

const queryService = this.queryService.setup({
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/data/public/search/aggs/agg_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { BaseParamType } from './param_types/base';

import { AggConfig } from './agg_config';
import { IAggConfigs } from './agg_configs';
import { AggTypeDependencies } from './agg_type';

const paramTypeMap = {
field: FieldParamType,
Expand All @@ -45,12 +46,13 @@ export interface AggParamOption {
}

export const initParams = <TAggParam extends AggParamType = AggParamType>(
params: TAggParam[]
params: TAggParam[],
{ getInternalStartServices }: AggTypeDependencies
): TAggParam[] =>
params.map((config: TAggParam) => {
const Class = paramTypeMap[config.type] || paramTypeMap._default;

return new Class(config);
return new Class(config, { getInternalStartServices });
}) as TAggParam[];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/aggs/agg_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class AggType<
});
}

this.params = initParams(params);
this.params = initParams(params, { getInternalStartServices });
}

this.getRequestAggs = config.getRequestAggs || noop;
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/data/public/search/aggs/agg_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IUiSettingsClient, NotificationsSetup } from 'src/core/public';
import { IUiSettingsClient } from 'src/core/public';
import { QuerySetup } from '../../query/query_service';

import { getCountMetricAgg } from './metrics/count';
Expand Down Expand Up @@ -56,14 +56,12 @@ import { getBucketMaxMetricAgg } from './metrics/bucket_max';
import { GetInternalStartServicesFn } from '../../types';

export interface AggTypesDependencies {
notifications: NotificationsSetup;
uiSettings: IUiSettingsClient;
query: QuerySetup;
getInternalStartServices: GetInternalStartServicesFn;
}

export const getAggTypes = ({
notifications,
uiSettings,
query,
getInternalStartServices,
Expand Down Expand Up @@ -93,7 +91,7 @@ export const getAggTypes = ({
],
buckets: [
getDateHistogramBucketAgg({ uiSettings, query, getInternalStartServices }),
getHistogramBucketAgg({ uiSettings, notifications, getInternalStartServices }),
getHistogramBucketAgg({ uiSettings, getInternalStartServices }),
getRangeBucketAgg({ getInternalStartServices }),
getDateRangeBucketAgg({ uiSettings, getInternalStartServices }),
getIpRangeBucketAgg({ getInternalStartServices }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { coreMock } from '../../../../../../../src/core/public/mocks';
import { coreMock, notificationServiceMock } from '../../../../../../../src/core/public/mocks';
import { getDateRangeBucketAgg, DateRangeBucketAggDependencies } from './date_range';
import { AggConfigs } from '../agg_configs';
import { mockAggTypesRegistry } from '../test_helpers';
Expand All @@ -34,6 +34,7 @@ describe('date_range params', () => {
uiSettings,
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};
});
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/aggs/buckets/geo_hash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getGeoHashBucketAgg, GeoHashBucketAggDependencies } from './geo_hash';
import { AggConfigs, IAggConfigs } from '../agg_configs';
import { mockAggTypesRegistry } from '../test_helpers';
import { BUCKET_TYPES } from './bucket_agg_types';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';

Expand All @@ -32,6 +33,7 @@ describe('Geohash Agg', () => {
aggTypesDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/data/public/search/aggs/buckets/histogram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { coreMock } from '../../../../../../../src/core/public/mocks';
import { coreMock, notificationServiceMock } from '../../../../../../../src/core/public/mocks';
import { AggConfigs } from '../agg_configs';
import { mockAggTypesRegistry } from '../test_helpers';
import { BUCKET_TYPES } from './bucket_agg_types';
Expand All @@ -34,13 +34,13 @@ describe('Histogram Agg', () => {
let aggTypesDependencies: HistogramBucketAggDependencies;

beforeEach(() => {
const { uiSettings, notifications } = coreMock.createSetup();
const { uiSettings } = coreMock.createSetup();

aggTypesDependencies = {
uiSettings,
notifications,
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};
});
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/data/public/search/aggs/buckets/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import { IUiSettingsClient, NotificationsSetup } from 'src/core/public';
import { IUiSettingsClient } from 'src/core/public';

import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';
import { createFilterHistogram } from './create_filter/histogram';
Expand All @@ -34,7 +34,6 @@ export interface AutoBounds {

export interface HistogramBucketAggDependencies {
uiSettings: IUiSettingsClient;
notifications: NotificationsSetup;
getInternalStartServices: GetInternalStartServicesFn;
}

Expand All @@ -45,7 +44,6 @@ export interface IBucketHistogramAggConfig extends IBucketAggConfig {

export const getHistogramBucketAgg = ({
uiSettings,
notifications,
getInternalStartServices,
}: HistogramBucketAggDependencies) =>
new BucketAggType<IBucketHistogramAggConfig>(
Expand Down Expand Up @@ -126,7 +124,7 @@ export const getHistogramBucketAgg = ({
})
.catch((e: Error) => {
if (e.name === 'AbortError') return;
notifications.toasts.addWarning(
getInternalStartServices().notifications.toasts.addWarning(
i18n.translate('data.search.aggs.histogram.missingMaxMinValuesWarning', {
defaultMessage:
'Unable to retrieve max and min values to auto-scale histogram buckets. This may lead to poor visualization performance.',
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/aggs/buckets/range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { mockDataServices, mockAggTypesRegistry } from '../test_helpers';
import { BUCKET_TYPES } from './bucket_agg_types';
import { FieldFormatsGetConfigFn, NumberFormat } from '../../../../common';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

const buckets = [
{
Expand Down Expand Up @@ -51,6 +52,7 @@ describe('Range Agg', () => {
aggTypesDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
SignificantTermsBucketAggDependencies,
} from './significant_terms';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

describe('Significant Terms Agg', () => {
describe('order agg editor UI', () => {
Expand All @@ -35,6 +36,7 @@ describe('Significant Terms Agg', () => {
aggTypesDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};
});
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/aggs/metrics/median.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import { AggConfigs, IAggConfigs } from '../agg_configs';
import { mockAggTypesRegistry } from '../test_helpers';
import { METRIC_TYPES } from './metric_agg_types';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

describe('AggTypeMetricMedianProvider class', () => {
let aggConfigs: IAggConfigs;
const aggTypesDependencies: MedianMetricAggDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import { mockAggTypesRegistry } from '../test_helpers';
import { IMetricAggConfig, MetricAggType } from './metric_agg_type';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { GetInternalStartServicesFn } from '../../../types';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

describe('parent pipeline aggs', function() {
const getInternalStartServices: GetInternalStartServicesFn = () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
});

const typesRegistry = mockAggTypesRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import { AggConfigs, IAggConfigs } from '../agg_configs';
import { mockAggTypesRegistry } from '../test_helpers';
import { METRIC_TYPES } from './metric_agg_types';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

describe('AggTypesMetricsPercentileRanksProvider class', function() {
let aggConfigs: IAggConfigs;
const aggTypesDependencies: PercentileRanksMetricAggDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import { AggConfigs, IAggConfigs } from '../agg_configs';
import { mockAggTypesRegistry } from '../test_helpers';
import { METRIC_TYPES } from './metric_agg_types';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

describe('AggTypesMetricsPercentilesProvider class', () => {
let aggConfigs: IAggConfigs;
const aggTypesDependencies: PercentilesMetricAggDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import { IMetricAggConfig, MetricAggType } from './metric_agg_type';
import { mockAggTypesRegistry } from '../test_helpers';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { GetInternalStartServicesFn } from '../../../types';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

describe('sibling pipeline aggs', () => {
const getInternalStartServices: GetInternalStartServicesFn = () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
});

const typesRegistry = mockAggTypesRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import { AggConfigs } from '../agg_configs';
import { mockAggTypesRegistry } from '../test_helpers';
import { METRIC_TYPES } from './metric_agg_types';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

describe('AggTypeMetricStandardDeviationProvider class', () => {
const aggTypesDependencies: StdDeviationMetricAggDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};
const typesRegistry = mockAggTypesRegistry([getStdDeviationMetricAgg(aggTypesDependencies)]);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/aggs/metrics/top_hit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ import { mockAggTypesRegistry } from '../test_helpers';
import { IMetricAggConfig } from './metric_agg_type';
import { KBN_FIELD_TYPES } from '../../../../common';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

describe('Top hit metric', () => {
let aggDsl: Record<string, any>;
let aggConfig: IMetricAggConfig;
const aggTypesDependencies: TopHitMetricAggDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

Expand Down
13 changes: 10 additions & 3 deletions src/plugins/data/public/search/aggs/param_types/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@ import { BaseParamType } from './base';
import { propFilter } from '../filter';
import { isNestedField, KBN_FIELD_TYPES } from '../../../../common';
import { Field as IndexPatternField } from '../../../index_patterns';
import { getNotifications } from '../../../../public/services';
import { GetInternalStartServicesFn } from '../../../types';

const filterByType = propFilter('type');

export type FieldTypes = KBN_FIELD_TYPES | KBN_FIELD_TYPES[] | '*';
// TODO need to make a more explicit interface for this
export type IFieldParamType = FieldParamType;

export interface FieldParamTypeDependencies {
getInternalStartServices: GetInternalStartServicesFn;
}

export class FieldParamType extends BaseParamType {
required = true;
scriptable = true;
filterFieldTypes: FieldTypes;
onlyAggregatable: boolean;

constructor(config: Record<string, any>) {
constructor(
config: Record<string, any>,
{ getInternalStartServices }: FieldParamTypeDependencies
) {
super(config);

this.filterFieldTypes = config.filterFieldTypes || '*';
Expand Down Expand Up @@ -87,7 +94,7 @@ export class FieldParamType extends BaseParamType {
// @ts-ignore
const validField = this.getAvailableFields(aggConfig).find((f: any) => f.name === fieldName);
if (!validField) {
getNotifications().toasts.addDanger(
getInternalStartServices().notifications.toasts.addDanger(
i18n.translate(
'data.search.aggs.paramTypes.field.invalidSavedFieldParameterErrorMessage',
{
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
const aggTypes = getAggTypes({
query,
uiSettings: core.uiSettings,
notifications: core.notifications,
getInternalStartServices,
});

Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface IDataPluginServices extends Partial<CoreStart> {
/** @internal **/
export interface InternalStartServices {
fieldFormats: FieldFormatsStart;
notifications: CoreStart['notifications'];
}

/** @internal **/
Expand Down

0 comments on commit 43750da

Please sign in to comment.