[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
This commit is contained in:
Aaron Caldwell 2020-04-16 05:49:53 -06:00 committed by GitHub
parent a3f4acfc27
commit 11b6f7fc7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 328 additions and 202 deletions

View file

@ -5,7 +5,7 @@
*/ */
jest.mock('../selectors/map_selectors', () => ({})); jest.mock('../selectors/map_selectors', () => ({}));
jest.mock('../kibana_services', () => ({})); jest.mock('../../../../../plugins/maps/public/kibana_services', () => ({}));
import { mapExtentChanged, setMouseCoordinates } from './map_actions'; import { mapExtentChanged, setMouseCoordinates } from './map_actions';

View file

@ -4,11 +4,28 @@
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
import _ from 'lodash'; import _ from 'lodash';
// Import each layer type, even those not used, to init in registry
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import '../../../../../plugins/maps/public/layers/sources/wms_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import '../../../../../plugins/maps/public/layers/sources/ems_file_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import '../../../../../plugins/maps/public/layers/sources/es_search_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import '../../../../../plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import '../../../../../plugins/maps/public/layers/sources/kibana_regionmap_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import '../../../../../plugins/maps/public/layers/sources/es_geo_grid_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import '../../../../../plugins/maps/public/layers/sources/xyz_tms_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { KibanaTilemapSource } from '../../../../../plugins/maps/public/layers/sources/kibana_tilemap_source'; import { KibanaTilemapSource } from '../../../../../plugins/maps/public/layers/sources/kibana_tilemap_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { EMSTMSSource } from '../../../../../plugins/maps/public/layers/sources/ems_tms_source'; import { EMSTMSSource } from '../../../../../plugins/maps/public/layers/sources/ems_tms_source';
import { getInjectedVarFunc } from '../kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getInjectedVarFunc } from '../../../../../plugins/maps/public/kibana_services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getKibanaTileMap } from '../../../../../plugins/maps/public/meta'; import { getKibanaTileMap } from '../../../../../plugins/maps/public/meta';

View file

