Skip to content

Commit e466309

Browse files
author
Aaron Caldwell
authored
[Maps] Update layer dependencies to NP (#59585) (#60753)
* Layers dir up through sources migrated. Kibana services updated * Create separate init method for plugin setup, leverage in embeddable factory * Add NP timefilter, http, IndexPatternSelect * Pull vis color utils into Maps * Add NP dark mode and toast handling. Some fixes * Init autocomplete and indexPattern via normal paths * Test fixes and clean up * Update index pattern and autocomplete refs. Make getters functions * Fix remaining broken jest tests * Update inspector start contract * Clean up plugin and legacy files. Fix type issues * Set inspector in plugin start method not external function * Keep both injected var functions (legacy and NP). Move inspector init back to separate init function * Add back ts-ignore on NP kibana services import
1 parent f0059a3 commit e466309

31 files changed

+207
-109
lines changed

x-pack/legacy/plugins/maps/public/angular/get_initial_layers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import _ from 'lodash';
77
import { KibanaTilemapSource } from '../layers/sources/kibana_tilemap_source';
88
import { EMSTMSSource } from '../layers/sources/ems_tms_source';
9-
import chrome from 'ui/chrome';
9+
import { getInjectedVarFunc } from '../kibana_services';
1010
import { getKibanaTileMap } from '../meta';
1111

1212
export function getInitialLayers(layerListJSON, initialLayers = []) {
@@ -22,7 +22,7 @@ export function getInitialLayers(layerListJSON, initialLayers = []) {
2222
return [layer.toLayerDescriptor(), ...initialLayers];
2323
}
2424

25-
const isEmsEnabled = chrome.getInjected('isEmsEnabled', true);
25+
const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true);
2626
if (isEmsEnabled) {
2727
const descriptor = EMSTMSSource.createDescriptor({ isAutoSelect: true });
2828
const source = new EMSTMSSource(descriptor);

x-pack/legacy/plugins/maps/public/angular/get_initial_layers.test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
jest.mock('../meta', () => {
88
return {};
99
});
10-
11-
jest.mock('ui/chrome', () => {
12-
return {};
13-
});
10+
jest.mock('../kibana_services');
1411

1512
import { getInitialLayers } from './get_initial_layers';
1613

1714
const layerListNotProvided = undefined;
1815

1916
describe('Saved object has layer list', () => {
17+
beforeEach(() => {
18+
require('../kibana_services').getInjectedVarFunc = () => jest.fn();
19+
});
20+
2021
it('Should get initial layers from saved object', () => {
2122
const layerListFromSavedObject = [
2223
{
@@ -64,7 +65,7 @@ describe('EMS is enabled', () => {
6465
require('../meta').getKibanaTileMap = () => {
6566
return null;
6667
};
67-
require('ui/chrome').getInjected = key => {
68+
require('../kibana_services').getInjectedVarFunc = () => key => {
6869
switch (key) {
6970
case 'emsTileLayerId':
7071
return {
@@ -75,7 +76,7 @@ describe('EMS is enabled', () => {
7576
case 'isEmsEnabled':
7677
return true;
7778
default:
78-
throw new Error(`Unexpected call to chrome.getInjected with key ${key}`);
79+
throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`);
7980
}
8081
};
8182
});
@@ -109,12 +110,12 @@ describe('EMS is not enabled', () => {
109110
return null;
110111
};
111112

112-
require('ui/chrome').getInjected = key => {
113+
require('../kibana_services').getInjectedVarFunc = () => key => {
113114
switch (key) {
114115
case 'isEmsEnabled':
115116
return false;
116117
default:
117-
throw new Error(`Unexpected call to chrome.getInjected with key ${key}`);
118+
throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`);
118119
}
119120
};
120121
});

x-pack/legacy/plugins/maps/public/angular/map_controller.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { i18n } from '@kbn/i18n';
1515
import { capabilities } from 'ui/capabilities';
1616
import { render, unmountComponentAtNode } from 'react-dom';
1717
import { uiModules } from 'ui/modules';
18-
import { timefilter } from 'ui/timefilter';
18+
import { getTimeFilter, getIndexPatternService, getInspector } from '../kibana_services';
1919
import { Provider } from 'react-redux';
2020
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2121
import { createMapStore } from '../../../../../plugins/maps/public/reducers/store';
@@ -52,7 +52,7 @@ import {
5252
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
5353
import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
5454
import { docTitle } from 'ui/doc_title';
55-
import { indexPatternService, getInspector } from '../kibana_services';
55+
5656
import { toastNotifications } from 'ui/notify';
5757
import { getInitialLayers } from './get_initial_layers';
5858
import { getInitialQuery } from './get_initial_query';
@@ -396,7 +396,7 @@ app.controller(
396396
const indexPatterns = [];
397397
const getIndexPatternPromises = nextIndexPatternIds.map(async indexPatternId => {
398398
try {
399-
const indexPattern = await indexPatternService.get(indexPatternId);
399+
const indexPattern = await getIndexPatternService().get(indexPatternId);
400400
indexPatterns.push(indexPattern);
401401
} catch (err) {
402402
// unable to fetch index pattern
@@ -519,8 +519,8 @@ app.controller(
519519
}
520520

521521
// Hide angular timepicer/refresh UI from top nav
522-
timefilter.disableTimeRangeSelector();
523-
timefilter.disableAutoRefreshSelector();
522+
getTimeFilter().disableTimeRangeSelector();
523+
getTimeFilter().disableAutoRefreshSelector();
524524
$scope.showDatePicker = true; // used by query-bar directive to enable timepikcer in query bar
525525
$scope.topNavMenu = [
526526
{

x-pack/legacy/plugins/maps/public/components/geo_field_with_index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// Maps can contain geo fields from multiple index patterns. GeoFieldWithIndex is used to:
99
// 1) Combine the geo field along with associated index pattern state.
10-
// 2) Package asynchronously looked up state via indexPatternService to avoid
10+
// 2) Package asynchronously looked up state via getIndexPatternService() to avoid
1111
// PITA of looking up async state in downstream react consumers.
1212
export type GeoFieldWithIndex = {
1313
geoFieldName: string;

x-pack/legacy/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020

2121
import { FormattedMessage } from '@kbn/i18n/react';
2222
import { i18n } from '@kbn/i18n';
23-
import { indexPatternService } from '../../../kibana_services';
23+
import { getIndexPatternService } from '../../../kibana_services';
2424
import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox';
2525

2626
import { npStart } from 'ui/new_platform';
@@ -47,7 +47,7 @@ export class FilterEditor extends Component {
4747
const indexPatterns = [];
4848
const getIndexPatternPromises = indexPatternIds.map(async indexPatternId => {
4949
try {
50-
const indexPattern = await indexPatternService.get(indexPatternId);
50+
const indexPattern = await getIndexPatternService().get(indexPatternId);
5151
indexPatterns.push(indexPattern);
5252
} catch (err) {
5353
// unable to fetch index pattern

x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { WhereExpression } from './where_expression';
1414
import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox';
1515

1616
import { indexPatterns } from '../../../../../../../../../src/plugins/data/public';
17-
import { indexPatternService } from '../../../../kibana_services';
17+
import { getIndexPatternService } from '../../../../kibana_services';
1818

1919
export class Join extends Component {
2020
state = {
@@ -39,7 +39,7 @@ export class Join extends Component {
3939

4040
let indexPattern;
4141
try {
42-
indexPattern = await indexPatternService.get(indexPatternId);
42+
indexPattern = await getIndexPatternService().get(indexPatternId);
4343
} catch (err) {
4444
if (this._isMounted) {
4545
this.setState({

x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ import { i18n } from '@kbn/i18n';
1919
import { SingleFieldSelect } from '../../../../components/single_field_select';
2020
import { FormattedMessage } from '@kbn/i18n/react';
2121
import { getTermsFields } from '../../../../index_pattern_util';
22-
23-
import { indexPatternService } from '../../../../kibana_services';
24-
25-
import { npStart } from 'ui/new_platform';
26-
const { IndexPatternSelect } = npStart.plugins.data.ui;
22+
import {
23+
getIndexPatternService,
24+
getIndexPatternSelectComponent,
25+
} from '../../../../kibana_services';
2726

2827
export class JoinExpression extends Component {
2928
state = {
@@ -44,7 +43,7 @@ export class JoinExpression extends Component {
4443

4544
_onRightSourceChange = async indexPatternId => {
4645
try {
47-
const indexPattern = await indexPatternService.get(indexPatternId);
46+
const indexPattern = await getIndexPatternService().get(indexPatternId);
4847
this.props.onRightSourceChange({
4948
indexPatternId,
5049
indexPatternTitle: indexPattern.title,
@@ -106,6 +105,7 @@ export class JoinExpression extends Component {
106105
if (!this.props.leftValue) {
107106
return null;
108107
}
108+
const IndexPatternSelect = getIndexPatternSelectComponent();
109109

110110
return (
111111
<EuiFormRow

x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public';
1515
import { setup } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy';
1616
import { MapEmbeddable } from './map_embeddable';
17-
import { indexPatternService } from '../kibana_services';
17+
import { getIndexPatternService } from '../kibana_services';
1818

1919
import { createMapPath, MAP_SAVED_OBJECT_TYPE, APP_ICON } from '../../common/constants';
2020
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
@@ -24,8 +24,8 @@ import { getQueryableUniqueIndexPatternIds } from '../selectors/map_selectors';
2424
import { getInitialLayers } from '../angular/get_initial_layers';
2525
import { mergeInputWithSavedMap } from './merge_input_with_saved_map';
2626
import '../angular/services/gis_map_saved_object_loader';
27-
import { bindSetupCoreAndPlugins } from '../plugin';
28-
import { npSetup } from 'ui/new_platform';
27+
import { bindSetupCoreAndPlugins, bindStartCoreAndPlugins } from '../plugin';
28+
import { npSetup, npStart } from 'ui/new_platform';
2929

3030
export class MapEmbeddableFactory extends EmbeddableFactory {
3131
type = MAP_SAVED_OBJECT_TYPE;
@@ -40,7 +40,9 @@ export class MapEmbeddableFactory extends EmbeddableFactory {
4040
getIconForSavedObject: () => APP_ICON,
4141
},
4242
});
43+
// Init required services. Necessary while in legacy
4344
bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
45+
bindStartCoreAndPlugins(npStart.core, npStart.plugins);
4446
}
4547
isEditable() {
4648
return capabilities.get().maps.save;
@@ -76,7 +78,7 @@ export class MapEmbeddableFactory extends EmbeddableFactory {
7678

7779
const promises = queryableIndexPatternIds.map(async indexPatternId => {
7880
try {
79-
return await indexPatternService.get(indexPatternId);
81+
return await getIndexPatternService().get(indexPatternId);
8082
} catch (error) {
8183
// Unable to load index pattern, better to not throw error so map embeddable can render
8284
// Error will be surfaced by map embeddable since it too will be unable to locate the index pattern

x-pack/legacy/plugins/maps/public/index_pattern_util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { indexPatternService } from './kibana_services';
7+
import { getIndexPatternService } from './kibana_services';
88
import { indexPatterns } from '../../../../../src/plugins/data/public';
99
import { ES_GEO_FIELD_TYPE } from '../common/constants';
1010

1111
export async function getIndexPatternsFromIds(indexPatternIds = []) {
1212
const promises = [];
1313
indexPatternIds.forEach(id => {
14-
const indexPatternPromise = indexPatternService.get(id);
14+
const indexPatternPromise = getIndexPatternService().get(id);
1515
if (indexPatternPromise) {
1616
promises.push(indexPatternPromise);
1717
}

x-pack/legacy/plugins/maps/public/kibana_services.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66

77
import { esFilters, search } from '../../../../../src/plugins/data/public';
88
const { getRequestInspectorStats, getResponseInspectorStats } = search;
9-
import { npStart } from 'ui/new_platform';
109

1110
export const SPATIAL_FILTER_TYPE = esFilters.FILTERS.SPATIAL_FILTER;
1211
export { SearchSource } from '../../../../../src/plugins/data/public';
13-
export const indexPatternService = npStart.plugins.data.indexPatterns;
14-
export const autocompleteService = npStart.plugins.data.autocomplete;
12+
13+
let indexPatternService;
14+
export const setIndexPatternService = dataIndexPatterns =>
15+
(indexPatternService = dataIndexPatterns);
16+
export const getIndexPatternService = () => indexPatternService;
17+
18+
let autocompleteService;
19+
export const setAutocompleteService = dataAutoComplete => (autocompleteService = dataAutoComplete);
20+
export const getAutocompleteService = () => autocompleteService;
1521

1622
let licenseId;
1723
export const setLicenseId = latestLicenseId => (licenseId = latestLicenseId);
@@ -31,6 +37,31 @@ export const getFileUploadComponent = () => {
3137
return fileUploadPlugin.JsonUploadAndParse;
3238
};
3339

40+
let getInjectedVar;
41+
export const setInjectedVarFunc = getInjectedVarFunc => (getInjectedVar = getInjectedVarFunc);
42+
export const getInjectedVarFunc = () => getInjectedVar;
43+
44+
let uiSettings;
45+
export const setUiSettings = coreUiSettings => (uiSettings = coreUiSettings);
46+
export const getUiSettings = () => uiSettings;
47+
48+
let indexPatternSelectComponent;
49+
export const setIndexPatternSelect = indexPatternSelect =>
50+
(indexPatternSelectComponent = indexPatternSelect);
51+
export const getIndexPatternSelectComponent = () => indexPatternSelectComponent;
52+
53+
let coreHttp;
54+
export const setHttp = http => (coreHttp = http);
55+
export const getHttp = () => coreHttp;
56+
57+
let dataTimeFilter;
58+
export const setTimeFilter = timeFilter => (dataTimeFilter = timeFilter);
59+
export const getTimeFilter = () => dataTimeFilter;
60+
61+
let toast;
62+
export const setToasts = notificationToast => (toast = notificationToast);
63+
export const getToasts = () => toast;
64+
3465
export async function fetchSearchSourceAndRecordWithInspector({
3566
searchSource,
3667
requestId,

0 commit comments

Comments
 (0)