Skip to content

Commit

Permalink
Move some kibana services init to NP. Some cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Feb 14, 2020
1 parent 11c6cc9 commit 989b682
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 47 deletions.
5 changes: 4 additions & 1 deletion x-pack/legacy/plugins/maps/public/angular/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import {
setQuery,
clearTransientLayerStateAndCloseFlyout,
} from '../actions/map_actions';
import { DEFAULT_IS_LAYER_TOC_OPEN, FLYOUT_STATE } from '../../../../../plugins/maps/public/reducers/ui';
import {
DEFAULT_IS_LAYER_TOC_OPEN,
FLYOUT_STATE,
} from '../../../../../plugins/maps/public/reducers/ui';
import {
enableFullScreen,
updateFlyout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { connect } from 'react-redux';
import { LayerControl } from './view';
import { FLYOUT_STATE } from '../../../../../../../plugins/maps/public/reducers/ui.js'
import { FLYOUT_STATE } from '../../../../../../../plugins/maps/public/reducers/ui.js';
import { updateFlyout, setIsLayerTOCOpen } from '../../../actions/ui_actions';
import { setSelectedLayer } from '../../../actions/map_actions';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ import {
} from '../actions/map_actions';
import { setReadOnly, setIsLayerTOCOpen, setOpenTOCDetails } from '../actions/ui_actions';
import { getIsLayerTOCOpen, getOpenTOCDetails } from '../selectors/ui_selectors';
import { getInspectorAdapters, setEventHandlers } from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
import {
getInspectorAdapters,
setEventHandlers,
} from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_selectors';
import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants';

Expand Down
12 changes: 0 additions & 12 deletions x-pack/legacy/plugins/maps/public/kibana_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ export const SPATIAL_FILTER_TYPE = esFilters.FILTERS.SPATIAL_FILTER;
export { SearchSource } from '../../../../../src/plugins/data/public';
export const indexPatternService = npStart.plugins.data.indexPatterns;

let licenseId;
export const setLicenseId = latestLicenseId => (licenseId = latestLicenseId);
export const getLicenseId = () => {
return licenseId;
};

let inspector;
export const setInspector = newInspector => (inspector = newInspector);
export const getInspector = () => {
return inspector;
};

export async function fetchSearchSourceAndRecordWithInspector({
searchSource,
requestId,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/public/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
SOURCE_DATA_ID_ORIGIN,
} from '../../common/constants';
import uuid from 'uuid/v4';
import { copyPersistentState } from '../../../../../plugins/maps/public/reducers/util.js'
import { copyPersistentState } from '../../../../../plugins/maps/public/reducers/util.js';
import { i18n } from '@kbn/i18n';

export class AbstractLayer {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/public/layers/sources/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers';
import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers/util';

export class AbstractSource {
static isIndexingSource = false;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/public/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import chrome from 'ui/chrome';
import { i18n } from '@kbn/i18n';
import { EMSClient } from '@elastic/ems-client';
import { getLicenseId } from './kibana_services';
import { getLicenseId } from '../../../../plugins/maps/public/kibana_services';
import fetch from 'node-fetch';

const GIS_API_RELATIVE = `../${GIS_API_PATH}`;
Expand Down
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { MapListing } from './components/map_listing';
// @ts-ignore
import { setLicenseId, setInspector } from './kibana_services';
import { setLicenseId, setInspector, setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services';
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';
import { featureCatalogueEntry } from './feature_catalogue_entry';
Expand Down Expand Up @@ -43,6 +43,7 @@ export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
return reactDirective(wrapInI18nContext(MapListing));
});

setInjectedVarFunc(core.injectedMetadata.getInjectedVar);
if (licensing) {
licensing.license$.subscribe(({ uid }) => setLicenseId(uid));
}
Expand Down
5 changes: 4 additions & 1 deletion x-pack/legacy/plugins/maps/public/selectors/map_selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { HeatmapLayer } from '../layers/heatmap_layer';
import { ALL_SOURCES } from '../layers/sources/all_sources';
import { timefilter } from 'ui/timefilter';
import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../../../../../plugins/maps/public/reducers/util';
import {
copyPersistentState,
TRACKED_LAYER_DESCRIPTOR,
} from '../../../../../plugins/maps/public/reducers/util';

function createLayerInstance(layerDescriptor, inspectorAdapters) {
const source = createSourceInstance(layerDescriptor.sourceDescriptor, inspectorAdapters);
Expand Down
20 changes: 18 additions & 2 deletions x-pack/plugins/maps/public/kibana_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@
export let indexPatternService;
export let timeFilter;

export const initKibanaServices = ({ data }) => {
let licenseId;
export const setLicenseId = latestLicenseId => (licenseId = latestLicenseId);
export const getLicenseId = () => {
return licenseId;
};

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;

export const initKibanaServices = ({ injectedMetadata }, { data }) => {
indexPatternService = data.indexPatterns;
timeFilter: data.query.timefilter
timeFilter = data.query.timefilter;
};
22 changes: 10 additions & 12 deletions x-pack/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
Plugin,
CoreSetup,
CoreStart, AppMountParameters,
} from 'src/core/public';
import { Plugin, CoreSetup, CoreStart } from 'src/core/public';
import { Setup as InspectorSetupContract } from 'src/plugins/inspector/public';
import { DataPublicPluginSetup } from '../../../../src/plugins/data/public';
import { initKibanaServices } from './kibana_services';
import { i18n } from '@kbn/i18n';
// @ts-ignore
import { initKibanaServices, setInspector, setInjectedVarFunc } from './kibana_services';

// eslint-disable-line @typescript-eslint/no-empty-interface
export interface MapsPluginSetupDependencies {
data: DataPublicPluginSetup
data: DataPublicPluginSetup;
inspector: InspectorSetupContract;
}
// eslint-disable-line @typescript-eslint/no-empty-interface
export interface MapsPluginStartDependencies {}
Expand All @@ -37,9 +35,10 @@ export class MapsPlugin
MapsPluginSetupDependencies,
MapsPluginStartDependencies
> {

public setup(core: CoreSetup, plugins: MapsPluginSetupDependencies) {
initKibanaServices(core, plugins);
setInspector(plugins.inspector);
setInjectedVarFunc(core.injectedMetadata.getInjectedVar);
// core.application.register({
// id: 'maps',
// title: i18n.translate('xpack.maps.pluginTitle', {
Expand All @@ -52,9 +51,8 @@ export class MapsPlugin
// },
// });
return {
maps: 'testing'
}

maps: 'testing',
};
}

public start(core: CoreStart, plugins: any) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { RequestAdapter} from '../../../../../src/plugins/inspector/public/adapters/request';
import { RequestAdapter } from '../../../../../src/plugins/inspector/common/adapters/request';
import { MapAdapter } from '../inspector/adapters/map_adapter';

// TODO
import chrome from 'ui/chrome';
import { getInjectedVarFunc } from '../kibana_services';

const REGISTER_CANCEL_CALLBACK = 'REGISTER_CANCEL_CALLBACK';
const UNREGISTER_CANCEL_CALLBACK = 'UNREGISTER_CANCEL_CALLBACK';
Expand All @@ -18,7 +16,7 @@ function createInspectorAdapters() {
const inspectorAdapters = {
requests: new RequestAdapter(),
};
if (chrome.getInjected('showMapsInspectorAdapter', false)) {
if (getInjectedVarFunc()('showMapsInspectorAdapter', false)) {
inspectorAdapters.map = new MapAdapter();
}
return inspectorAdapters;
Expand Down
14 changes: 6 additions & 8 deletions x-pack/plugins/maps/public/reducers/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import { ui } from './ui';
import { map } from './map';
import { nonSerializableInstances } from './non_serializable_instances';

const rootReducer = combineReducers({
map,
ui,
nonSerializableInstances,
});

const enhancers = [applyMiddleware(thunk)];

export function createMapStore() {
const enhancers = [applyMiddleware(thunk)];
const rootReducer = combineReducers({
map,
ui,
nonSerializableInstances,
});
const storeConfig = {};
return createStore(rootReducer, storeConfig, compose(...enhancers));
}

0 comments on commit 989b682

Please sign in to comment.