@ -7,7 +7,7 @@
jest.mock('../../../../../plugins/maps/public/meta', () => { jest.mock('../../../../../plugins/maps/public/meta', () => {
return {}; return {};
}); });
jest.mock('../kibana_services'); jest.mock('../../../../../plugins/maps/public/kibana_services');
import { getInitialLayers } from './get_initial_layers'; import { getInitialLayers } from './get_initial_layers';
@ -15,7 +15,8 @@ const layerListNotProvided = undefined;
describe('Saved object has layer list', () => { describe('Saved object has layer list', () => {
beforeEach(() => { beforeEach(() => {
require('../kibana_services').getInjectedVarFunc = () => jest.fn(); require('../../../../../plugins/maps/public/kibana_services').getInjectedVarFunc = () =>
jest.fn();
}); });
it('Should get initial layers from saved object', () => { it('Should get initial layers from saved object', () => {
@ -65,7 +66,7 @@ describe('EMS is enabled', () => {
require('../../../../../plugins/maps/public/meta').getKibanaTileMap = () => { require('../../../../../plugins/maps/public/meta').getKibanaTileMap = () => {
return null; return null;
}; };
require('../kibana_services').getInjectedVarFunc = () => key => { require('../../../../../plugins/maps/public/kibana_services').getInjectedVarFunc = () => key => {
switch (key) { switch (key) {
case 'emsTileLayerId': case 'emsTileLayerId':
return { return {
@ -110,7 +111,7 @@ describe('EMS is not enabled', () => {
return null; return null;
}; };
require('../kibana_services').getInjectedVarFunc = () => key => { require('../../../../../plugins/maps/public/kibana_services').getInjectedVarFunc = () => key => {
switch (key) { switch (key) {
case 'isEmsEnabled': case 'isEmsEnabled':
return false; return false;

View file

@ -4,11 +4,12 @@
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
import chrome from 'ui/chrome'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services';
const settings = chrome.getUiSettingsClient();
export function getInitialQuery({ mapStateJSON, appState = {}, userQueryLanguage }) { export function getInitialQuery({ mapStateJSON, appState = {}, userQueryLanguage }) {
const settings = getUiSettings();
if (appState.query) { if (appState.query) {
return appState.query; return appState.query;
} }

View file

@ -3,11 +3,12 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
import chrome from 'ui/chrome'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services';
const uiSettings = chrome.getUiSettingsClient();
export function getInitialRefreshConfig({ mapStateJSON, globalState = {} }) { export function getInitialRefreshConfig({ mapStateJSON, globalState = {} }) {
const uiSettings = getUiSettings();
if (mapStateJSON) { if (mapStateJSON) {
const mapState = JSON.parse(mapStateJSON); const mapState = JSON.parse(mapStateJSON);
if (mapState.refreshConfig) { if (mapState.refreshConfig) {

View file

@ -3,9 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
import chrome from 'ui/chrome'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services';
const uiSettings = chrome.getUiSettingsClient();
export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) { export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) {
if (mapStateJSON) { if (mapStateJSON) {
@ -15,6 +14,6 @@ export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) {
} }
} }
const defaultTime = uiSettings.get('timepicker:timeDefaults'); const defaultTime = getUiSettings().get('timepicker:timeDefaults');
return { ...defaultTime, ...globalState.time }; return { ...defaultTime, ...globalState.time };
} }

View file

@ -3,11 +3,11 @@
<div id="maps-top-nav"> <div id="maps-top-nav">
<div> <div>
<kbn-top-nav <kbn-top-nav
ng-show="chrome.getVisible()" ng-show="isVisible"
app-name="'maps'" app-name="'maps'"
config="topNavMenu" config="topNavMenu"
show-search-bar="chrome.getVisible()" show-search-bar="isVisible"
show-filter-bar="chrome.getVisible()" show-filter-bar="isVisible"
show-date-picker="showDatePicker" show-date-picker="showDatePicker"
show-save-query="showSaveQuery" show-save-query="showSaveQuery"
query="query" query="query"

View file

@ -5,20 +5,29 @@
*/ */
import _ from 'lodash'; import _ from 'lodash';
import chrome from 'ui/chrome';
import rison from 'rison-node'; import rison from 'rison-node';
import 'ui/directives/listen'; import 'ui/directives/listen';
import 'ui/directives/storage'; import 'ui/directives/storage';
import React from 'react'; import React from 'react';
import { I18nProvider } from '@kbn/i18n/react'; import { I18nProvider } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { capabilities } from 'ui/capabilities';
import { render, unmountComponentAtNode } from 'react-dom'; import { render, unmountComponentAtNode } from 'react-dom';
import { uiModules } from 'ui/modules'; import { uiModules } from 'ui/modules';
import { getTimeFilter, getIndexPatternService, getInspector } from '../kibana_services'; import {
import { Provider } from 'react-redux'; getTimeFilter,
getIndexPatternService,
getInspector,
getNavigation,
getData,
getCoreI18n,
getCoreChrome,
getMapsCapabilities,
getToasts,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../plugins/maps/public/kibana_services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; import { createMapStore } from '../../../../../plugins/maps/public/reducers/store';
import { Provider } from 'react-redux';
import { GisMap } from '../connected_components/gis_map'; import { GisMap } from '../connected_components/gis_map';
import { addHelpMenuToAppChrome } from '../help_menu_util'; import { addHelpMenuToAppChrome } from '../help_menu_util';
import { import {
@ -51,29 +60,33 @@ import {
} from '../selectors/map_selectors'; } from '../selectors/map_selectors';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
import { docTitle } from 'ui/doc_title';
import { toastNotifications } from 'ui/notify';
import { getInitialLayers } from './get_initial_layers'; import { getInitialLayers } from './get_initial_layers';
import { getInitialQuery } from './get_initial_query'; import { getInitialQuery } from './get_initial_query';
import { getInitialTimeFilters } from './get_initial_time_filters'; import { getInitialTimeFilters } from './get_initial_time_filters';
import { getInitialRefreshConfig } from './get_initial_refresh_config'; import { getInitialRefreshConfig } from './get_initial_refresh_config';
import { MAP_SAVED_OBJECT_TYPE, MAP_APP_PATH } from '../../common/constants'; import { MAP_SAVED_OBJECT_TYPE, MAP_APP_PATH } from '../../common/constants';
import { npStart } from 'ui/new_platform'; import { npSetup, npStart } from 'ui/new_platform';
import { esFilters } from '../../../../../../src/plugins/data/public'; import { esFilters } from '../../../../../../src/plugins/data/public';
import { import {
SavedObjectSaveModal, SavedObjectSaveModal,
showSaveModal, showSaveModal,
} from '../../../../../../src/plugins/saved_objects/public'; } from '../../../../../../src/plugins/saved_objects/public';
import { loadKbnTopNavDirectives } from '../../../../../../src/plugins/kibana_legacy/public'; import { loadKbnTopNavDirectives } from '../../../../../../src/plugins/kibana_legacy/public';
loadKbnTopNavDirectives(npStart.plugins.navigation.ui); import {
bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins,
const savedQueryService = npStart.plugins.data.query.savedQueries; bindStartCoreAndPlugins as bindNpStartCoreAndPlugins,
} from '../../../../../plugins/maps/public/plugin'; // eslint-disable-line @kbn/eslint/no-restricted-paths
const REACT_ANCHOR_DOM_ELEMENT_ID = 'react-maps-root'; const REACT_ANCHOR_DOM_ELEMENT_ID = 'react-maps-root';
const app = uiModules.get(MAP_APP_PATH, []); const app = uiModules.get(MAP_APP_PATH, []);
// Init required services. Necessary while in legacy
bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
bindNpStartCoreAndPlugins(npStart.core, npStart.plugins);
loadKbnTopNavDirectives(getNavigation().ui);
function getInitialLayersFromUrlParam() { function getInitialLayersFromUrlParam() {
const locationSplit = window.location.href.split('?'); const locationSplit = window.location.href.split('?');
if (locationSplit.length <= 1) { if (locationSplit.length <= 1) {
@ -87,7 +100,7 @@ function getInitialLayersFromUrlParam() {
try { try {
return rison.decode_array(mapAppParams.get('initialLayers')); return rison.decode_array(mapAppParams.get('initialLayers'));
} catch (e) { } catch (e) {
toastNotifications.addWarning({ getToasts().addWarning({
title: i18n.translate('xpack.maps.initialLayers.unableToParseTitle', { title: i18n.translate('xpack.maps.initialLayers.unableToParseTitle', {
defaultMessage: `Inital layers not added to map`, defaultMessage: `Inital layers not added to map`,
}), }),
@ -103,7 +116,8 @@ function getInitialLayersFromUrlParam() {
app.controller( app.controller(
'GisMapController', 'GisMapController',
($scope, $route, kbnUrl, localStorage, AppState, globalState) => { ($scope, $route, kbnUrl, localStorage, AppState, globalState) => {
const { filterManager } = npStart.plugins.data.query; const savedQueryService = getData().query.savedQueries;
const { filterManager } = getData().query;
const savedMap = $route.current.locals.map; const savedMap = $route.current.locals.map;
$scope.screenTitle = savedMap.title; $scope.screenTitle = savedMap.title;
let unsubscribe; let unsubscribe;
@ -115,6 +129,14 @@ app.controller(
return _.get($state, 'filters', []); return _.get($state, 'filters', []);
} }
const visibleSubscription = getCoreChrome()
.getIsVisible$()
.subscribe(isVisible => {
$scope.$evalAsync(() => {
$scope.isVisible = isVisible;
});
});
$scope.$listen(globalState, 'fetch_with_changes', diff => { $scope.$listen(globalState, 'fetch_with_changes', diff => {
if (diff.includes('time') || diff.includes('filters')) { if (diff.includes('time') || diff.includes('filters')) {
onQueryChange({ onQueryChange({
@ -169,10 +191,10 @@ app.controller(
}); });
/* Saved Queries */ /* Saved Queries */
$scope.showSaveQuery = capabilities.get().maps.saveQuery; $scope.showSaveQuery = getMapsCapabilities().saveQuery;
$scope.$watch( $scope.$watch(
() => capabilities.get().maps.saveQuery, () => getMapsCapabilities().saveQuery,
newCapability => { newCapability => {
$scope.showSaveQuery = newCapability; $scope.showSaveQuery = newCapability;
} }
@ -342,7 +364,7 @@ app.controller(
// clear old UI state // clear old UI state
store.dispatch(setSelectedLayer(null)); store.dispatch(setSelectedLayer(null));
store.dispatch(updateFlyout(FLYOUT_STATE.NONE)); store.dispatch(updateFlyout(FLYOUT_STATE.NONE));
store.dispatch(setReadOnly(!capabilities.get().maps.save)); store.dispatch(setReadOnly(!getMapsCapabilities().save));
handleStoreChanges(store); handleStoreChanges(store);
unsubscribe = store.subscribe(() => { unsubscribe = store.subscribe(() => {
@ -446,6 +468,8 @@ app.controller(
$scope.$on('$destroy', () => { $scope.$on('$destroy', () => {
window.removeEventListener('beforeunload', beforeUnload); window.removeEventListener('beforeunload', beforeUnload);
visibleSubscription.unsubscribe();
getCoreChrome().setIsVisible(true);
if (unsubscribe) { if (unsubscribe) {
unsubscribe(); unsubscribe();
@ -457,7 +481,7 @@ app.controller(
}); });
const updateBreadcrumbs = () => { const updateBreadcrumbs = () => {
chrome.breadcrumbs.set([ getCoreChrome().setBreadcrumbs([
{ {
text: i18n.translate('xpack.maps.mapController.mapsBreadcrumbLabel', { text: i18n.translate('xpack.maps.mapController.mapsBreadcrumbLabel', {
defaultMessage: 'Maps', defaultMessage: 'Maps',
@ -482,7 +506,7 @@ app.controller(
}; };
updateBreadcrumbs(); updateBreadcrumbs();
addHelpMenuToAppChrome(chrome); addHelpMenuToAppChrome();
async function doSave(saveOptions) { async function doSave(saveOptions) {
await store.dispatch(clearTransientLayerStateAndCloseFlyout()); await store.dispatch(clearTransientLayerStateAndCloseFlyout());
@ -491,9 +515,9 @@ app.controller(
try { try {
id = await savedMap.save(saveOptions); id = await savedMap.save(saveOptions);
docTitle.change(savedMap.title); getCoreChrome().docTitle.change(savedMap.title);
} catch (err) { } catch (err) {
toastNotifications.addDanger({ getToasts().addDanger({
title: i18n.translate('xpack.maps.mapController.saveErrorMessage', { title: i18n.translate('xpack.maps.mapController.saveErrorMessage', {
defaultMessage: `Error on saving '{title}'`, defaultMessage: `Error on saving '{title}'`,
values: { title: savedMap.title }, values: { title: savedMap.title },
@ -505,7 +529,7 @@ app.controller(
} }
if (id) { if (id) {
toastNotifications.addSuccess({ getToasts().addSuccess({
title: i18n.translate('xpack.maps.mapController.saveSuccessMessage', { title: i18n.translate('xpack.maps.mapController.saveSuccessMessage', {
defaultMessage: `Saved '{title}'`, defaultMessage: `Saved '{title}'`,
values: { title: savedMap.title }, values: { title: savedMap.title },
@ -539,6 +563,7 @@ app.controller(
}), }),
testId: 'mapsFullScreenMode', testId: 'mapsFullScreenMode',
run() { run() {
getCoreChrome().setIsVisible(false);
store.dispatch(enableFullScreen()); store.dispatch(enableFullScreen());
}, },
}, },
@ -556,7 +581,7 @@ app.controller(
getInspector().open(inspectorAdapters, {}); getInspector().open(inspectorAdapters, {});
}, },
}, },
...(capabilities.get().maps.save ...(getMapsCapabilities().save
? [ ? [
{ {
id: 'save', id: 'save',
@ -611,7 +636,7 @@ app.controller(
showDescription={false} showDescription={false}
/> />
); );
showSaveModal(saveModal, npStart.core.i18n.Context); showSaveModal(saveModal, getCoreI18n().Context);
}, },
}, },
] ]

View file

@ -4,24 +4,27 @@
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
import _ from 'lodash';
import { createSavedGisMapClass } from './saved_gis_map'; import { createSavedGisMapClass } from './saved_gis_map';
import { uiModules } from 'ui/modules';
import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public'; import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public';
import { npStart } from '../../../../../../../src/legacy/ui/public/new_platform'; import {
getCoreChrome,
getSavedObjectsClient,
getIndexPatternService,
getCoreOverlays,
getData,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../plugins/maps/public/kibana_services';
const module = uiModules.get('app/maps'); export const getMapsSavedObjectLoader = _.once(function() {
// This is the only thing that gets injected into controllers
module.service('gisMapSavedObjectLoader', function() {
const savedObjectsClient = npStart.core.savedObjects.client;
const services = { const services = {
savedObjectsClient, savedObjectsClient: getSavedObjectsClient(),
indexPatterns: npStart.plugins.data.indexPatterns, indexPatterns: getIndexPatternService(),
search: npStart.plugins.data.search, search: getData().search,
chrome: npStart.core.chrome, chrome: getCoreChrome(),
overlays: npStart.core.overlays, overlays: getCoreOverlays(),
}; };
const SavedGisMap = createSavedGisMapClass(services); const SavedGisMap = createSavedGisMapClass(services);
return new SavedObjectLoader(SavedGisMap, npStart.core.savedObjects.client, npStart.core.chrome); return new SavedObjectLoader(SavedGisMap, getSavedObjectsClient(), getCoreChrome());
}); });

View file

@ -7,7 +7,8 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import _ from 'lodash'; import _ from 'lodash';
import { toastNotifications } from 'ui/notify'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getToasts } from '../../../../../plugins/maps/public/kibana_services';
import { import {
EuiTitle, EuiTitle,
EuiFieldSearch, EuiFieldSearch,
@ -27,7 +28,6 @@ import {
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react'; import { FormattedMessage } from '@kbn/i18n/react';
import { addHelpMenuToAppChrome } from '../help_menu_util'; import { addHelpMenuToAppChrome } from '../help_menu_util';
import chrome from 'ui/chrome';
export const EMPTY_FILTER = ''; export const EMPTY_FILTER = '';
@ -55,7 +55,7 @@ export class MapListing extends React.Component {
componentDidMount() { componentDidMount() {
this.fetchItems(); this.fetchItems();
addHelpMenuToAppChrome(chrome); addHelpMenuToAppChrome();
} }
debouncedFetch = _.debounce(async filter => { debouncedFetch = _.debounce(async filter => {
@ -91,7 +91,7 @@ export class MapListing extends React.Component {
try { try {
await this.props.delete(this.state.selectedIds); await this.props.delete(this.state.selectedIds);
} catch (error) { } catch (error) {
toastNotifications.addDanger({ getToasts().addDanger({
title: i18n.translate('xpack.maps.mapListing.unableToDeleteToastTitle', { title: i18n.translate('xpack.maps.mapListing.unableToDeleteToastTitle', {
defaultMessage: `Unable to delete map(s)`, defaultMessage: `Unable to delete map(s)`,
}), }),

View file

@ -18,6 +18,8 @@ import {
getQueryableUniqueIndexPatternIds, getQueryableUniqueIndexPatternIds,
isToolbarOverlayHidden, isToolbarOverlayHidden,
} from '../../selectors/map_selectors'; } from '../../selectors/map_selectors';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getCoreChrome } from '../../../../../../plugins/maps/public/kibana_services';
function mapStateToProps(state = {}) { function mapStateToProps(state = {}) {
const flyoutDisplay = getFlyoutDisplay(state); const flyoutDisplay = getFlyoutDisplay(state);
@ -37,7 +39,10 @@ function mapStateToProps(state = {}) {
function mapDispatchToProps(dispatch) { function mapDispatchToProps(dispatch) {
return { return {
triggerRefreshTimer: () => dispatch(triggerRefreshTimer()), triggerRefreshTimer: () => dispatch(triggerRefreshTimer()),
exitFullScreen: () => dispatch(exitFullScreen()), exitFullScreen: () => {
dispatch(exitFullScreen());
getCoreChrome().setIsVisible(true);
},
cancelAllInFlightRequests: () => dispatch(cancelAllInFlightRequests()), cancelAllInFlightRequests: () => dispatch(cancelAllInFlightRequests()),
}; };
} }

View file

@ -12,7 +12,8 @@ import { ToolbarOverlay } from '../toolbar_overlay/index';
import { LayerPanel } from '../layer_panel/index'; import { LayerPanel } from '../layer_panel/index';
import { AddLayerPanel } from '../layer_addpanel/index'; import { AddLayerPanel } from '../layer_addpanel/index';
import { EuiFlexGroup, EuiFlexItem, EuiCallOut } from '@elastic/eui'; import { EuiFlexGroup, EuiFlexItem, EuiCallOut } from '@elastic/eui';
import { ExitFullScreenButton } from 'ui/exit_full_screen'; import { ExitFullScreenButton } from '../../../../../../../src/plugins/kibana_react/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getIndexPatternsFromIds } from '../../../../../../plugins/maps/public/index_pattern_util'; import { getIndexPatternsFromIds } from '../../../../../../plugins/maps/public/index_pattern_util';
import { ES_GEO_FIELD_TYPE } from '../../../common/constants'; import { ES_GEO_FIELD_TYPE } from '../../../common/constants';

View file

@ -20,12 +20,14 @@ import {
import { FormattedMessage } from '@kbn/i18n/react'; import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { getIndexPatternService } from '../../../kibana_services'; import {
getIndexPatternService,
getUiSettings,
getData,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../../plugins/maps/public/kibana_services';
import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox'; import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox';
import { npStart } from 'ui/new_platform';
const { SearchBar } = npStart.plugins.data.ui;
export class FilterEditor extends Component { export class FilterEditor extends Component {
state = { state = {
isPopoverOpen: false, isPopoverOpen: false,
@ -84,7 +86,8 @@ export class FilterEditor extends Component {
_renderQueryPopover() { _renderQueryPopover() {
const layerQuery = this.props.layer.getQuery(); const layerQuery = this.props.layer.getQuery();
const { uiSettings } = npStart.core; const uiSettings = getUiSettings();
const { SearchBar } = getData().ui;
return ( return (
<EuiPopover <EuiPopover

View file

@ -14,7 +14,8 @@ import { WhereExpression } from './where_expression';
import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox'; import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox';
import { indexPatterns } from '../../../../../../../../../src/plugins/data/public'; import { indexPatterns } from '../../../../../../../../../src/plugins/data/public';
import { getIndexPatternService } from '../../../../kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getIndexPatternService } from '../../../../../../../../plugins/maps/public/kibana_services';
export class Join extends Component { export class Join extends Component {
state = { state = {

View file

@ -24,7 +24,8 @@ import { getTermsFields } from '../../../../../../../../plugins/maps/public/inde
import { import {
getIndexPatternService, getIndexPatternService,
getIndexPatternSelectComponent, getIndexPatternSelectComponent,
} from '../../../../kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../../../plugins/maps/public/kibana_services';
export class JoinExpression extends Component { export class JoinExpression extends Component {
state = { state = {

View file

@ -8,8 +8,11 @@ import React, { Component } from 'react';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { EuiButton, EuiPopover, EuiExpression, EuiFormHelpText } from '@elastic/eui'; import { EuiButton, EuiPopover, EuiExpression, EuiFormHelpText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react'; import { FormattedMessage } from '@kbn/i18n/react';
import { npStart } from 'ui/new_platform'; import {
const { SearchBar } = npStart.plugins.data.ui; getUiSettings,
getData,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../../../plugins/maps/public/kibana_services';
export class WhereExpression extends Component { export class WhereExpression extends Component {
state = { state = {
@ -34,6 +37,7 @@ export class WhereExpression extends Component {
}; };
render() { render() {
const { SearchBar } = getData().ui;
const { whereQuery, indexPattern } = this.props; const { whereQuery, indexPattern } = this.props;
const expressionValue = const expressionValue =
whereQuery && whereQuery.query whereQuery && whereQuery.query
@ -42,8 +46,6 @@ export class WhereExpression extends Component {
defaultMessage: '-- add filter --', defaultMessage: '-- add filter --',
}); });
const { uiSettings } = npStart.core;
return ( return (
<EuiPopover <EuiPopover
id="whereClausePopover" id="whereClausePopover"
@ -81,7 +83,7 @@ export class WhereExpression extends Component {
query={ query={
whereQuery whereQuery
? whereQuery ? whereQuery
: { language: uiSettings.get('search:queryLanguage'), query: '' } : { language: getUiSettings().get('search:queryLanguage'), query: '' }
} }
onQuerySubmit={this._onQueryChange} onQuerySubmit={this._onQueryChange}
indexPatterns={[indexPattern]} indexPatterns={[indexPattern]}

View file

@ -30,12 +30,11 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react'; import { FormattedMessage } from '@kbn/i18n/react';
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public';
import { Storage } from '../../../../../../../src/plugins/kibana_utils/public'; import { Storage } from '../../../../../../../src/plugins/kibana_utils/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getData, getCore } from '../../../../../../plugins/maps/public/kibana_services';
const localStorage = new Storage(window.localStorage); const localStorage = new Storage(window.localStorage);
// This import will eventually become a dependency injected by the fully deangularized NP plugin.
import { npStart } from 'ui/new_platform';
export class LayerPanel extends React.Component { export class LayerPanel extends React.Component {
state = { state = {
displayName: '', displayName: '',
@ -168,8 +167,8 @@ export class LayerPanel extends React.Component {
services={{ services={{
appName: 'maps', appName: 'maps',
storage: localStorage, storage: localStorage,
data: npStart.plugins.data, data: getData(),
...npStart.core, ...getCore(),
}} }}
> >
<EuiFlexGroup direction="column" gutterSize="none"> <EuiFlexGroup direction="column" gutterSize="none">

View file

@ -12,7 +12,8 @@ import { i18n } from '@kbn/i18n';
import { createSpatialFilterWithGeometry } from '../../../../../../../plugins/maps/public/elasticsearch_geo_utils'; import { createSpatialFilterWithGeometry } from '../../../../../../../plugins/maps/public/elasticsearch_geo_utils';
import { GEO_JSON_TYPE } from '../../../../common/constants'; import { GEO_JSON_TYPE } from '../../../../common/constants';
import { GeometryFilterForm } from '../../../components/geometry_filter_form'; import { GeometryFilterForm } from '../../../components/geometry_filter_form';
import { UrlOverflowService } from 'ui/error_url_overflow'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { UrlOverflowService } from '../../../../../../../../src/plugins/kibana_legacy/public';
import rison from 'rison-node'; import rison from 'rison-node';
// over estimated and imprecise value to ensure filter has additional room for any meta keys added when filter is mapped. // over estimated and imprecise value to ensure filter has additional room for any meta keys added when filter is mapped.

View file

@ -18,7 +18,6 @@ import { DECIMAL_DEGREES_PRECISION, ZOOM_PRECISION } from '../../../../common/co
import mapboxgl from 'mapbox-gl/dist/mapbox-gl-csp'; import mapboxgl from 'mapbox-gl/dist/mapbox-gl-csp';
import mbWorkerUrl from '!!file-loader!mapbox-gl/dist/mapbox-gl-csp-worker'; import mbWorkerUrl from '!!file-loader!mapbox-gl/dist/mapbox-gl-csp-worker';
import mbRtlPlugin from '!!file-loader!@mapbox/mapbox-gl-rtl-text/mapbox-gl-rtl-text.min.js'; import mbRtlPlugin from '!!file-loader!@mapbox/mapbox-gl-rtl-text/mapbox-gl-rtl-text.min.js';
import chrome from 'ui/chrome';
import { spritesheet } from '@elastic/maki'; import { spritesheet } from '@elastic/maki';
import sprites1 from '@elastic/maki/dist/sprite@1.png'; import sprites1 from '@elastic/maki/dist/sprite@1.png';
import sprites2 from '@elastic/maki/dist/sprite@2.png'; import sprites2 from '@elastic/maki/dist/sprite@2.png';
@ -29,6 +28,8 @@ import {
clampToLonBounds, clampToLonBounds,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../../plugins/maps/public/elasticsearch_geo_utils'; } from '../../../../../../../plugins/maps/public/elasticsearch_geo_utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getInjectedVarFunc } from '../../../../../../../plugins/maps/public/kibana_services';
mapboxgl.workerUrl = mbWorkerUrl; mapboxgl.workerUrl = mbWorkerUrl;
mapboxgl.setRTLTextPlugin(mbRtlPlugin); mapboxgl.setRTLTextPlugin(mbRtlPlugin);
@ -129,7 +130,7 @@ export class MBMapContainer extends React.Component {
container: this.refs.mapContainer, container: this.refs.mapContainer,
style: mbStyle, style: mbStyle,
scrollZoom: this.props.scrollZoom, scrollZoom: this.props.scrollZoom,
preserveDrawingBuffer: chrome.getInjected('preserveDrawingBuffer', false), preserveDrawingBuffer: getInjectedVarFunc()('preserveDrawingBuffer', false),
interactive: !this.props.disableInteractive, interactive: !this.props.disableInteractive,
}; };
const initialView = _.get(this.props.goto, 'center'); const initialView = _.get(this.props.goto, 'center');

View file

@ -11,7 +11,6 @@ import { render, unmountComponentAtNode } from 'react-dom';
import 'mapbox-gl/dist/mapbox-gl.css'; import 'mapbox-gl/dist/mapbox-gl.css';
import { I18nContext } from 'ui/i18n'; import { I18nContext } from 'ui/i18n';
import { npStart } from 'ui/new_platform';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { Unsubscribe } from 'redux'; import { Unsubscribe } from 'redux';
import { import {
@ -59,6 +58,8 @@ import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_se
import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants'; import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { RenderToolTipContent } from '../../../../../plugins/maps/public/layers/tooltips/tooltip_property'; import { RenderToolTipContent } from '../../../../../plugins/maps/public/layers/tooltips/tooltip_property';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getUiActions } from '../../../../../plugins/maps/public/kibana_services';
interface MapEmbeddableConfig { interface MapEmbeddableConfig {
editUrl?: string; editUrl?: string;
@ -269,7 +270,7 @@ export class MapEmbeddable extends Embeddable<MapEmbeddableInput, MapEmbeddableO
} }
addFilters = (filters: Filter[]) => { addFilters = (filters: Filter[]) => {
npStart.plugins.uiActions.executeTriggerActions(APPLY_FILTER_TRIGGER, { getUiActions().executeTriggerActions(APPLY_FILTER_TRIGGER, {
embeddable: this, embeddable: this,
filters, filters,
}); });

View file

@ -5,14 +5,18 @@
*/ */
import _ from 'lodash'; import _ from 'lodash';
import chrome from 'ui/chrome';
import { capabilities } from 'ui/capabilities';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { npSetup, npStart } from 'ui/new_platform'; import { npSetup, npStart } from 'ui/new_platform';
import { SavedObjectLoader } from 'src/plugins/saved_objects/public';
import { IIndexPattern } from 'src/plugins/data/public'; import { IIndexPattern } from 'src/plugins/data/public';
// @ts-ignore
import { getMapsSavedObjectLoader } from '../angular/services/gis_map_saved_object_loader';
import { MapEmbeddable, MapEmbeddableInput } from './map_embeddable'; import { MapEmbeddable, MapEmbeddableInput } from './map_embeddable';
import { getIndexPatternService } from '../kibana_services'; import {
getIndexPatternService,
getHttp,
getMapsCapabilities,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../plugins/maps/public/kibana_services';
import { import {
EmbeddableFactoryDefinition, EmbeddableFactoryDefinition,
IContainer, IContainer,
@ -26,7 +30,6 @@ import { getQueryableUniqueIndexPatternIds } from '../selectors/map_selectors';
import { getInitialLayers } from '../angular/get_initial_layers'; import { getInitialLayers } from '../angular/get_initial_layers';
import { mergeInputWithSavedMap } from './merge_input_with_saved_map'; import { mergeInputWithSavedMap } from './merge_input_with_saved_map';
import '../angular/services/gis_map_saved_object_loader'; import '../angular/services/gis_map_saved_object_loader';
import { bindSetupCoreAndPlugins, bindStartCoreAndPlugins } from '../plugin';
// @ts-ignore // @ts-ignore
import { import {
bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins, bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins,
@ -44,14 +47,12 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition {
}; };
constructor() { constructor() {
// Init required services. Necessary while in legacy // Init required services. Necessary while in legacy
bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins); bindNpSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
bindStartCoreAndPlugins(npStart.core, npStart.plugins);
bindNpStartCoreAndPlugins(npStart.core, npStart.plugins); bindNpStartCoreAndPlugins(npStart.core, npStart.plugins);
} }
async isEditable() { async isEditable() {
return capabilities.get().maps.save as boolean; return getMapsCapabilities().save as boolean;
} }
// Not supported yet for maps types. // Not supported yet for maps types.
@ -96,8 +97,7 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition {
} }
async _fetchSavedMap(savedObjectId: string) { async _fetchSavedMap(savedObjectId: string) {
const $injector = await chrome.dangerouslyGetActiveInjector(); const savedObjectLoader = getMapsSavedObjectLoader();
const savedObjectLoader = $injector.get<SavedObjectLoader>('gisMapSavedObjectLoader');
return await savedObjectLoader.get(savedObjectId); return await savedObjectLoader.get(savedObjectId);
} }
@ -114,7 +114,7 @@ export class MapEmbeddableFactory implements EmbeddableFactoryDefinition {
{ {
layerList, layerList,
title: savedMap.title, title: savedMap.title,
editUrl: chrome.addBasePath(createMapPath(savedObjectId)), editUrl: getHttp().basePath.prepend(createMapPath(savedObjectId)),
indexPatterns, indexPatterns,
editable: await this.isEditable(), editable: await this.isEditable(),
}, },

View file

@ -3,10 +3,13 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getDocLinks, getCoreChrome } from '../../../../plugins/maps/public/kibana_services';
export function addHelpMenuToAppChrome(chrome) { export function addHelpMenuToAppChrome() {
chrome.helpExtension.set({ const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = getDocLinks();
getCoreChrome().setHelpExtension({
appName: 'Maps', appName: 'Maps',
links: [ links: [
{ {

View file

@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
import './kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import '../../../../plugins/maps/public/kibana_services';
// import the uiExports that we want to "use" // import the uiExports that we want to "use"
import 'uiExports/inspectorViews'; import 'uiExports/inspectorViews';

View file

@ -1,23 +0,0 @@
/*
* 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 { IIndexPattern } from 'src/plugins/data/public';
export function getIndexPatternService(): {
get: (id: string) => IIndexPattern | undefined;
};
export function setLicenseId(args: unknown): void;
export function setInspector(args: unknown): void;
export function setFileUpload(args: unknown): void;
export function setIndexPatternSelect(args: unknown): void;
export function setHttp(args: unknown): void;
export function setTimeFilter(args: unknown): void;
export function setUiSettings(args: unknown): void;
export function setInjectedVarFunc(args: unknown): void;
export function setToasts(args: unknown): void;
export function setIndexPatternService(args: unknown): void;
export function setAutocompleteService(args: unknown): void;

View file

@ -1,29 +0,0 @@
/*
* 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.
*/
let indexPatternService;
export const setIndexPatternService = dataIndexPatterns =>
(indexPatternService = dataIndexPatterns);
export const getIndexPatternService = () => indexPatternService;
let inspector;
export const setInspector = newInspector => (inspector = newInspector);
export const getInspector = () => {
return inspector;
};
let getInjectedVar;
export const setInjectedVarFunc = getInjectedVarFunc => (getInjectedVar = getInjectedVarFunc);
export const getInjectedVarFunc = () => getInjectedVar;
let indexPatternSelectComponent;
export const setIndexPatternSelect = indexPatternSelect =>
(indexPatternSelectComponent = indexPatternSelect);
export const getIndexPatternSelectComponent = () => indexPatternSelectComponent;
let dataTimeFilter;
export const setTimeFilter = timeFilter => (dataTimeFilter = timeFilter);
export const getTimeFilter = () => dataTimeFilter;

View file

@ -13,19 +13,11 @@ import '../../../../plugins/maps/public/layers/load_layer_wizards';
import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; import { Plugin, CoreStart, CoreSetup } from 'src/core/public';
// @ts-ignore // @ts-ignore
import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { Start as InspectorStartContract } from 'src/plugins/inspector/public'; import { Start as InspectorStartContract } from 'src/plugins/inspector/public';
// @ts-ignore // @ts-ignore
import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { MapListing } from './components/map_listing'; import { MapListing } from './components/map_listing';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import {
setInspector,
setIndexPatternSelect,
setTimeFilter,
setInjectedVarFunc,
setIndexPatternService,
} from './kibana_services';
// @ts-ignore // @ts-ignore
import { import {
bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins, bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins,
@ -62,20 +54,6 @@ interface MapsPluginStartDependencies {
// file_upload TODO: Export type from file upload and use here // file_upload TODO: Export type from file upload and use here
} }
export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => {
const { injectedMetadata } = core;
setInjectedVarFunc(injectedMetadata.getInjectedVar);
setInjectedVarFunc(core.injectedMetadata.getInjectedVar);
};
export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => {
const { data, inspector } = plugins;
setInspector(inspector);
setIndexPatternSelect(data.ui.IndexPatternSelect);
setTimeFilter(data.query.timefilter.timefilter);
setIndexPatternService(data.indexPatterns);
};
/** @internal */ /** @internal */
export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> { export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
public setup(core: CoreSetup, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) { public setup(core: CoreSetup, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) {
@ -85,14 +63,12 @@ export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
return reactDirective(wrapInI18nContext(MapListing)); return reactDirective(wrapInI18nContext(MapListing));
}); });
bindSetupCoreAndPlugins(core, np);
bindNpSetupCoreAndPlugins(core, np); bindNpSetupCoreAndPlugins(core, np);
np.home.featureCatalogue.register(featureCatalogueEntry); np.home.featureCatalogue.register(featureCatalogueEntry);
} }
public start(core: CoreStart, plugins: MapsPluginStartDependencies) { public start(core: CoreStart, plugins: MapsPluginStartDependencies) {
bindStartCoreAndPlugins(core, plugins);
bindNpStartCoreAndPlugins(core, plugins); bindNpStartCoreAndPlugins(core, plugins);
} }
} }

View file

@ -4,12 +4,20 @@
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
import chrome from 'ui/chrome';
import { npSetup } from '../../../../../src/legacy/ui/public/new_platform';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { APP_ID, APP_ICON, MAP_BASE_URL } from '../common/constants'; import { APP_ID, APP_ICON, MAP_BASE_URL } from '../common/constants';
import {
getInjectedVarFunc,
getVisualizations,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/maps/public/kibana_services';
import { npSetup } from 'ui/new_platform';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { bindSetupCoreAndPlugins } from '../../../../plugins/maps/public/plugin';
const showMapVisualizationTypes = chrome.getInjected('showMapVisualizationTypes', false); bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
const showMapVisualizationTypes = getInjectedVarFunc()('showMapVisualizationTypes', false);
const description = i18n.translate('xpack.maps.visTypeAlias.description', { const description = i18n.translate('xpack.maps.visTypeAlias.description', {
defaultMessage: 'Create and style maps with multiple layers and indices.', defaultMessage: 'Create and style maps with multiple layers and indices.',
@ -23,7 +31,7 @@ The Maps app offers more functionality and is easier to use.`,
} }
); );
npSetup.plugins.visualizations.registerAlias({ getVisualizations().registerAlias({
aliasUrl: MAP_BASE_URL, aliasUrl: MAP_BASE_URL,
name: APP_ID, name: APP_ID,
title: i18n.translate('xpack.maps.visTypeAlias.title', { title: i18n.translate('xpack.maps.visTypeAlias.title', {
@ -37,5 +45,5 @@ npSetup.plugins.visualizations.registerAlias({
}); });
if (!showMapVisualizationTypes) { if (!showMapVisualizationTypes) {
npSetup.plugins.visualizations.hideTypes(['region_map', 'tile_map']); getVisualizations().hideTypes(['region_map', 'tile_map']);
} }

View file

@ -5,20 +5,23 @@
*/ */
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { capabilities } from 'ui/capabilities';
import chrome from 'ui/chrome';
import routes from 'ui/routes'; import routes from 'ui/routes';
import { docTitle } from 'ui/doc_title';
import listingTemplate from './angular/listing_ng_wrapper.html'; import listingTemplate from './angular/listing_ng_wrapper.html';
import mapTemplate from './angular/map.html'; import mapTemplate from './angular/map.html';
import { npStart } from 'ui/new_platform'; import {
getSavedObjectsClient,
getCoreChrome,
getMapsCapabilities,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/maps/public/kibana_services';
import { getMapsSavedObjectLoader } from './angular/services/gis_map_saved_object_loader';
routes.enable(); routes.enable();
routes routes
.defaults(/.*/, { .defaults(/.*/, {
badge: uiCapabilities => { badge: () => {
if (uiCapabilities.maps.save) { if (getMapsCapabilities().save) {
return undefined; return undefined;
} }
@ -35,7 +38,8 @@ routes
}) })
.when('/', { .when('/', {
template: listingTemplate, template: listingTemplate,
controller($scope, gisMapSavedObjectLoader, config) { controller($scope, config) {
const gisMapSavedObjectLoader = getMapsSavedObjectLoader();
$scope.listingLimit = config.get('savedObjects:listingLimit'); $scope.listingLimit = config.get('savedObjects:listingLimit');
$scope.find = search => { $scope.find = search => {
return gisMapSavedObjectLoader.find(search, $scope.listingLimit); return gisMapSavedObjectLoader.find(search, $scope.listingLimit);
@ -43,19 +47,17 @@ routes
$scope.delete = ids => { $scope.delete = ids => {
return gisMapSavedObjectLoader.delete(ids); return gisMapSavedObjectLoader.delete(ids);
}; };
$scope.readOnly = !capabilities.get().maps.save; $scope.readOnly = !getMapsCapabilities().save;
}, },
resolve: { resolve: {
hasMaps: function(kbnUrl) { hasMaps: function(kbnUrl) {
chrome getSavedObjectsClient()
.getSavedObjectsClient()
.find({ type: 'map', perPage: 1 }) .find({ type: 'map', perPage: 1 })
.then(resp => { .then(resp => {
// Do not show empty listing page, just redirect to a new map // Do not show empty listing page, just redirect to a new map
if (resp.savedObjects.length === 0) { if (resp.savedObjects.length === 0) {
kbnUrl.redirect('/map'); kbnUrl.redirect('/map');
} }
return true; return true;
}); });
}, },
@ -65,7 +67,8 @@ routes
template: mapTemplate, template: mapTemplate,
controller: 'GisMapController', controller: 'GisMapController',
resolve: { resolve: {
map: function(gisMapSavedObjectLoader, redirectWhenMissing) { map: function(redirectWhenMissing) {
const gisMapSavedObjectLoader = getMapsSavedObjectLoader();
return gisMapSavedObjectLoader.get().catch( return gisMapSavedObjectLoader.get().catch(
redirectWhenMissing({ redirectWhenMissing({
map: '/', map: '/',
@ -78,13 +81,14 @@ routes
template: mapTemplate, template: mapTemplate,
controller: 'GisMapController', controller: 'GisMapController',
resolve: { resolve: {
map: function(gisMapSavedObjectLoader, redirectWhenMissing, $route) { map: function(redirectWhenMissing, $route) {
const gisMapSavedObjectLoader = getMapsSavedObjectLoader();
const id = $route.current.params.id; const id = $route.current.params.id;
return gisMapSavedObjectLoader return gisMapSavedObjectLoader
.get(id) .get(id)
.then(savedMap => { .then(savedMap => {
npStart.core.chrome.recentlyAccessed.add(savedMap.getFullPath(), savedMap.title, id); getCoreChrome().recentlyAccessed.add(savedMap.getFullPath(), savedMap.title, id);
docTitle.change(savedMap.title); getCoreChrome().docTitle.change(savedMap.title);
return savedMap; return savedMap;
}) })
.catch( .catch(

View file

@ -16,7 +16,8 @@ import { VectorLayer } from '../../../../../plugins/maps/public/layers/vector_la
import { HeatmapLayer } from '../../../../../plugins/maps/public/layers/heatmap_layer'; import { HeatmapLayer } from '../../../../../plugins/maps/public/layers/heatmap_layer';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { BlendedVectorLayer } from '../../../../../plugins/maps/public/layers/blended_vector_layer'; import { BlendedVectorLayer } from '../../../../../plugins/maps/public/layers/blended_vector_layer';
import { getTimeFilter } from '../kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getTimeFilter } from '../../../../../plugins/maps/public/kibana_services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths // eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
import { import {

View file

@ -14,7 +14,7 @@ jest.mock('../../../../../plugins/maps/public/reducers/non_serializable_instance
return {}; return {};
}, },
})); }));
jest.mock('../kibana_services', () => ({ jest.mock('../../../../../plugins/maps/public/kibana_services', () => ({
getTimeFilter: () => ({ getTimeFilter: () => ({
getTime: () => { getTime: () => {
return { return {

View file

@ -0,0 +1,55 @@
/*
* 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 { IIndexPattern } from 'src/plugins/data/public';
export function getLicenseId(): any;
export function getInspector(): any;
export function getFileUploadComponent(): any;
export function getIndexPatternSelectComponent(): any;
export function getHttp(): any;
export function getTimeFilter(): any;
export function getInjectedVarFunc(): any;
export function getToasts(): any;
export function getIndexPatternService(): {
get: (id: string) => IIndexPattern | undefined;
};
export function getAutocompleteService(): any;
export function getSavedObjectsClient(): any;
export function getMapsCapabilities(): any;
export function getVisualizations(): any;
export function getDocLinks(): any;
export function getCoreChrome(): any;
export function getUiSettings(): any;
export function getCoreOverlays(): any;
export function getData(): any;
export function getUiActions(): any;
export function getCore(): any;
export function getNavigation(): any;
export function getCoreI18n(): any;
export function setLicenseId(args: unknown): void;
export function setInspector(args: unknown): void;
export function setFileUpload(args: unknown): void;
export function setIndexPatternSelect(args: unknown): void;
export function setHttp(args: unknown): void;
export function setTimeFilter(args: unknown): void;
export function setInjectedVarFunc(args: unknown): void;
export function setToasts(args: unknown): void;
export function setIndexPatternService(args: unknown): void;
export function setAutocompleteService(args: unknown): void;
export function setSavedObjectsClient(args: unknown): void;
export function setMapsCapabilities(args: unknown): void;
export function setVisualizations(args: unknown): void;
export function setDocLinks(args: unknown): void;
export function setCoreChrome(args: unknown): void;
export function setUiSettings(args: unknown): void;
export function setCoreOverlays(args: unknown): void;
export function setData(args: unknown): void;
export function setUiActions(args: unknown): void;
export function setCore(args: unknown): void;
export function setNavigation(args: unknown): void;
export function setCoreI18n(args: unknown): void;

View file

@ -89,3 +89,49 @@ export async function fetchSearchSourceAndRecordWithInspector({
return resp; return resp;
} }
let savedObjectsClient;
export const setSavedObjectsClient = coreSavedObjectsClient =>
(savedObjectsClient = coreSavedObjectsClient);
export const getSavedObjectsClient = () => savedObjectsClient;
let chrome;
export const setCoreChrome = coreChrome => (chrome = coreChrome);
export const getCoreChrome = () => chrome;
let mapsCapabilities;
export const setMapsCapabilities = coreAppMapsCapabilities =>
(mapsCapabilities = coreAppMapsCapabilities);
export const getMapsCapabilities = () => mapsCapabilities;
let visualizations;
export const setVisualizations = visPlugin => (visualizations = visPlugin);
export const getVisualizations = () => visualizations;
let docLinks;
export const setDocLinks = coreDocLinks => (docLinks = coreDocLinks);
export const getDocLinks = () => docLinks;
let overlays;
export const setCoreOverlays = coreOverlays => (overlays = coreOverlays);
export const getCoreOverlays = () => overlays;
let data;
export const setData = dataPlugin => (data = dataPlugin);
export const getData = () => data;
let uiActions;
export const setUiActions = pluginUiActions => (uiActions = pluginUiActions);
export const getUiActions = () => uiActions;
let core;
export const setCore = kibanaCore => (core = kibanaCore);
export const getCore = () => core;
let navigation;
export const setNavigation = pluginNavigation => (navigation = pluginNavigation);
export const getNavigation = () => navigation;
let coreI18n;
export const setCoreI18n = kibanaCoreI18n => (coreI18n = kibanaCoreI18n);
export const getCoreI18n = () => coreI18n;

View file

@ -10,6 +10,12 @@ import { Setup as InspectorSetupContract } from 'src/plugins/inspector/public';
import { MapView } from './inspector/views/map_view'; import { MapView } from './inspector/views/map_view';
import { import {
setAutocompleteService, setAutocompleteService,
setCore,
setCoreChrome,
setCoreI18n,
setCoreOverlays,
setData,
setDocLinks,
setFileUpload, setFileUpload,
setHttp, setHttp,
setIndexPatternSelect, setIndexPatternSelect,
@ -17,9 +23,14 @@ import {
setInjectedVarFunc, setInjectedVarFunc,
setInspector, setInspector,
setLicenseId, setLicenseId,
setMapsCapabilities,
setNavigation,
setSavedObjectsClient,
setTimeFilter, setTimeFilter,
setToasts, setToasts,
setUiActions,
setUiSettings, setUiSettings,
setVisualizations,
// @ts-ignore // @ts-ignore
} from './kibana_services'; } from './kibana_services';
@ -31,15 +42,16 @@ export interface MapsPluginStartDependencies {}
export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => {
const { licensing } = plugins; const { licensing } = plugins;
const { injectedMetadata, http } = core; const { injectedMetadata, uiSettings, http, notifications } = core;
if (licensing) { if (licensing) {
licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid)); licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid));
} }
setInjectedVarFunc(injectedMetadata.getInjectedVar); setInjectedVarFunc(injectedMetadata.getInjectedVar);
setHttp(http); setHttp(http);
setUiSettings(core.uiSettings); setToasts(notifications.toasts);
setInjectedVarFunc(core.injectedMetadata.getInjectedVar); setInjectedVarFunc(injectedMetadata.getInjectedVar);
setToasts(core.notifications.toasts); setVisualizations(plugins.visualizations);
setUiSettings(uiSettings);
}; };
export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => {
@ -50,6 +62,16 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => {
setTimeFilter(data.query.timefilter.timefilter); setTimeFilter(data.query.timefilter.timefilter);
setIndexPatternService(data.indexPatterns); setIndexPatternService(data.indexPatterns);
setAutocompleteService(data.autocomplete); setAutocompleteService(data.autocomplete);
setCore(core);
setSavedObjectsClient(core.savedObjects.client);
setCoreChrome(core.chrome);
setCoreOverlays(core.overlays);
setMapsCapabilities(core.application.capabilities.maps);
setDocLinks(core.docLinks);
setData(plugins.data);
setUiActions(plugins.uiActions);
setNavigation(plugins.navigation);
setCoreI18n(core.i18n);
}; };
/** /**