Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] Update remaining client dependencies to NP #63297

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fe0441e
Routes dependencies updated (except for routes itself)
Apr 9, 2020
25b586a
Replace all chrome deps except map controller
Apr 10, 2020
892c449
Merge remote-tracking branch 'upstream/master' into np-update-remaini…
Apr 13, 2020
30b5aa6
Replace npSetup and npStart with normal plugin init logic. Some clean up
Apr 13, 2020
5c657a7
Bind kibana services in map controller
Apr 13, 2020
bd9b707
Use kibana services in map controller
Apr 13, 2020
cd6cdd9
Convert remaining deps that aren't critical to legacy operation
Apr 13, 2020
9397439
Merge remote-tracking branch 'upstream/master' into np-update-remaini…
Apr 13, 2020
ca40d71
Remove last angular bindings to gis map saved object loader
Apr 13, 2020
4e3ed3a
Consolidate kibana services in NP
Apr 14, 2020
e36abee
Some fixes. Remove console logs
Apr 14, 2020
4db6223
Fix type errors
Apr 14, 2020
9c550e6
Merge remote-tracking branch 'upstream/master' into np-update-remaini…
Apr 14, 2020
e95e0c1
Merge remote-tracking branch 'upstream/master' into np-update-remaini…
Apr 14, 2020
b95101b
Fix jest test path refs
Apr 14, 2020
ef3972c
Accomodate legacy 'hacks' and init services for vis type alias
Apr 15, 2020
401dda1
Review feedback. Remove/update unused declarations
Apr 15, 2020
aad7c5b
Merge remote-tracking branch 'upstream/master' into np-update-remaini…
Apr 15, 2020
2e1ca36
getFileUpload actually just needed Component tacked on the end
Apr 15, 2020
0b2e683
Handle visibility of toolbars for full screen mode using new core chr…
Apr 16, 2020
d04135f
Merge remote-tracking branch 'upstream/master' into np-update-remaini…
Apr 16, 2020
a64a942
Import source types in getInitialLayers to ensure registry
Apr 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import _ from 'lodash';
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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
jest.mock('../../../../../plugins/maps/public/meta', () => {
return {};
});
jest.mock('../kibana_services');
jest.mock('../../../../../plugins/maps/public/kibana_services');

import { getInitialLayers } from './get_initial_layers';

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', () => {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 };
}
60 changes: 37 additions & 23 deletions x-pack/legacy/plugins/maps/public/angular/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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`,
}),
Expand All @@ -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;
Expand Down Expand Up @@ -169,10 +183,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;
}
Expand Down Expand Up @@ -342,7 +356,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(() => {
Expand Down Expand Up @@ -457,7 +471,7 @@ app.controller(
});

const updateBreadcrumbs = () => {
chrome.breadcrumbs.set([
getCoreChrome().setBreadcrumbs([
{
text: i18n.translate('xpack.maps.mapController.mapsBreadcrumbLabel', {
defaultMessage: 'Maps',
Expand All @@ -482,7 +496,7 @@ app.controller(
};
updateBreadcrumbs();

addHelpMenuToAppChrome(chrome);
addHelpMenuToAppChrome();

async function doSave(saveOptions) {
await store.dispatch(clearTransientLayerStateAndCloseFlyout());
Expand All @@ -491,9 +505,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 },
Expand All @@ -505,7 +519,7 @@ app.controller(
}

if (id) {
toastNotifications.addSuccess({
getToasts().addSuccess({
title: i18n.translate('xpack.maps.mapController.saveSuccessMessage', {
defaultMessage: `Saved '{title}'`,
values: { title: savedMap.title },
Expand Down Expand Up @@ -556,7 +570,7 @@ app.controller(
getInspector().open(inspectorAdapters, {});
},
},
...(capabilities.get().maps.save
...(getMapsCapabilities().save
? [
{
id: 'save',
Expand Down Expand Up @@ -611,7 +625,7 @@ app.controller(
showDescription={false}
/>
);
showSaveModal(saveModal, npStart.core.i18n.Context);
showSaveModal(saveModal, getCoreI18n().Context);
},
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
8 changes: 4 additions & 4 deletions x-pack/legacy/plugins/maps/public/components/map_listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = '';

Expand Down Expand Up @@ -55,7 +55,7 @@ export class MapListing extends React.Component {

componentDidMount() {
this.fetchItems();
addHelpMenuToAppChrome(chrome);
addHelpMenuToAppChrome();
}

debouncedFetch = _.debounce(async filter => {
Expand Down Expand Up @@ -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)`,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading