Skip to content

Commit

Permalink
Merge branch 'master' into upgrade/execa
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Mar 18, 2020
2 parents c4c3b57 + 24534e8 commit 46612a7
Show file tree
Hide file tree
Showing 107 changed files with 3,941 additions and 579 deletions.
18 changes: 11 additions & 7 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import sinon from 'sinon';
import { getFieldFormatsRegistry } from '../../../../test_utils/public/stub_field_formats';
import { METRIC_TYPE } from '@kbn/analytics';
import {
setFieldFormats,
setIndexPatterns,
setQueryService,
setUiSettings,
setInjectedMetadata,
setFieldFormats,
setSearchService,
setHttp,
setNotifications,
setOverlays,
setQueryService,
setSearchService,
setUiSettings,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/data/public/services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Expand Down Expand Up @@ -477,11 +479,13 @@ export function __start__(coreStart) {

// Services that need to be set in the legacy platform since the legacy data plugin
// which previously provided them has been removed.
setHttp(npStart.core.http);
setNotifications(npStart.core.notifications);
setOverlays(npStart.core.overlays);
setUiSettings(npStart.core.uiSettings);
setQueryService(npStart.plugins.data.query);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setFieldFormats(npStart.plugins.data.fieldFormats);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setQueryService(npStart.plugins.data.query);
setSearchService(npStart.plugins.data.search);
setAggs(npStart.plugins.data.search.aggs);
setOverlays(npStart.core.overlays);
}
34 changes: 33 additions & 1 deletion src/legacy/ui/public/new_platform/new_platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
jest.mock('history');

import { setRootControllerMock, historyMock } from './new_platform.test.mocks';
import { legacyAppRegister, __reset__, __setup__ } from './new_platform';
import {
legacyAppRegister,
__reset__,
__setup__,
__start__,
PluginsSetup,
PluginsStart,
} from './new_platform';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import * as dataServices from '../../../../plugins/data/public/services';
import { LegacyCoreSetup, LegacyCoreStart } from '../../../../core/public';
import { coreMock } from '../../../../core/public/mocks';
import { npSetup, npStart } from './__mocks__';

describe('ui/new_platform', () => {
describe('legacyAppRegister', () => {
Expand Down Expand Up @@ -108,4 +119,25 @@ describe('ui/new_platform', () => {
expect(unmountMock).toHaveBeenCalled();
});
});

describe('service getters', () => {
const services: Record<string, Function> = dataServices;
const getters = Object.keys(services).filter(k => k.substring(0, 3) === 'get');

getters.forEach(g => {
it(`sets a value for ${g}`, () => {
__reset__();
__setup__(
(coreMock.createSetup() as unknown) as LegacyCoreSetup,
(npSetup.plugins as unknown) as PluginsSetup
);
__start__(
(coreMock.createStart() as unknown) as LegacyCoreStart,
(npStart.plugins as unknown) as PluginsStart
);

expect(services[g]()).toBeDefined();
});
});
});
});
18 changes: 11 additions & 7 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ import {
} from '../../../../core/public';
import { Plugin as DataPlugin } from '../../../../plugins/data/public';
import {
setFieldFormats,
setIndexPatterns,
setQueryService,
setUiSettings,
setInjectedMetadata,
setFieldFormats,
setSearchService,
setHttp,
setNotifications,
setOverlays,
setQueryService,
setSearchService,
setUiSettings,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/data/public/services';
import { Plugin as ExpressionsPlugin } from '../../../../plugins/expressions/public';
Expand Down Expand Up @@ -141,12 +143,14 @@ export function __start__(coreStart: LegacyCoreStart, plugins: PluginsStart) {

// Services that need to be set in the legacy platform since the legacy data plugin
// which previously provided them has been removed.
setHttp(npStart.core.http);
setNotifications(npStart.core.notifications);
setOverlays(npStart.core.overlays);
setUiSettings(npStart.core.uiSettings);
setQueryService(npStart.plugins.data.query);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setFieldFormats(npStart.plugins.data.fieldFormats);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setQueryService(npStart.plugins.data.query);
setSearchService(npStart.plugins.data.search);
setOverlays(npStart.core.overlays);
}

/** Flag used to ensure `legacyAppRegister` is only called once. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,11 @@ export function queryDsl(api) {
__scope_link: '.',
},
],
filter: {
__scope_link: 'GLOBAL.filter',
},
filter: [
{
__scope_link: 'GLOBAL.filter',
},
],
minimum_should_match: 1,
boost: 1.0,
},
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { createIndexPatternSelect } from './ui/index_pattern_select';
import { IndexPatternsService } from './index_patterns';
import {
setFieldFormats,
setHttp,
setIndexPatterns,
setInjectedMetadata,
setNotifications,
Expand Down Expand Up @@ -128,6 +129,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli

public start(core: CoreStart, { uiActions }: DataStartDependencies): DataPublicPluginStart {
const { uiSettings, http, notifications, savedObjects, overlays } = core;
setHttp(http);
setNotifications(notifications);
setOverlays(overlays);
setUiSettings(uiSettings);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

// Global map state passed to every layer.
export type MapFilters = {
buffer: unknown;
extent: unknown;
filters: unknown[];
query: unknown;
refreshTimerLastTriggeredAt: string;
timeFilters: unknown;
zoom: number;
};

export type VectorLayerRequestMeta = MapFilters & {
applyGlobalQuery: boolean;
fieldNames: string[];
geogridPrecision: number;
sourceQuery: unknown;
sourceMeta: unknown;
};

export type ESSearchSourceResponseMeta = {
areResultsTrimmed?: boolean;
sourceType?: string;

// top hits meta
areEntitiesTrimmed?: boolean;
entityCount?: number;
totalEntities?: number;
};

// Partial because objects are justified downstream in constructors
export type DataMeta = Partial<VectorLayerRequestMeta> & Partial<ESSearchSourceResponseMeta>;

export type DataRequestDescriptor = {
dataId: string;
dataMetaAtStart?: DataMeta;
dataRequestToken?: symbol;
data?: object;
dataMeta?: DataMeta;
};
13 changes: 3 additions & 10 deletions x-pack/legacy/plugins/maps/common/descriptor_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER } from './constants';
import { DataRequestDescriptor } from './data_request_descriptor_types';
import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER, SCALING_TYPES } from './constants';

export type AbstractSourceDescriptor = {
id?: string;
Expand Down Expand Up @@ -49,7 +50,7 @@ export type ESSearchSourceDescriptor = AbstractESSourceDescriptor & {
tooltipProperties?: string[];
sortField?: string;
sortOrder?: SORT_ORDER;
useTopHits?: boolean;
scalingType: SCALING_TYPES;
topHitsSplitField?: string;
topHitsSize?: number;
};
Expand Down Expand Up @@ -93,14 +94,6 @@ export type JoinDescriptor = {
right: ESTermSourceDescriptor;
};

export type DataRequestDescriptor = {
dataId: string;
dataMetaAtStart: object;
dataRequestToken: symbol;
data: object;
dataMeta: object;
};

export type LayerDescriptor = {
__dataRequests?: DataRequestDescriptor[];
__isInErrorState?: boolean;
Expand Down
74 changes: 74 additions & 0 deletions x-pack/legacy/plugins/maps/common/migrations/scaling_type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { migrateUseTopHitsToScalingType } from './scaling_type';

describe('migrateUseTopHitsToScalingType', () => {
test('Should handle missing layerListJSON attribute', () => {
const attributes = {
title: 'my map',
};
expect(migrateUseTopHitsToScalingType({ attributes })).toEqual({
title: 'my map',
});
});

test('Should migrate useTopHits: true to scalingType TOP_HITS for ES documents sources', () => {
const layerListJSON = JSON.stringify([
{
sourceDescriptor: {
type: 'ES_SEARCH',
useTopHits: true,
},
},
]);
const attributes = {
title: 'my map',
layerListJSON,
};
expect(migrateUseTopHitsToScalingType({ attributes })).toEqual({
title: 'my map',
layerListJSON: '[{"sourceDescriptor":{"type":"ES_SEARCH","scalingType":"TOP_HITS"}}]',
});
});

test('Should migrate useTopHits: false to scalingType LIMIT for ES documents sources', () => {
const layerListJSON = JSON.stringify([
{
sourceDescriptor: {
type: 'ES_SEARCH',
useTopHits: false,
},
},
]);
const attributes = {
title: 'my map',
layerListJSON,
};
expect(migrateUseTopHitsToScalingType({ attributes })).toEqual({
title: 'my map',
layerListJSON: '[{"sourceDescriptor":{"type":"ES_SEARCH","scalingType":"LIMIT"}}]',
});
});

test('Should set scalingType to LIMIT when useTopHits is not set', () => {
const layerListJSON = JSON.stringify([
{
sourceDescriptor: {
type: 'ES_SEARCH',
},
},
]);
const attributes = {
title: 'my map',
layerListJSON,
};
expect(migrateUseTopHitsToScalingType({ attributes })).toEqual({
title: 'my map',
layerListJSON: '[{"sourceDescriptor":{"type":"ES_SEARCH","scalingType":"LIMIT"}}]',
});
});
});
43 changes: 43 additions & 0 deletions x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import _ from 'lodash';
import { ES_SEARCH, SCALING_TYPES } from '../constants';
import { LayerDescriptor, ESSearchSourceDescriptor } from '../descriptor_types';
import { MapSavedObjectAttributes } from '../../../../../plugins/maps/common/map_saved_object_type';

function isEsDocumentSource(layerDescriptor: LayerDescriptor) {
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
return sourceType === ES_SEARCH;
}

export function migrateUseTopHitsToScalingType({
attributes,
}: {
attributes: MapSavedObjectAttributes;
}): MapSavedObjectAttributes {
if (!attributes || !attributes.layerListJSON) {
return attributes;
}

const layerList: LayerDescriptor[] = JSON.parse(attributes.layerListJSON);
layerList.forEach((layerDescriptor: LayerDescriptor) => {
if (isEsDocumentSource(layerDescriptor)) {
const sourceDescriptor = layerDescriptor.sourceDescriptor as ESSearchSourceDescriptor;
sourceDescriptor.scalingType = _.get(layerDescriptor, 'sourceDescriptor.useTopHits', false)
? SCALING_TYPES.TOP_HITS
: SCALING_TYPES.LIMIT;
// @ts-ignore useTopHits no longer in type definition but that does not mean its not in live data
// hence the entire point of this method
delete sourceDescriptor.useTopHits;
}
});

return {
...attributes,
layerListJSON: JSON.stringify(layerList),
};
}
6 changes: 4 additions & 2 deletions x-pack/legacy/plugins/maps/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { topHitsTimeToSort } from './common/migrations/top_hits_time_to_sort';
import { moveApplyGlobalQueryToSources } from './common/migrations/move_apply_global_query';
import { addFieldMetaOptions } from './common/migrations/add_field_meta_options';
import { migrateSymbolStyleDescriptor } from './common/migrations/migrate_symbol_style_descriptor';
import { migrateUseTopHitsToScalingType } from './common/migrations/scaling_type';

export const migrations = {
map: {
Expand Down Expand Up @@ -48,11 +49,12 @@ export const migrations = {
};
},
'7.7.0': doc => {
const attributes = migrateSymbolStyleDescriptor(doc);
const attributesPhase1 = migrateSymbolStyleDescriptor(doc);
const attributesPhase2 = migrateUseTopHitsToScalingType({ attributes: attributesPhase1 });

return {
...doc,
attributes,
attributes: attributesPhase2,
};
},
},
Expand Down
18 changes: 18 additions & 0 deletions x-pack/legacy/plugins/maps/public/actions/map_actions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { DataMeta, MapFilters } from '../../common/data_request_descriptor_types';

export type SyncContext = {
startLoading(dataId: string, requestToken: symbol, meta: DataMeta): void;
stopLoading(dataId: string, requestToken: symbol, data: unknown, meta: DataMeta): void;
onLoadError(dataId: string, requestToken: symbol, errorMessage: string): void;
updateSourceData(newData: unknown): void;
isRequestStillActive(dataId: string, requestToken: symbol): boolean;
registerCancelCallback(requestToken: symbol, callback: () => void): void;
dataFilters: MapFilters;
};
Loading

0 comments on commit 46612a7

Please sign in to comment.