[Maps] Update layer dependencies to NP (#59585)
* Layers dir up through sources migrated. Kibana services updated * Create separate init method for plugin setup, leverage in embeddable factory * Add NP timefilter, http, IndexPatternSelect * Pull vis color utils into Maps * Add NP dark mode and toast handling. Some fixes * Init autocomplete and indexPattern via normal paths * Test fixes and clean up * Update index pattern and autocomplete refs. Make getters functions * Fix remaining broken jest tests * Update inspector start contract * Clean up plugin and legacy files. Fix type issues * Set inspector in plugin start method not external function * Keep both injected var functions (legacy and NP). Move inspector init back to separate init function * Add back ts-ignore on NP kibana services import
This commit is contained in:
parent
9b07ddc1e2
commit
592ded89c0
|
@ -6,7 +6,7 @@
|
|||
import _ from 'lodash';
|
||||
import { KibanaTilemapSource } from '../layers/sources/kibana_tilemap_source';
|
||||
import { EMSTMSSource } from '../layers/sources/ems_tms_source';
|
||||
import chrome from 'ui/chrome';
|
||||
import { getInjectedVarFunc } from '../kibana_services';
|
||||
import { getKibanaTileMap } from '../meta';
|
||||
|
||||
export function getInitialLayers(layerListJSON, initialLayers = []) {
|
||||
|
@ -22,7 +22,7 @@ export function getInitialLayers(layerListJSON, initialLayers = []) {
|
|||
return [layer.toLayerDescriptor(), ...initialLayers];
|
||||
}
|
||||
|
||||
const isEmsEnabled = chrome.getInjected('isEmsEnabled', true);
|
||||
const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true);
|
||||
if (isEmsEnabled) {
|
||||
const descriptor = EMSTMSSource.createDescriptor({ isAutoSelect: true });
|
||||
const source = new EMSTMSSource(descriptor);
|
||||
|
|
|
@ -7,16 +7,17 @@
|
|||
jest.mock('../meta', () => {
|
||||
return {};
|
||||
});
|
||||
|
||||
jest.mock('ui/chrome', () => {
|
||||
return {};
|
||||
});
|
||||
jest.mock('../kibana_services');
|
||||
|
||||
import { getInitialLayers } from './get_initial_layers';
|
||||
|
||||
const layerListNotProvided = undefined;
|
||||
|
||||
describe('Saved object has layer list', () => {
|
||||
beforeEach(() => {
|
||||
require('../kibana_services').getInjectedVarFunc = () => jest.fn();
|
||||
});
|
||||
|
||||
it('Should get initial layers from saved object', () => {
|
||||
const layerListFromSavedObject = [
|
||||
{
|
||||
|
@ -64,7 +65,7 @@ describe('EMS is enabled', () => {
|
|||
require('../meta').getKibanaTileMap = () => {
|
||||
return null;
|
||||
};
|
||||
require('ui/chrome').getInjected = key => {
|
||||
require('../kibana_services').getInjectedVarFunc = () => key => {
|
||||
switch (key) {
|
||||
case 'emsTileLayerId':
|
||||
return {
|
||||
|
@ -75,7 +76,7 @@ describe('EMS is enabled', () => {
|
|||
case 'isEmsEnabled':
|
||||
return true;
|
||||
default:
|
||||
throw new Error(`Unexpected call to chrome.getInjected with key ${key}`);
|
||||
throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -109,12 +110,12 @@ describe('EMS is not enabled', () => {
|
|||
return null;
|
||||
};
|
||||
|
||||
require('ui/chrome').getInjected = key => {
|
||||
require('../kibana_services').getInjectedVarFunc = () => key => {
|
||||
switch (key) {
|
||||
case 'isEmsEnabled':
|
||||
return false;
|
||||
default:
|
||||
throw new Error(`Unexpected call to chrome.getInjected with key ${key}`);
|
||||
throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ import { i18n } from '@kbn/i18n';
|
|||
import { capabilities } from 'ui/capabilities';
|
||||
import { render, unmountComponentAtNode } from 'react-dom';
|
||||
import { uiModules } from 'ui/modules';
|
||||
import { timefilter } from 'ui/timefilter';
|
||||
import { getTimeFilter, getIndexPatternService, getInspector } from '../kibana_services';
|
||||
import { Provider } from 'react-redux';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { createMapStore } from '../../../../../plugins/maps/public/reducers/store';
|
||||
|
@ -52,7 +52,7 @@ import {
|
|||
// 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 { indexPatternService, getInspector } from '../kibana_services';
|
||||
|
||||
import { toastNotifications } from 'ui/notify';
|
||||
import { getInitialLayers } from './get_initial_layers';
|
||||
import { getInitialQuery } from './get_initial_query';
|
||||
|
@ -396,7 +396,7 @@ app.controller(
|
|||
const indexPatterns = [];
|
||||
const getIndexPatternPromises = nextIndexPatternIds.map(async indexPatternId => {
|
||||
try {
|
||||
const indexPattern = await indexPatternService.get(indexPatternId);
|
||||
const indexPattern = await getIndexPatternService().get(indexPatternId);
|
||||
indexPatterns.push(indexPattern);
|
||||
} catch (err) {
|
||||
// unable to fetch index pattern
|
||||
|
@ -519,8 +519,8 @@ app.controller(
|
|||
}
|
||||
|
||||
// Hide angular timepicer/refresh UI from top nav
|
||||
timefilter.disableTimeRangeSelector();
|
||||
timefilter.disableAutoRefreshSelector();
|
||||
getTimeFilter().disableTimeRangeSelector();
|
||||
getTimeFilter().disableAutoRefreshSelector();
|
||||
$scope.showDatePicker = true; // used by query-bar directive to enable timepikcer in query bar
|
||||
$scope.topNavMenu = [
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// Maps can contain geo fields from multiple index patterns. GeoFieldWithIndex is used to:
|
||||
// 1) Combine the geo field along with associated index pattern state.
|
||||
// 2) Package asynchronously looked up state via indexPatternService to avoid
|
||||
// 2) Package asynchronously looked up state via getIndexPatternService() to avoid
|
||||
// PITA of looking up async state in downstream react consumers.
|
||||
export type GeoFieldWithIndex = {
|
||||
geoFieldName: string;
|
||||
|
|
|
@ -20,7 +20,7 @@ import {
|
|||
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { indexPatternService } from '../../../kibana_services';
|
||||
import { getIndexPatternService } from '../../../kibana_services';
|
||||
import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox';
|
||||
|
||||
import { npStart } from 'ui/new_platform';
|
||||
|
@ -47,7 +47,7 @@ export class FilterEditor extends Component {
|
|||
const indexPatterns = [];
|
||||
const getIndexPatternPromises = indexPatternIds.map(async indexPatternId => {
|
||||
try {
|
||||
const indexPattern = await indexPatternService.get(indexPatternId);
|
||||
const indexPattern = await getIndexPatternService().get(indexPatternId);
|
||||
indexPatterns.push(indexPattern);
|
||||
} catch (err) {
|
||||
// unable to fetch index pattern
|
||||
|
|
|
@ -14,7 +14,7 @@ import { WhereExpression } from './where_expression';
|
|||
import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox';
|
||||
|
||||
import { indexPatterns } from '../../../../../../../../../src/plugins/data/public';
|
||||
import { indexPatternService } from '../../../../kibana_services';
|
||||
import { getIndexPatternService } from '../../../../kibana_services';
|
||||
|
||||
export class Join extends Component {
|
||||
state = {
|
||||
|
@ -39,7 +39,7 @@ export class Join extends Component {
|
|||
|
||||
let indexPattern;
|
||||
try {
|
||||
indexPattern = await indexPatternService.get(indexPatternId);
|
||||
indexPattern = await getIndexPatternService().get(indexPatternId);
|
||||
} catch (err) {
|
||||
if (this._isMounted) {
|
||||
this.setState({
|
||||
|
|
|
@ -19,11 +19,10 @@ import { i18n } from '@kbn/i18n';
|
|||
import { SingleFieldSelect } from '../../../../components/single_field_select';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
import { getTermsFields } from '../../../../index_pattern_util';
|
||||
|
||||
import { indexPatternService } from '../../../../kibana_services';
|
||||
|
||||
import { npStart } from 'ui/new_platform';
|
||||
const { IndexPatternSelect } = npStart.plugins.data.ui;
|
||||
import {
|
||||
getIndexPatternService,
|
||||
getIndexPatternSelectComponent,
|
||||
} from '../../../../kibana_services';
|
||||
|
||||
export class JoinExpression extends Component {
|
||||
state = {
|
||||
|
@ -44,7 +43,7 @@ export class JoinExpression extends Component {
|
|||
|
||||
_onRightSourceChange = async indexPatternId => {
|
||||
try {
|
||||
const indexPattern = await indexPatternService.get(indexPatternId);
|
||||
const indexPattern = await getIndexPatternService().get(indexPatternId);
|
||||
this.props.onRightSourceChange({
|
||||
indexPatternId,
|
||||
indexPatternTitle: indexPattern.title,
|
||||
|
@ -106,6 +105,7 @@ export class JoinExpression extends Component {
|
|||
if (!this.props.leftValue) {
|
||||
return null;
|
||||
}
|
||||
const IndexPatternSelect = getIndexPatternSelectComponent();
|
||||
|
||||
return (
|
||||
<EuiFormRow
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
} from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public';
|
||||
import { setup } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy';
|
||||
import { MapEmbeddable } from './map_embeddable';
|
||||
import { indexPatternService } from '../kibana_services';
|
||||
import { getIndexPatternService } from '../kibana_services';
|
||||
|
||||
import { createMapPath, MAP_SAVED_OBJECT_TYPE, APP_ICON } from '../../common/constants';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
|
@ -24,8 +24,8 @@ 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 } from '../plugin';
|
||||
import { npSetup } from 'ui/new_platform';
|
||||
import { bindSetupCoreAndPlugins, bindStartCoreAndPlugins } from '../plugin';
|
||||
import { npSetup, npStart } from 'ui/new_platform';
|
||||
|
||||
export class MapEmbeddableFactory extends EmbeddableFactory {
|
||||
type = MAP_SAVED_OBJECT_TYPE;
|
||||
|
@ -40,7 +40,9 @@ export class MapEmbeddableFactory extends EmbeddableFactory {
|
|||
getIconForSavedObject: () => APP_ICON,
|
||||
},
|
||||
});
|
||||
// Init required services. Necessary while in legacy
|
||||
bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
|
||||
bindStartCoreAndPlugins(npStart.core, npStart.plugins);
|
||||
}
|
||||
isEditable() {
|
||||
return capabilities.get().maps.save;
|
||||
|
@ -76,7 +78,7 @@ export class MapEmbeddableFactory extends EmbeddableFactory {
|
|||
|
||||
const promises = queryableIndexPatternIds.map(async indexPatternId => {
|
||||
try {
|
||||
return await indexPatternService.get(indexPatternId);
|
||||
return await getIndexPatternService().get(indexPatternId);
|
||||
} catch (error) {
|
||||
// Unable to load index pattern, better to not throw error so map embeddable can render
|
||||
// Error will be surfaced by map embeddable since it too will be unable to locate the index pattern
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { indexPatternService } from './kibana_services';
|
||||
import { getIndexPatternService } from './kibana_services';
|
||||
import { indexPatterns } from '../../../../../src/plugins/data/public';
|
||||
import { ES_GEO_FIELD_TYPE } from '../common/constants';
|
||||
|
||||
export async function getIndexPatternsFromIds(indexPatternIds = []) {
|
||||
const promises = [];
|
||||
indexPatternIds.forEach(id => {
|
||||
const indexPatternPromise = indexPatternService.get(id);
|
||||
const indexPatternPromise = getIndexPatternService().get(id);
|
||||
if (indexPatternPromise) {
|
||||
promises.push(indexPatternPromise);
|
||||
}
|
||||
|
|
|
@ -6,12 +6,18 @@
|
|||
|
||||
import { esFilters, search } from '../../../../../src/plugins/data/public';
|
||||
const { getRequestInspectorStats, getResponseInspectorStats } = search;
|
||||
import { npStart } from 'ui/new_platform';
|
||||
|
||||
export const SPATIAL_FILTER_TYPE = esFilters.FILTERS.SPATIAL_FILTER;
|
||||
export { SearchSource } from '../../../../../src/plugins/data/public';
|
||||
export const indexPatternService = npStart.plugins.data.indexPatterns;
|
||||
export const autocompleteService = npStart.plugins.data.autocomplete;
|
||||
|
||||
let indexPatternService;
|
||||
export const setIndexPatternService = dataIndexPatterns =>
|
||||
(indexPatternService = dataIndexPatterns);
|
||||
export const getIndexPatternService = () => indexPatternService;
|
||||
|
||||
let autocompleteService;
|
||||
export const setAutocompleteService = dataAutoComplete => (autocompleteService = dataAutoComplete);
|
||||
export const getAutocompleteService = () => autocompleteService;
|
||||
|
||||
let licenseId;
|
||||
export const setLicenseId = latestLicenseId => (licenseId = latestLicenseId);
|
||||
|
@ -31,6 +37,31 @@ 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;
|
||||
|
||||
let toast;
|
||||
export const setToasts = notificationToast => (toast = notificationToast);
|
||||
export const getToasts = () => toast;
|
||||
|
||||
export async function fetchSearchSourceAndRecordWithInspector({
|
||||
searchSource,
|
||||
requestId,
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import { InnerJoin } from './inner_join';
|
||||
|
||||
jest.mock('../../kibana_services', () => {});
|
||||
jest.mock('ui/timefilter', () => {});
|
||||
jest.mock('../vector_layer', () => {});
|
||||
|
||||
const rightSource = {
|
||||
|
|
|
@ -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';
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
|
|||
|
||||
import { SingleFieldSelect } from '../../../components/single_field_select';
|
||||
import { RENDER_AS } from '../../../../common/constants';
|
||||
import { indexPatternService } from '../../../kibana_services';
|
||||
import { getIndexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services';
|
||||
import { NoIndexPatternCallout } from '../../../components/no_index_pattern_callout';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
|
@ -20,9 +20,6 @@ import {
|
|||
getAggregatableGeoFields,
|
||||
} from '../../../index_pattern_util';
|
||||
|
||||
import { npStart } from 'ui/new_platform';
|
||||
const { IndexPatternSelect } = npStart.plugins.data.ui;
|
||||
|
||||
const requestTypeOptions = [
|
||||
{
|
||||
label: i18n.translate('xpack.maps.source.esGeoGrid.gridRectangleDropdownOption', {
|
||||
|
@ -92,7 +89,7 @@ export class CreateSourceEditor extends Component {
|
|||
|
||||
let indexPattern;
|
||||
try {
|
||||
indexPattern = await indexPatternService.get(indexPatternId);
|
||||
indexPattern = await getIndexPatternService().get(indexPatternId);
|
||||
} catch (err) {
|
||||
// index pattern no longer exists
|
||||
return;
|
||||
|
@ -205,6 +202,8 @@ export class CreateSourceEditor extends Component {
|
|||
}
|
||||
|
||||
_renderIndexPatternSelect() {
|
||||
const IndexPatternSelect = getIndexPatternSelectComponent();
|
||||
|
||||
return (
|
||||
<EuiFormRow
|
||||
label={i18n.translate('xpack.maps.source.esGeoGrid.indexPatternLabel', {
|
||||
|
|
|
@ -8,7 +8,7 @@ import React, { Fragment, Component } from 'react';
|
|||
|
||||
import { RENDER_AS } from '../../../../common/constants';
|
||||
import { MetricsEditor } from '../../../components/metrics_editor';
|
||||
import { indexPatternService } from '../../../kibana_services';
|
||||
import { getIndexPatternService } from '../../../kibana_services';
|
||||
import { ResolutionEditor } from './resolution_editor';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
|
@ -33,7 +33,7 @@ export class UpdateSourceEditor extends Component {
|
|||
async _loadFields() {
|
||||
let indexPattern;
|
||||
try {
|
||||
indexPattern = await indexPatternService.get(this.props.indexPatternId);
|
||||
indexPattern = await getIndexPatternService().get(this.props.indexPatternId);
|
||||
} catch (err) {
|
||||
if (this._isMounted) {
|
||||
this.setState({
|
||||
|
|
|
@ -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 { getIndexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
|
||||
|
@ -19,9 +19,6 @@ import {
|
|||
getAggregatableGeoFields,
|
||||
} from '../../../index_pattern_util';
|
||||
|
||||
import { npStart } from 'ui/new_platform';
|
||||
const { IndexPatternSelect } = npStart.plugins.data.ui;
|
||||
|
||||
export class CreateSourceEditor extends Component {
|
||||
static propTypes = {
|
||||
onSourceConfigChange: PropTypes.func.isRequired,
|
||||
|
@ -73,7 +70,7 @@ export class CreateSourceEditor extends Component {
|
|||
|
||||
let indexPattern;
|
||||
try {
|
||||
indexPattern = await indexPatternService.get(indexPatternId);
|
||||
indexPattern = await getIndexPatternService().get(indexPatternId);
|
||||
} catch (err) {
|
||||
// index pattern no longer exists
|
||||
return;
|
||||
|
@ -169,6 +166,8 @@ export class CreateSourceEditor extends Component {
|
|||
}
|
||||
|
||||
_renderIndexPatternSelect() {
|
||||
const IndexPatternSelect = getIndexPatternSelectComponent();
|
||||
|
||||
return (
|
||||
<EuiFormRow
|
||||
label={i18n.translate('xpack.maps.source.pewPew.indexPatternLabel', {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import React, { Component, Fragment } from 'react';
|
||||
|
||||
import { MetricsEditor } from '../../../components/metrics_editor';
|
||||
import { indexPatternService } from '../../../kibana_services';
|
||||
import { getIndexPatternService } from '../../../kibana_services';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { EuiPanel, EuiTitle, EuiSpacer } from '@elastic/eui';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
|
@ -30,7 +30,7 @@ export class UpdateSourceEditor extends Component {
|
|||
async _loadFields() {
|
||||
let indexPattern;
|
||||
try {
|
||||
indexPattern = await indexPatternService.get(this.props.indexPatternId);
|
||||
indexPattern = await getIndexPatternService().get(this.props.indexPatternId);
|
||||
} catch (err) {
|
||||
if (this._isMounted) {
|
||||
this.setState({
|
||||
|
|
|
@ -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 {
|
||||
getIndexPatternService,
|
||||
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,
|
||||
|
@ -23,9 +26,6 @@ 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;
|
||||
|
||||
function getGeoFields(fields) {
|
||||
return fields.filter(field => {
|
||||
return (
|
||||
|
@ -81,8 +81,10 @@ export class CreateSourceEditor extends Component {
|
|||
};
|
||||
|
||||
loadIndexDocCount = async indexPatternTitle => {
|
||||
const { count } = await kfetch({
|
||||
pathname: `../${GIS_API_PATH}/indexCount`,
|
||||
const http = getHttp();
|
||||
const { count } = await http.fetch(`../${GIS_API_PATH}/indexCount`, {
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
query: {
|
||||
index: indexPatternTitle,
|
||||
},
|
||||
|
@ -97,7 +99,7 @@ export class CreateSourceEditor extends Component {
|
|||
|
||||
let indexPattern;
|
||||
try {
|
||||
indexPattern = await indexPatternService.get(indexPatternId);
|
||||
indexPattern = await getIndexPatternService().get(indexPatternId);
|
||||
} catch (err) {
|
||||
// index pattern no longer exists
|
||||
return;
|
||||
|
@ -249,6 +251,8 @@ export class CreateSourceEditor extends Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
const IndexPatternSelect = getIndexPatternSelectComponent();
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{this._renderNoIndexPatternWarning()}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
jest.mock('ui/new_platform');
|
||||
jest.mock('../../../kibana_services');
|
||||
|
||||
import { ESSearchSource } from './es_search_source';
|
||||
import { VectorLayer } from '../../vector_layer';
|
||||
|
@ -19,6 +20,11 @@ const descriptor: ESSearchSourceDescriptor = {
|
|||
};
|
||||
|
||||
describe('ES Search Source', () => {
|
||||
beforeEach(() => {
|
||||
require('../../../kibana_services').getUiSettings = () => ({
|
||||
get: jest.fn(),
|
||||
});
|
||||
});
|
||||
it('should create a vector layer', () => {
|
||||
const source = new ESSearchSource(descriptor, null);
|
||||
const layer = source.createDefaultLayer();
|
||||
|
|
|
@ -9,8 +9,7 @@ import {
|
|||
DEFAULT_MAX_INNER_RESULT_WINDOW,
|
||||
INDEX_SETTINGS_API_PATH,
|
||||
} from '../../../../common/constants';
|
||||
import { kfetch } from 'ui/kfetch';
|
||||
import { toastNotifications } from 'ui/notify';
|
||||
import { getHttp, getToasts } from '../../../kibana_services';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
let toastDisplayed = false;
|
||||
|
@ -27,9 +26,12 @@ export async function loadIndexSettings(indexPatternTitle) {
|
|||
}
|
||||
|
||||
async function fetchIndexSettings(indexPatternTitle) {
|
||||
const http = getHttp();
|
||||
const toasts = getToasts();
|
||||
try {
|
||||
const indexSettings = await kfetch({
|
||||
pathname: `../${INDEX_SETTINGS_API_PATH}`,
|
||||
const indexSettings = await http.fetch(`../${INDEX_SETTINGS_API_PATH}`, {
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
query: {
|
||||
indexPatternTitle,
|
||||
},
|
||||
|
@ -47,7 +49,7 @@ async function fetchIndexSettings(indexPatternTitle) {
|
|||
if (!toastDisplayed) {
|
||||
// Only show toast for first failure to avoid flooding user with warnings
|
||||
toastDisplayed = true;
|
||||
toastNotifications.addWarning(warningMsg);
|
||||
toasts.addWarning(warningMsg);
|
||||
}
|
||||
console.warn(warningMsg);
|
||||
return {
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
import { SingleFieldSelect } from '../../../components/single_field_select';
|
||||
import { TooltipSelector } from '../../../components/tooltip_selector';
|
||||
|
||||
import { indexPatternService } from '../../../kibana_services';
|
||||
import { getIndexPatternService } from '../../../kibana_services';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { getTermsFields, getSourceFields } from '../../../index_pattern_util';
|
||||
import { ValidatedRange } from '../../../components/validated_range';
|
||||
|
@ -69,7 +69,7 @@ export class UpdateSourceEditor extends Component {
|
|||
|
||||
async loadIndexSettings() {
|
||||
try {
|
||||
const indexPattern = await indexPatternService.get(this.props.indexPatternId);
|
||||
const indexPattern = await getIndexPatternService().get(this.props.indexPatternId);
|
||||
const { maxInnerResultWindow, maxResultWindow } = await loadIndexSettings(indexPattern.title);
|
||||
if (this._isMounted) {
|
||||
this.setState({ maxInnerResultWindow, maxResultWindow });
|
||||
|
@ -82,7 +82,7 @@ export class UpdateSourceEditor extends Component {
|
|||
async loadFields() {
|
||||
let indexPattern;
|
||||
try {
|
||||
indexPattern = await indexPatternService.get(this.props.indexPatternId);
|
||||
indexPattern = await getIndexPatternService().get(this.props.indexPatternId);
|
||||
} catch (err) {
|
||||
if (this._isMounted) {
|
||||
this.setState({
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
import { AbstractVectorSource } from './vector_source';
|
||||
import {
|
||||
autocompleteService,
|
||||
getAutocompleteService,
|
||||
fetchSearchSourceAndRecordWithInspector,
|
||||
indexPatternService,
|
||||
getIndexPatternService,
|
||||
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';
|
||||
|
@ -125,7 +125,7 @@ export class AbstractESSource extends AbstractVectorSource {
|
|||
allFilters.push(createExtentFilter(buffer, geoField.name, geoField.type));
|
||||
}
|
||||
if (isTimeAware) {
|
||||
allFilters.push(timefilter.createFilter(indexPattern, searchFilters.timeFilters));
|
||||
allFilters.push(getTimeFilter().createFilter(indexPattern, searchFilters.timeFilters));
|
||||
}
|
||||
|
||||
const searchSource = new SearchSource(initialSearchContext);
|
||||
|
@ -208,7 +208,7 @@ export class AbstractESSource extends AbstractVectorSource {
|
|||
}
|
||||
|
||||
try {
|
||||
this.indexPattern = await indexPatternService.get(this.getIndexPatternId());
|
||||
this.indexPattern = await getIndexPatternService().get(this.getIndexPatternId());
|
||||
return this.indexPattern;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
|
@ -305,7 +305,7 @@ export class AbstractESSource extends AbstractVectorSource {
|
|||
}
|
||||
if (style.isTimeAware() && (await this.isTimeAware())) {
|
||||
searchSource.setField('filter', [
|
||||
timefilter.createFilter(indexPattern, searchFilters.timeFilters),
|
||||
getTimeFilter().createFilter(indexPattern, searchFilters.timeFilters),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ export class AbstractESSource extends AbstractVectorSource {
|
|||
getValueSuggestions = async (field, query) => {
|
||||
try {
|
||||
const indexPattern = await this.getIndexPattern();
|
||||
return await autocompleteService.getValueSuggestions({
|
||||
return await getAutocompleteService().getValueSuggestions({
|
||||
indexPattern,
|
||||
field: indexPattern.fields.getByName(field.getRootName()),
|
||||
query,
|
||||
|
|
|
@ -8,7 +8,6 @@ import { ESTermSource, extractPropertiesMap } from './es_term_source';
|
|||
|
||||
jest.mock('ui/new_platform');
|
||||
jest.mock('../vector_layer', () => {});
|
||||
jest.mock('ui/timefilter', () => {});
|
||||
|
||||
const indexPatternTitle = 'myIndex';
|
||||
const termFieldName = 'myTermField';
|
||||
|
|
|
@ -7,11 +7,7 @@
|
|||
import React from 'react';
|
||||
import tinycolor from 'tinycolor2';
|
||||
import chroma from 'chroma-js';
|
||||
|
||||
import { euiPaletteColorBlind } from '@elastic/eui/lib/services';
|
||||
|
||||
import { getLegendColors, getColor } from 'ui/vis/map/color_util';
|
||||
|
||||
import { ColorGradient } from './components/color_gradient';
|
||||
import { COLOR_PALETTE_MAX_SIZE } from '../../../common/constants';
|
||||
import { vislibColorMaps } from '../../../../../../../src/plugins/charts/public';
|
||||
|
@ -30,6 +26,24 @@ export const DEFAULT_LINE_COLORS = [
|
|||
'#FFF',
|
||||
];
|
||||
|
||||
function getLegendColors(colorRamp, numLegendColors = 4) {
|
||||
const colors = [];
|
||||
colors[0] = getColor(colorRamp, 0);
|
||||
for (let i = 1; i < numLegendColors - 1; i++) {
|
||||
colors[i] = getColor(colorRamp, Math.floor((colorRamp.length * i) / numLegendColors));
|
||||
}
|
||||
colors[numLegendColors - 1] = getColor(colorRamp, colorRamp.length - 1);
|
||||
return colors;
|
||||
}
|
||||
|
||||
function getColor(colorRamp, i) {
|
||||
const color = colorRamp[i][1];
|
||||
const red = Math.floor(color[0] * 255);
|
||||
const green = Math.floor(color[1] * 255);
|
||||
const blue = Math.floor(color[2] * 255);
|
||||
return `rgb(${red},${green},${blue})`;
|
||||
}
|
||||
|
||||
function getColorRamp(colorRampName) {
|
||||
const colorRamp = vislibColorMaps[colorRampName];
|
||||
if (!colorRamp) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import React from 'react';
|
||||
|
||||
import chrome from 'ui/chrome';
|
||||
import { getUiSettings } from '../../../../../kibana_services';
|
||||
import { StylePropEditor } from '../style_prop_editor';
|
||||
import { DynamicIconForm } from './dynamic_icon_form';
|
||||
import { StaticIconForm } from './static_icon_form';
|
||||
|
@ -16,13 +16,13 @@ export function VectorStyleIconEditor(props) {
|
|||
const iconForm = props.styleProperty.isDynamic() ? (
|
||||
<DynamicIconForm
|
||||
{...props}
|
||||
isDarkMode={chrome.getUiSettingsClient().get('theme:darkMode', false)}
|
||||
isDarkMode={getUiSettings().get('theme:darkMode', false)}
|
||||
symbolOptions={SYMBOL_OPTIONS}
|
||||
/>
|
||||
) : (
|
||||
<StaticIconForm
|
||||
{...props}
|
||||
isDarkMode={chrome.getUiSettingsClient().get('theme:darkMode', false)}
|
||||
isDarkMode={getUiSettings().get('theme:darkMode', false)}
|
||||
symbolOptions={SYMBOL_OPTIONS}
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -9,6 +9,7 @@ import { DataRequest } from '../../util/data_request';
|
|||
import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types';
|
||||
import { FIELD_ORIGIN } from '../../../../common/constants';
|
||||
|
||||
jest.mock('../../../kibana_services');
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
class MockField {
|
||||
|
@ -65,7 +66,13 @@ describe('getDescriptorWithMissingStylePropsRemoved', () => {
|
|||
},
|
||||
};
|
||||
|
||||
it('Should return no changes when next oridinal fields contain existing style property fields', () => {
|
||||
beforeEach(() => {
|
||||
require('../../../kibana_services').getUiSettings = () => ({
|
||||
get: jest.fn(),
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return no changes when next ordinal fields contain existing style property fields', () => {
|
||||
const vectorStyle = new VectorStyle({ properties }, new MockSource());
|
||||
|
||||
const nextFields = [new MockField({ fieldName })];
|
||||
|
@ -73,7 +80,7 @@ describe('getDescriptorWithMissingStylePropsRemoved', () => {
|
|||
expect(hasChanges).toBe(false);
|
||||
});
|
||||
|
||||
it('Should clear missing fields when next oridinal fields do not contain existing style property fields', () => {
|
||||
it('Should clear missing fields when next ordinal fields do not contain existing style property fields', () => {
|
||||
const vectorStyle = new VectorStyle({ properties }, new MockSource());
|
||||
|
||||
const nextFields = [];
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
DEFAULT_FILL_COLORS,
|
||||
DEFAULT_LINE_COLORS,
|
||||
} from '../color_utils';
|
||||
import chrome from 'ui/chrome';
|
||||
import { getUiSettings } from '../../../kibana_services';
|
||||
|
||||
export const MIN_SIZE = 1;
|
||||
export const MAX_SIZE = 64;
|
||||
|
@ -67,7 +67,7 @@ export function getDefaultStaticProperties(mapColors = []) {
|
|||
const nextFillColor = DEFAULT_FILL_COLORS[nextColorIndex];
|
||||
const nextLineColor = DEFAULT_LINE_COLORS[nextColorIndex];
|
||||
|
||||
const isDarkMode = chrome.getUiSettingsClient().get('theme:darkMode', false);
|
||||
const isDarkMode = getUiSettings().get('theme:darkMode', false);
|
||||
|
||||
return {
|
||||
[VECTOR_STYLES.ICON]: {
|
||||
|
|
|
@ -19,9 +19,5 @@ const setupPlugins = {
|
|||
np: npSetup.plugins,
|
||||
};
|
||||
|
||||
const startPlugins = {
|
||||
np: npStart.plugins,
|
||||
};
|
||||
|
||||
export const setup = pluginInstance.setup(npSetup.core, setupPlugins);
|
||||
export const start = pluginInstance.start(npStart.core, startPlugins);
|
||||
export const start = pluginInstance.start(npStart.core, npStart.plugins);
|
||||
|
|
|
@ -8,14 +8,33 @@ 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 { MapListing } from './components/map_listing';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import {
|
||||
setLicenseId,
|
||||
setInspector,
|
||||
setFileUpload,
|
||||
setIndexPatternSelect,
|
||||
setHttp,
|
||||
setTimeFilter,
|
||||
setUiSettings,
|
||||
setInjectedVarFunc,
|
||||
setToasts,
|
||||
setIndexPatternService,
|
||||
setAutocompleteService,
|
||||
// @ts-ignore
|
||||
} from './kibana_services';
|
||||
// @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';
|
||||
import { setInjectedVarFunc as npSetInjectedVarFunc } from '../../../../plugins/maps/public/kibana_services'; // eslint-disable-line @kbn/eslint/no-restricted-paths
|
||||
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
|
||||
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';
|
||||
import { featureCatalogueEntry } from './feature_catalogue_entry';
|
||||
import {
|
||||
DataPublicPluginSetup,
|
||||
DataPublicPluginStart,
|
||||
} from '../../../../../src/plugins/data/public';
|
||||
|
||||
/**
|
||||
* These are the interfaces with your public contracts. You should export these
|
||||
|
@ -30,16 +49,38 @@ interface MapsPluginSetupDependencies {
|
|||
np: {
|
||||
licensing?: LicensingPluginSetup;
|
||||
home: HomePublicPluginSetup;
|
||||
data: DataPublicPluginSetup;
|
||||
};
|
||||
}
|
||||
|
||||
interface MapsPluginStartDependencies {
|
||||
data: DataPublicPluginStart;
|
||||
inspector: InspectorStartContract;
|
||||
// file_upload 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);
|
||||
setUiSettings(core.uiSettings);
|
||||
setInjectedVarFunc(core.injectedMetadata.getInjectedVar);
|
||||
npSetInjectedVarFunc(core.injectedMetadata.getInjectedVar);
|
||||
setToasts(core.notifications.toasts);
|
||||
};
|
||||
|
||||
export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => {
|
||||
const { file_upload, data, inspector } = plugins;
|
||||
setInspector(inspector);
|
||||
setFileUpload(file_upload);
|
||||
setIndexPatternSelect(data.ui.IndexPatternSelect);
|
||||
setTimeFilter(data.query.timefilter.timefilter);
|
||||
setIndexPatternService(data.indexPatterns);
|
||||
setAutocompleteService(data.autocompleteService);
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
|
@ -56,9 +97,7 @@ export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
|
|||
np.home.featureCatalogue.register(featureCatalogueEntry);
|
||||
}
|
||||
|
||||
public start(core: CoreStart, plugins: any) {
|
||||
const { inspector, file_upload } = plugins.np;
|
||||
setInspector(inspector);
|
||||
setFileUpload(file_upload);
|
||||
public start(core: CoreStart, plugins: MapsPluginStartDependencies) {
|
||||
bindStartCoreAndPlugins(core, plugins);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import { VectorLayer } from '../layers/vector_layer';
|
|||
import { HeatmapLayer } from '../layers/heatmap_layer';
|
||||
import { BlendedVectorLayer } from '../layers/blended_vector_layer';
|
||||
import { ALL_SOURCES } from '../layers/sources/all_sources';
|
||||
import { timefilter } from 'ui/timefilter';
|
||||
import { getTimeFilter } from '../kibana_services';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances';
|
||||
import {
|
||||
|
@ -109,7 +109,7 @@ export const getMapCenter = ({ map }) =>
|
|||
export const getMouseCoordinates = ({ map }) => map.mapState.mouseCoordinates;
|
||||
|
||||
export const getTimeFilters = ({ map }) =>
|
||||
map.mapState.timeFilters ? map.mapState.timeFilters : timefilter.getTime();
|
||||
map.mapState.timeFilters ? map.mapState.timeFilters : getTimeFilter().getTime();
|
||||
|
||||
export const getQuery = ({ map }) => map.mapState.query;
|
||||
|
||||
|
@ -132,7 +132,7 @@ export const getRefreshConfig = ({ map }) => {
|
|||
return map.mapState.refreshConfig;
|
||||
}
|
||||
|
||||
const refreshInterval = timefilter.getRefreshInterval();
|
||||
const refreshInterval = getTimeFilter().getRefreshInterval();
|
||||
return {
|
||||
isPaused: refreshInterval.pause,
|
||||
interval: refreshInterval.value,
|
||||
|
|
|
@ -15,15 +15,15 @@ jest.mock('../../../../../plugins/maps/public/reducers/non_serializable_instance
|
|||
return {};
|
||||
},
|
||||
}));
|
||||
jest.mock('ui/timefilter', () => ({
|
||||
timefilter: {
|
||||
jest.mock('../kibana_services', () => ({
|
||||
getTimeFilter: () => ({
|
||||
getTime: () => {
|
||||
return {
|
||||
to: 'now',
|
||||
from: 'now-15m',
|
||||
};
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
import { getTimeFilters } from './map_selectors';
|
||||
|
|
Loading…
Reference in a new issue