Skip to content

Commit

Permalink
Layers dir up through sources migrated. Kibana services updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Mar 16, 2020
1 parent ef32611 commit 504a572
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 23 deletions.
21 changes: 21 additions & 0 deletions x-pack/legacy/plugins/maps/public/kibana_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ export const getFileUploadComponent = () => {
return fileUploadPlugin.JsonUploadAndParse;
};

let getInjectedVar;
export const setInjectedVarFunc = getInjectedVarFunc => (getInjectedVar = getInjectedVarFunc);
export const getInjectedVarFunc = () => getInjectedVar;

let uiSettings;
export const setUiSettings = coreUiSettings => (uiSettings = coreUiSettings);
export const getUiSettings = () => uiSettings;

let indexPatternSelectComponent;
export const setIndexPatternSelect = indexPatternSelect =>
(indexPatternSelectComponent = indexPatternSelect);
export const getIndexPatternSelectComponent = () => indexPatternSelectComponent;

let coreHttp;
export const setHttp = http => (coreHttp = http);
export const getHttp = () => coreHttp;

let dataTimeFilter;
export const setTimeFilter = timeFilter => (dataTimeFilter = timeFilter);
export const getTimeFilter = () => dataTimeFilter;

export async function fetchSearchSourceAndRecordWithInspector({
searchSource,
requestId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import _ from 'lodash';
import chrome from 'ui/chrome';
import React from 'react';
import { AbstractTMSSource } from '../tms_source';
import { VectorTileLayer } from '../../vector_tile_layer';
Expand All @@ -16,6 +15,7 @@ import { UpdateSourceEditor } from './update_source_editor';
import { i18n } from '@kbn/i18n';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
import { EMS_TMS } from '../../../../common/constants';
import { getInjectedVarFunc, getUiSettings } from '../../../kibana_services';

export class EMSTMSSource extends AbstractTMSSource {
static type = EMS_TMS;
Expand Down Expand Up @@ -152,8 +152,8 @@ export class EMSTMSSource extends AbstractTMSSource {
return this._descriptor.id;
}

const isDarkMode = chrome.getUiSettingsClient().get('theme:darkMode', false);
const emsTileLayerId = chrome.getInjected('emsTileLayerId');
const isDarkMode = getUiSettings().get('theme:darkMode', false);
const emsTileLayerId = getInjectedVarFunc()('emsTileLayerId');
return isDarkMode ? emsTileLayerId.dark : emsTileLayerId.bright;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import chrome from 'ui/chrome';
import { getInjectedVarFunc } from '../../kibana_services';
import { i18n } from '@kbn/i18n';

export function getEmsUnavailableMessage() {
const isEmsEnabled = chrome.getInjected('isEmsEnabled', true);
const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true);
if (isEmsEnabled) {
return i18n.translate('xpack.maps.source.ems.noAccessDescription', {
defaultMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { Fragment, Component } from 'react';
import PropTypes from 'prop-types';

import { SingleFieldSelect } from '../../../components/single_field_select';
import { indexPatternService } from '../../../kibana_services';
import { indexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

Expand All @@ -19,8 +19,7 @@ import {
getAggregatableGeoFields,
} from '../../../index_pattern_util';

import { npStart } from 'ui/new_platform';
const { IndexPatternSelect } = npStart.plugins.data.ui;
const IndexPatternSelect = getIndexPatternSelectComponent();

export class CreateSourceEditor extends Component {
static propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import PropTypes from 'prop-types';
import { EuiFormRow, EuiSpacer, EuiSwitch, EuiCallOut } from '@elastic/eui';

import { SingleFieldSelect } from '../../../components/single_field_select';
import { indexPatternService } from '../../../kibana_services';
import {
indexPatternService,
getIndexPatternSelectComponent,
getHttp,
} from '../../../kibana_services';
import { NoIndexPatternCallout } from '../../../components/no_index_pattern_callout';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { kfetch } from 'ui/kfetch';
import {
ES_GEO_FIELD_TYPE,
GIS_API_PATH,
Expand All @@ -23,8 +26,8 @@ import {
import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants';
import { indexPatterns } from '../../../../../../../../src/plugins/data/public';

import { npStart } from 'ui/new_platform';
const { IndexPatternSelect } = npStart.plugins.data.ui;
const IndexPatternSelect = getIndexPatternSelectComponent();
const http = getHttp();

function getGeoFields(fields) {
return fields.filter(field => {
Expand Down Expand Up @@ -81,7 +84,8 @@ export class CreateSourceEditor extends Component {
};

loadIndexDocCount = async indexPatternTitle => {
const { count } = await kfetch({
const { count } = await http({
method: 'GET',
pathname: `../${GIS_API_PATH}/indexCount`,
query: {
index: indexPatternTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
DEFAULT_MAX_INNER_RESULT_WINDOW,
INDEX_SETTINGS_API_PATH,
} from '../../../../common/constants';
import { kfetch } from 'ui/kfetch';
import { getHttp } from '../../../kibana_services';
import { toastNotifications } from 'ui/notify';
import { i18n } from '@kbn/i18n';

let toastDisplayed = false;
const indexSettings = new Map();
const http = getHttp();

export async function loadIndexSettings(indexPatternTitle) {
if (indexSettings.has(indexPatternTitle)) {
Expand All @@ -28,7 +29,8 @@ export async function loadIndexSettings(indexPatternTitle) {

async function fetchIndexSettings(indexPatternTitle) {
try {
const indexSettings = await kfetch({
const indexSettings = await http({
method: 'GET',
pathname: `../${INDEX_SETTINGS_API_PATH}`,
query: {
indexPatternTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
fetchSearchSourceAndRecordWithInspector,
indexPatternService,
SearchSource,
getTimeFilter,
} from '../../kibana_services';
import { createExtentFilter } from '../../elasticsearch_geo_utils';
import { timefilter } from 'ui/timefilter';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import uuid from 'uuid/v4';
Expand All @@ -22,6 +22,8 @@ import { ES_GEO_FIELD_TYPE } from '../../../common/constants';
import { DataRequestAbortError } from '../util/data_request';
import { expandToTileBoundaries } from './es_geo_grid_source/geo_tile_utils';

const timefilter = getTimeFilter();

export class AbstractESSource extends AbstractVectorSource {
static icon = 'logoElasticsearch';

Expand Down
34 changes: 27 additions & 7 deletions x-pack/legacy/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ import { Plugin, CoreStart, CoreSetup } from 'src/core/public';
import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { MapListing } from './components/map_listing';
// @ts-ignore
import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; // eslint-disable-line @kbn/eslint/no-restricted-paths
// @ts-ignore
import { setLicenseId, setInspector, setFileUpload } from './kibana_services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services';
import {
setLicenseId,
setInspector,
setFileUpload,
setIndexPatternSelect,
setHttp,
setTimeFilter,
} from './kibana_services';
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';
import { featureCatalogueEntry } from './feature_catalogue_entry';
import { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
import { Start as InspectorPluginStart } from '../../../plugins/inspector/public';

/**
* These are the interfaces with your public contracts. You should export these
Expand All @@ -30,16 +38,26 @@ interface MapsPluginSetupDependencies {
np: {
licensing?: LicensingPluginSetup;
home: HomePublicPluginSetup;
data: DataPublicPluginStart;
};
}

interface MapsPluginStartDependencies {
np: {
data: DataPublicPluginStart;
inspector: InspectorPluginStart;
file_upload: any; // TODO: Export type from file upload and use here
};
}

export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => {
const { licensing } = plugins;
const { injectedMetadata } = core;
const { injectedMetadata, http } = core;
if (licensing) {
licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid));
}
setInjectedVarFunc(injectedMetadata.getInjectedVar);
setHttp(http);
};

/** @internal */
Expand All @@ -56,9 +74,11 @@ export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
np.home.featureCatalogue.register(featureCatalogueEntry);
}

public start(core: CoreStart, plugins: any) {
const { inspector, file_upload } = plugins.np;
public start(core: CoreStart, plugins: MapsPluginStartDependencies) {
const { inspector, file_upload, data } = plugins.np;
setInspector(inspector);
setFileUpload(file_upload);
setIndexPatternSelect(data.ui.IndexPatternSelect);
setTimeFilter(data.timefilter.timefilter);
}
}

0 comments on commit 504a572

Please sign in to comment.