Skip to content

Commit 11b6f7f

Browse files
author
Aaron Caldwell
authored
[Maps] Update remaining client dependencies to NP (#63297)
* Routes dependencies updated (except for routes itself) * Replace all chrome deps except map controller * Replace npSetup and npStart with normal plugin init logic. Some clean up * Bind kibana services in map controller * Use kibana services in map controller * Convert remaining deps that aren't critical to legacy operation * Remove last angular bindings to gis map saved object loader * Consolidate kibana services in NP * Some fixes. Remove console logs * Fix type errors * Fix jest test path refs * Accomodate legacy 'hacks' and init services for vis type alias * Review feedback. Remove/update unused declarations * getFileUpload actually just needed Component tacked on the end * Handle visibility of toolbars for full screen mode using new core chrome. Should fix test * Import source types in getInitialLayers to ensure registry
1 parent a3f4acf commit 11b6f7f

33 files changed

+328
-202
lines changed

x-pack/legacy/plugins/maps/public/actions/map_actions.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
jest.mock('../selectors/map_selectors', () => ({}));
8-
jest.mock('../kibana_services', () => ({}));
8+
jest.mock('../../../../../plugins/maps/public/kibana_services', () => ({}));
99

1010
import { mapExtentChanged, setMouseCoordinates } from './map_actions';
1111

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,28 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import _ from 'lodash';
7+
// Import each layer type, even those not used, to init in registry
8+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
9+
import '../../../../../plugins/maps/public/layers/sources/wms_source';
10+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
11+
import '../../../../../plugins/maps/public/layers/sources/ems_file_source';
12+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
13+
import '../../../../../plugins/maps/public/layers/sources/es_search_source';
14+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
15+
import '../../../../../plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source';
16+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
17+
import '../../../../../plugins/maps/public/layers/sources/kibana_regionmap_source';
18+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
19+
import '../../../../../plugins/maps/public/layers/sources/es_geo_grid_source';
20+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
21+
import '../../../../../plugins/maps/public/layers/sources/xyz_tms_source';
22+
723
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
824
import { KibanaTilemapSource } from '../../../../../plugins/maps/public/layers/sources/kibana_tilemap_source';
925
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1026
import { EMSTMSSource } from '../../../../../plugins/maps/public/layers/sources/ems_tms_source';
11-
import { getInjectedVarFunc } from '../kibana_services';
27+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
28+
import { getInjectedVarFunc } from '../../../../../plugins/maps/public/kibana_services';
1229
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1330
import { getKibanaTileMap } from '../../../../../plugins/maps/public/meta';
1431

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
jest.mock('../../../../../plugins/maps/public/meta', () => {
88
return {};
99
});
10-
jest.mock('../kibana_services');
10+
jest.mock('../../../../../plugins/maps/public/kibana_services');
1111

1212
import { getInitialLayers } from './get_initial_layers';
1313

1414
const layerListNotProvided = undefined;
1515

1616
describe('Saved object has layer list', () => {
1717
beforeEach(() => {
18-
require('../kibana_services').getInjectedVarFunc = () => jest.fn();
18+
require('../../../../../plugins/maps/public/kibana_services').getInjectedVarFunc = () =>
19+
jest.fn();
1920
});
2021

2122
it('Should get initial layers from saved object', () => {
@@ -65,7 +66,7 @@ describe('EMS is enabled', () => {
6566
require('../../../../../plugins/maps/public/meta').getKibanaTileMap = () => {
6667
return null;
6768
};
68-
require('../kibana_services').getInjectedVarFunc = () => key => {
69+
require('../../../../../plugins/maps/public/kibana_services').getInjectedVarFunc = () => key => {
6970
switch (key) {
7071
case 'emsTileLayerId':
7172
return {
@@ -110,7 +111,7 @@ describe('EMS is not enabled', () => {
110111
return null;
111112
};
112113

113-
require('../kibana_services').getInjectedVarFunc = () => key => {
114+
require('../../../../../plugins/maps/public/kibana_services').getInjectedVarFunc = () => key => {
114115
switch (key) {
115116
case 'isEmsEnabled':
116117
return false;

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

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

7-
import chrome from 'ui/chrome';
8-
9-
const settings = chrome.getUiSettingsClient();
7+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
8+
import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services';
109

1110
export function getInitialQuery({ mapStateJSON, appState = {}, userQueryLanguage }) {
11+
const settings = getUiSettings();
12+
1213
if (appState.query) {
1314
return appState.query;
1415
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
import chrome from 'ui/chrome';
7-
8-
const uiSettings = chrome.getUiSettingsClient();
6+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
7+
import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services';
98

109
export function getInitialRefreshConfig({ mapStateJSON, globalState = {} }) {
10+
const uiSettings = getUiSettings();
11+
1112
if (mapStateJSON) {
1213
const mapState = JSON.parse(mapStateJSON);
1314
if (mapState.refreshConfig) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
import chrome from 'ui/chrome';
7-
8-
const uiSettings = chrome.getUiSettingsClient();
6+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
7+
import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services';
98

109
export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) {
1110
if (mapStateJSON) {
@@ -15,6 +14,6 @@ export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) {
1514
}
1615
}
1716

18-
const defaultTime = uiSettings.get('timepicker:timeDefaults');
17+
const defaultTime = getUiSettings().get('timepicker:timeDefaults');
1918
return { ...defaultTime, ...globalState.time };
2019
}

x-pack/legacy/plugins/maps/public/angular/map.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<div id="maps-top-nav">
44
<div>
55
<kbn-top-nav
6-
ng-show="chrome.getVisible()"
6+
ng-show="isVisible"
77
app-name="'maps'"
88
config="topNavMenu"
9-
show-search-bar="chrome.getVisible()"
10-
show-filter-bar="chrome.getVisible()"
9+
show-search-bar="isVisible"
10+
show-filter-bar="isVisible"
1111
show-date-picker="showDatePicker"
1212
show-save-query="showSaveQuery"
1313
query="query"

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

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@
55
*/
66

77
import _ from 'lodash';
8-
import chrome from 'ui/chrome';
98
import rison from 'rison-node';
109
import 'ui/directives/listen';
1110
import 'ui/directives/storage';
1211
import React from 'react';
1312
import { I18nProvider } from '@kbn/i18n/react';
1413
import { i18n } from '@kbn/i18n';
15-
import { capabilities } from 'ui/capabilities';
1614
import { render, unmountComponentAtNode } from 'react-dom';
1715
import { uiModules } from 'ui/modules';
18-
import { getTimeFilter, getIndexPatternService, getInspector } from '../kibana_services';
19-
import { Provider } from 'react-redux';
16+
import {
17+
getTimeFilter,
18+
getIndexPatternService,
19+
getInspector,
20+
getNavigation,
21+
getData,
22+
getCoreI18n,
23+
getCoreChrome,
24+
getMapsCapabilities,
25+
getToasts,
26+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
27+
} from '../../../../../plugins/maps/public/kibana_services';
2028
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2129
import { createMapStore } from '../../../../../plugins/maps/public/reducers/store';
30+
import { Provider } from 'react-redux';
2231
import { GisMap } from '../connected_components/gis_map';
2332
import { addHelpMenuToAppChrome } from '../help_menu_util';
2433
import {
@@ -51,29 +60,33 @@ import {
5160
} from '../selectors/map_selectors';
5261
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
5362
import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
54-
import { docTitle } from 'ui/doc_title';
55-
56-
import { toastNotifications } from 'ui/notify';
5763
import { getInitialLayers } from './get_initial_layers';
5864
import { getInitialQuery } from './get_initial_query';
5965
import { getInitialTimeFilters } from './get_initial_time_filters';
6066
import { getInitialRefreshConfig } from './get_initial_refresh_config';
6167
import { MAP_SAVED_OBJECT_TYPE, MAP_APP_PATH } from '../../common/constants';
62-
import { npStart } from 'ui/new_platform';
68+
import { npSetup, npStart } from 'ui/new_platform';
6369
import { esFilters } from '../../../../../../src/plugins/data/public';
6470
import {
6571
SavedObjectSaveModal,
6672
showSaveModal,
6773
} from '../../../../../../src/plugins/saved_objects/public';
6874
import { loadKbnTopNavDirectives } from '../../../../../../src/plugins/kibana_legacy/public';
69-
loadKbnTopNavDirectives(npStart.plugins.navigation.ui);
70-
71-
const savedQueryService = npStart.plugins.data.query.savedQueries;
75+
import {
76+
bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins,
77+
bindStartCoreAndPlugins as bindNpStartCoreAndPlugins,
78+
} from '../../../../../plugins/maps/public/plugin'; // eslint-disable-line @kbn/eslint/no-restricted-paths
7279

7380
const REACT_ANCHOR_DOM_ELEMENT_ID = 'react-maps-root';
7481

7582
const app = uiModules.get(MAP_APP_PATH, []);
7683

84+
// Init required services. Necessary while in legacy
85+
bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
86+
bindNpStartCoreAndPlugins(npStart.core, npStart.plugins);
87+
88+
loadKbnTopNavDirectives(getNavigation().ui);
89+
7790
function getInitialLayersFromUrlParam() {
7891
const locationSplit = window.location.href.split('?');
7992
if (locationSplit.length <= 1) {
@@ -87,7 +100,7 @@ function getInitialLayersFromUrlParam() {
87100
try {
88101
return rison.decode_array(mapAppParams.get('initialLayers'));
89102
} catch (e) {
90-
toastNotifications.addWarning({
103+
getToasts().addWarning({
91104
title: i18n.translate('xpack.maps.initialLayers.unableToParseTitle', {
92105
defaultMessage: `Inital layers not added to map`,
93106
}),
@@ -103,7 +116,8 @@ function getInitialLayersFromUrlParam() {
103116
app.controller(
104117
'GisMapController',
105118
($scope, $route, kbnUrl, localStorage, AppState, globalState) => {
106-
const { filterManager } = npStart.plugins.data.query;
119+
const savedQueryService = getData().query.savedQueries;
120+
const { filterManager } = getData().query;
107121
const savedMap = $route.current.locals.map;
108122
$scope.screenTitle = savedMap.title;
109123
let unsubscribe;
@@ -115,6 +129,14 @@ app.controller(
115129
return _.get($state, 'filters', []);
116130
}
117131

132+
const visibleSubscription = getCoreChrome()
133+
.getIsVisible$()
134+
.subscribe(isVisible => {
135+
$scope.$evalAsync(() => {
136+
$scope.isVisible = isVisible;
137+
});
138+
});
139+
118140
$scope.$listen(globalState, 'fetch_with_changes', diff => {
119141
if (diff.includes('time') || diff.includes('filters')) {
120142
onQueryChange({
@@ -169,10 +191,10 @@ app.controller(
169191
});
170192

171193
/* Saved Queries */
172-
$scope.showSaveQuery = capabilities.get().maps.saveQuery;
194+
$scope.showSaveQuery = getMapsCapabilities().saveQuery;
173195

174196
$scope.$watch(
175-
() => capabilities.get().maps.saveQuery,
197+
() => getMapsCapabilities().saveQuery,
176198
newCapability => {
177199
$scope.showSaveQuery = newCapability;
178200
}
@@ -342,7 +364,7 @@ app.controller(
342364
// clear old UI state
343365
store.dispatch(setSelectedLayer(null));
344366
store.dispatch(updateFlyout(FLYOUT_STATE.NONE));
345-
store.dispatch(setReadOnly(!capabilities.get().maps.save));
367+
store.dispatch(setReadOnly(!getMapsCapabilities().save));
346368

347369
handleStoreChanges(store);
348370
unsubscribe = store.subscribe(() => {
@@ -446,6 +468,8 @@ app.controller(
446468

447469
$scope.$on('$destroy', () => {
448470
window.removeEventListener('beforeunload', beforeUnload);
471+
visibleSubscription.unsubscribe();
472+
getCoreChrome().setIsVisible(true);
449473

450474
if (unsubscribe) {
451475
unsubscribe();
@@ -457,7 +481,7 @@ app.controller(
457481
});
458482

459483
const updateBreadcrumbs = () => {
460-
chrome.breadcrumbs.set([
484+
getCoreChrome().setBreadcrumbs([
461485
{
462486
text: i18n.translate('xpack.maps.mapController.mapsBreadcrumbLabel', {
463487
defaultMessage: 'Maps',
@@ -482,7 +506,7 @@ app.controller(
482506
};
483507
updateBreadcrumbs();
484508

485-
addHelpMenuToAppChrome(chrome);
509+
addHelpMenuToAppChrome();
486510

487511
async function doSave(saveOptions) {
488512
await store.dispatch(clearTransientLayerStateAndCloseFlyout());
@@ -491,9 +515,9 @@ app.controller(
491515

492516
try {
493517
id = await savedMap.save(saveOptions);
494-
docTitle.change(savedMap.title);
518+
getCoreChrome().docTitle.change(savedMap.title);
495519
} catch (err) {
496-
toastNotifications.addDanger({
520+
getToasts().addDanger({
497521
title: i18n.translate('xpack.maps.mapController.saveErrorMessage', {
498522
defaultMessage: `Error on saving '{title}'`,
499523
values: { title: savedMap.title },
@@ -505,7 +529,7 @@ app.controller(
505529
}
506530

507531
if (id) {
508-
toastNotifications.addSuccess({
532+
getToasts().addSuccess({
509533
title: i18n.translate('xpack.maps.mapController.saveSuccessMessage', {
510534
defaultMessage: `Saved '{title}'`,
511535
values: { title: savedMap.title },
@@ -539,6 +563,7 @@ app.controller(
539563
}),
540564
testId: 'mapsFullScreenMode',
541565
run() {
566+
getCoreChrome().setIsVisible(false);
542567
store.dispatch(enableFullScreen());
543568
},
544569
},
@@ -556,7 +581,7 @@ app.controller(
556581
getInspector().open(inspectorAdapters, {});
557582
},
558583
},
559-
...(capabilities.get().maps.save
584+
...(getMapsCapabilities().save
560585
? [
561586
{
562587
id: 'save',
@@ -611,7 +636,7 @@ app.controller(
611636
showDescription={false}
612637
/>
613638
);
614-
showSaveModal(saveModal, npStart.core.i18n.Context);
639+
showSaveModal(saveModal, getCoreI18n().Context);
615640
},
616641
},
617642
]

x-pack/legacy/plugins/maps/public/angular/services/gis_map_saved_object_loader.js

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

7+
import _ from 'lodash';
78
import { createSavedGisMapClass } from './saved_gis_map';
8-
import { uiModules } from 'ui/modules';
99
import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public';
10-
import { npStart } from '../../../../../../../src/legacy/ui/public/new_platform';
10+
import {
11+
getCoreChrome,
12+
getSavedObjectsClient,
13+
getIndexPatternService,
14+
getCoreOverlays,
15+
getData,
16+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
17+
} from '../../../../../../plugins/maps/public/kibana_services';
1118

12-
const module = uiModules.get('app/maps');
13-
14-
// This is the only thing that gets injected into controllers
15-
module.service('gisMapSavedObjectLoader', function() {
16-
const savedObjectsClient = npStart.core.savedObjects.client;
19+
export const getMapsSavedObjectLoader = _.once(function() {
1720
const services = {
18-
savedObjectsClient,
19-
indexPatterns: npStart.plugins.data.indexPatterns,
20-
search: npStart.plugins.data.search,
21-
chrome: npStart.core.chrome,
22-
overlays: npStart.core.overlays,
21+
savedObjectsClient: getSavedObjectsClient(),
22+
indexPatterns: getIndexPatternService(),
23+
search: getData().search,
24+
chrome: getCoreChrome(),
25+
overlays: getCoreOverlays(),
2326
};
2427
const SavedGisMap = createSavedGisMapClass(services);
2528

26-
return new SavedObjectLoader(SavedGisMap, npStart.core.savedObjects.client, npStart.core.chrome);
29+
return new SavedObjectLoader(SavedGisMap, getSavedObjectsClient(), getCoreChrome());
2730
});

0 commit comments

Comments
 (0)