[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('../kibana_services', () => ({}));
jest.mock('../../../../../plugins/maps/public/kibana_services', () => ({}));
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.
*/
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
import { KibanaTilemapSource } from '../../../../../plugins/maps/public/layers/sources/kibana_tilemap_source';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
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
import { getKibanaTileMap } from '../../../../../plugins/maps/public/meta';

View file

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

View file

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

View file

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

View file

@ -3,9 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import chrome from 'ui/chrome';
const uiSettings = chrome.getUiSettingsClient();
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getUiSettings } from '../../../../../plugins/maps/public/kibana_services';
export function getInitialTimeFilters({ mapStateJSON, globalState = {} }) {
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 };
}

View file

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

View file

@ -5,20 +5,29 @@
*/
import _ from 'lodash';
import chrome from 'ui/chrome';
import rison from 'rison-node';
import 'ui/directives/listen';
import 'ui/directives/storage';
import React from 'react';
import { I18nProvider } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { capabilities } from 'ui/capabilities';
import { render, unmountComponentAtNode } from 'react-dom';
import { uiModules } from 'ui/modules';
import { getTimeFilter, getIndexPatternService, getInspector } from '../kibana_services';
import { Provider } from 'react-redux';
import {
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
import { createMapStore } from '../../../../../plugins/maps/public/reducers/store';
import { Provider } from 'react-redux';
import { GisMap } from '../connected_components/gis_map';
import { addHelpMenuToAppChrome } from '../help_menu_util';
import {
@ -51,29 +60,33 @@ import {
} from '../selectors/map_selectors';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
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 { getInitialQuery } from './get_initial_query';
import { getInitialTimeFilters } from './get_initial_time_filters';
import { getInitialRefreshConfig } from './get_initial_refresh_config';
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 {
SavedObjectSaveModal,
showSaveModal,
} from '../../../../../../src/plugins/saved_objects/public';
import { loadKbnTopNavDirectives } from '../../../../../../src/plugins/kibana_legacy/public';
loadKbnTopNavDirectives(npStart.plugins.navigation.ui);
const savedQueryService = npStart.plugins.data.query.savedQueries;
import {
bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins,
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 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() {
const locationSplit = window.location.href.split('?');
if (locationSplit.length <= 1) {
@ -87,7 +100,7 @@ function getInitialLayersFromUrlParam() {
try {
return rison.decode_array(mapAppParams.get('initialLayers'));
} catch (e) {
toastNotifications.addWarning({
getToasts().addWarning({
title: i18n.translate('xpack.maps.initialLayers.unableToParseTitle', {
defaultMessage: `Inital layers not added to map`,
}),
@ -103,7 +116,8 @@ function getInitialLayersFromUrlParam() {
app.controller(
'GisMapController',
($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;
$scope.screenTitle = savedMap.title;
let unsubscribe;
@ -115,6 +129,14 @@ app.controller(
return _.get($state, 'filters', []);
}
const visibleSubscription = getCoreChrome()
.getIsVisible$()
.subscribe(isVisible => {
$scope.$evalAsync(() => {
$scope.isVisible = isVisible;
});
});
$scope.$listen(globalState, 'fetch_with_changes', diff => {
if (diff.includes('time') || diff.includes('filters')) {
onQueryChange({
@ -169,10 +191,10 @@ app.controller(
});
/* Saved Queries */
$scope.showSaveQuery = capabilities.get().maps.saveQuery;
$scope.showSaveQuery = getMapsCapabilities().saveQuery;
$scope.$watch(
() => capabilities.get().maps.saveQuery,
() => getMapsCapabilities().saveQuery,
newCapability => {
$scope.showSaveQuery = newCapability;
}
@ -342,7 +364,7 @@ app.controller(
// clear old UI state
store.dispatch(setSelectedLayer(null));
store.dispatch(updateFlyout(FLYOUT_STATE.NONE));
store.dispatch(setReadOnly(!capabilities.get().maps.save));
store.dispatch(setReadOnly(!getMapsCapabilities().save));
handleStoreChanges(store);
unsubscribe = store.subscribe(() => {
@ -446,6 +468,8 @@ app.controller(
$scope.$on('$destroy', () => {
window.removeEventListener('beforeunload', beforeUnload);
visibleSubscription.unsubscribe();
getCoreChrome().setIsVisible(true);
if (unsubscribe) {
unsubscribe();
@ -457,7 +481,7 @@ app.controller(
});
const updateBreadcrumbs = () => {
chrome.breadcrumbs.set([
getCoreChrome().setBreadcrumbs([
{
text: i18n.translate('xpack.maps.mapController.mapsBreadcrumbLabel', {
defaultMessage: 'Maps',
@ -482,7 +506,7 @@ app.controller(
};
updateBreadcrumbs();
addHelpMenuToAppChrome(chrome);
addHelpMenuToAppChrome();
async function doSave(saveOptions) {
await store.dispatch(clearTransientLayerStateAndCloseFlyout());
@ -491,9 +515,9 @@ app.controller(
try {
id = await savedMap.save(saveOptions);
docTitle.change(savedMap.title);
getCoreChrome().docTitle.change(savedMap.title);
} catch (err) {
toastNotifications.addDanger({
getToasts().addDanger({
title: i18n.translate('xpack.maps.mapController.saveErrorMessage', {
defaultMessage: `Error on saving '{title}'`,
values: { title: savedMap.title },
@ -505,7 +529,7 @@ app.controller(
}
if (id) {
toastNotifications.addSuccess({
getToasts().addSuccess({
title: i18n.translate('xpack.maps.mapController.saveSuccessMessage', {
defaultMessage: `Saved '{title}'`,
values: { title: savedMap.title },
@ -539,6 +563,7 @@ app.controller(
}),
testId: 'mapsFullScreenMode',
run() {
getCoreChrome().setIsVisible(false);
store.dispatch(enableFullScreen());
},
},
@ -556,7 +581,7 @@ app.controller(
getInspector().open(inspectorAdapters, {});
},
},
...(capabilities.get().maps.save
...(getMapsCapabilities().save
? [
{
id: 'save',
@ -611,7 +636,7 @@ app.controller(
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.
*/
import _ from 'lodash';
import { createSavedGisMapClass } from './saved_gis_map';
import { uiModules } from 'ui/modules';
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');
// This is the only thing that gets injected into controllers
module.service('gisMapSavedObjectLoader', function() {
const savedObjectsClient = npStart.core.savedObjects.client;
export const getMapsSavedObjectLoader = _.once(function() {
const services = {
savedObjectsClient,
indexPatterns: npStart.plugins.data.indexPatterns,
search: npStart.plugins.data.search,
chrome: npStart.core.chrome,
overlays: npStart.core.overlays,
savedObjectsClient: getSavedObjectsClient(),
indexPatterns: getIndexPatternService(),
search: getData().search,
chrome: getCoreChrome(),
overlays: getCoreOverlays(),
};
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 PropTypes from 'prop-types';
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 {
EuiTitle,
EuiFieldSearch,
@ -27,7 +28,6 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { addHelpMenuToAppChrome } from '../help_menu_util';
import chrome from 'ui/chrome';
export const EMPTY_FILTER = '';
@ -55,7 +55,7 @@ export class MapListing extends React.Component {
componentDidMount() {
this.fetchItems();
addHelpMenuToAppChrome(chrome);
addHelpMenuToAppChrome();
}
debouncedFetch = _.debounce(async filter => {
@ -91,7 +91,7 @@ export class MapListing extends React.Component {
try {
await this.props.delete(this.state.selectedIds);
} catch (error) {
toastNotifications.addDanger({
getToasts().addDanger({
title: i18n.translate('xpack.maps.mapListing.unableToDeleteToastTitle', {
defaultMessage: `Unable to delete map(s)`,
}),

View file

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

View file

@ -12,7 +12,8 @@ import { ToolbarOverlay } from '../toolbar_overlay/index';
import { LayerPanel } from '../layer_panel/index';
import { AddLayerPanel } from '../layer_addpanel/index';
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
import { getIndexPatternsFromIds } from '../../../../../../plugins/maps/public/index_pattern_util';
import { ES_GEO_FIELD_TYPE } from '../../../common/constants';

View file

@ -20,12 +20,14 @@ import {
import { FormattedMessage } from '@kbn/i18n/react';
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 { npStart } from 'ui/new_platform';
const { SearchBar } = npStart.plugins.data.ui;
export class FilterEditor extends Component {
state = {
isPopoverOpen: false,
@ -84,7 +86,8 @@ export class FilterEditor extends Component {
_renderQueryPopover() {
const layerQuery = this.props.layer.getQuery();
const { uiSettings } = npStart.core;
const uiSettings = getUiSettings();
const { SearchBar } = getData().ui;
return (
<EuiPopover

View file

@ -14,7 +14,8 @@ import { WhereExpression } from './where_expression';
import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox';
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 {
state = {

View file

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

View file

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

View file

@ -30,12 +30,11 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/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);
// 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 {
state = {
displayName: '',
@ -168,8 +167,8 @@ export class LayerPanel extends React.Component {
services={{
appName: 'maps',
storage: localStorage,
data: npStart.plugins.data,
...npStart.core,
data: getData(),
...getCore(),
}}
>
<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 { GEO_JSON_TYPE } from '../../../../common/constants';
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';
// 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 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 chrome from 'ui/chrome';
import { spritesheet } from '@elastic/maki';
import sprites1 from '@elastic/maki/dist/sprite@1.png';
import sprites2 from '@elastic/maki/dist/sprite@2.png';
@ -29,6 +28,8 @@ import {
clampToLonBounds,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} 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.setRTLTextPlugin(mbRtlPlugin);
@ -129,7 +130,7 @@ export class MBMapContainer extends React.Component {
container: this.refs.mapContainer,
style: mbStyle,
scrollZoom: this.props.scrollZoom,
preserveDrawingBuffer: chrome.getInjected('preserveDrawingBuffer', false),
preserveDrawingBuffer: getInjectedVarFunc()('preserveDrawingBuffer', false),
interactive: !this.props.disableInteractive,
};
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 { I18nContext } from 'ui/i18n';
import { npStart } from 'ui/new_platform';
import { Subscription } from 'rxjs';
import { Unsubscribe } from 'redux';
import {
@ -59,6 +58,8 @@ import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_se
import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
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 {
editUrl?: string;
@ -269,7 +270,7 @@ export class MapEmbeddable extends Embeddable<MapEmbeddableInput, MapEmbeddableO
}
addFilters = (filters: Filter[]) => {
npStart.plugins.uiActions.executeTriggerActions(APPLY_FILTER_TRIGGER, {
getUiActions().executeTriggerActions(APPLY_FILTER_TRIGGER, {
embeddable: this,
filters,
});

View file

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

View file

@ -3,10 +3,13 @@
* or more contributor license agreements. Licensed under 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) {
chrome.helpExtension.set({
export function addHelpMenuToAppChrome() {
const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = getDocLinks();
getCoreChrome().setHelpExtension({
appName: 'Maps',
links: [
{

View file

@ -4,7 +4,8 @@
* 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 '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';
// @ts-ignore
import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { Start as InspectorStartContract } from 'src/plugins/inspector/public';
// @ts-ignore
import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
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
import {
bindSetupCoreAndPlugins as bindNpSetupCoreAndPlugins,
@ -62,20 +54,6 @@ interface MapsPluginStartDependencies {
// 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 */
export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
public setup(core: CoreSetup, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) {
@ -85,14 +63,12 @@ export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
return reactDirective(wrapInI18nContext(MapListing));
});
bindSetupCoreAndPlugins(core, np);
bindNpSetupCoreAndPlugins(core, np);
np.home.featureCatalogue.register(featureCatalogueEntry);
}
public start(core: CoreStart, plugins: MapsPluginStartDependencies) {
bindStartCoreAndPlugins(core, plugins);
bindNpStartCoreAndPlugins(core, plugins);
}
}

View file

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

View file

@ -14,7 +14,7 @@ jest.mock('../../../../../plugins/maps/public/reducers/non_serializable_instance
return {};
},
}));
jest.mock('../kibana_services', () => ({
jest.mock('../../../../../plugins/maps/public/kibana_services', () => ({
getTimeFilter: () => ({
getTime: () => {
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;
}
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 {
setAutocompleteService,
setCore,
setCoreChrome,
setCoreI18n,
setCoreOverlays,
setData,
setDocLinks,
setFileUpload,
setHttp,
setIndexPatternSelect,
@ -17,9 +23,14 @@ import {
setInjectedVarFunc,
setInspector,
setLicenseId,
setMapsCapabilities,
setNavigation,
setSavedObjectsClient,
setTimeFilter,
setToasts,
setUiActions,
setUiSettings,
setVisualizations,
// @ts-ignore
} from './kibana_services';
@ -31,15 +42,16 @@ export interface MapsPluginStartDependencies {}
export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => {
const { licensing } = plugins;
const { injectedMetadata, http } = core;
const { injectedMetadata, uiSettings, http, notifications } = core;
if (licensing) {
licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid));
}
setInjectedVarFunc(injectedMetadata.getInjectedVar);
setHttp(http);
setUiSettings(core.uiSettings);
setInjectedVarFunc(core.injectedMetadata.getInjectedVar);
setToasts(core.notifications.toasts);
setToasts(notifications.toasts);
setInjectedVarFunc(injectedMetadata.getInjectedVar);
setVisualizations(plugins.visualizations);
setUiSettings(uiSettings);
};
export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => {
@ -50,6 +62,16 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => {
setTimeFilter(data.query.timefilter.timefilter);
setIndexPatternService(data.indexPatterns);
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);
};
/**