Skip to content

Commit

Permalink
[Maps] bump @elastic/ems-client and incorporate types (#68444)
Browse files Browse the repository at this point in the history
* [Maps] bump @elastic/ems-client and incorporate types

* tslint

* update to ems-client 7.9.2

* bump to 7.9.3

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
nreese and elasticmachine authored Jun 10, 2020
1 parent e616935 commit 332a138
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 200 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"@elastic/apm-rum": "^5.1.1",
"@elastic/charts": "19.2.0",
"@elastic/datemath": "5.0.3",
"@elastic/ems-client": "7.8.0",
"@elastic/ems-client": "7.9.3",
"@elastic/eui": "24.1.0",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
Expand Down
2 changes: 1 addition & 1 deletion x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"@babel/runtime": "^7.9.2",
"@elastic/apm-rum-react": "^1.1.1",
"@elastic/datemath": "5.0.3",
"@elastic/ems-client": "7.8.0",
"@elastic/ems-client": "7.9.3",
"@elastic/eui": "24.1.0",
"@elastic/filesaver": "1.1.2",
"@elastic/maki": "6.3.0",
Expand Down
8 changes: 1 addition & 7 deletions x-pack/plugins/maps/public/classes/fields/ems_file_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ export class EMSFileField extends AbstractField implements IField {
}

async getLabel(): Promise<string> {
const emsFileLayer = await this._source.getEMSFileLayer();
// TODO remove any and @ts-ignore when emsFileLayer type defined
// @ts-ignore
const emsFields: any[] = emsFileLayer.getFieldsInLanguage();
// Map EMS field name to language specific label
const emsField = emsFields.find((field) => field.name === this.getName());
return emsField ? emsField.description : this.getName();
return this._source.getEmsFieldLabel(this.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import React, { Component } from 'react';
import { EuiComboBox, EuiComboBoxOptionOption, EuiFormRow } from '@elastic/eui';

import { i18n } from '@kbn/i18n';
// @ts-ignore
import { getEMSClient } from '../../../meta';
import { FileLayer } from '@elastic/ems-client';
import { getEmsFileLayers } from '../../../meta';
import { getEmsUnavailableMessage } from '../ems_unavailable_message';
import { EMSFileSourceDescriptor } from '../../../../common/descriptor_types';

Expand All @@ -33,15 +33,10 @@ export class EMSFileCreateSourceEditor extends Component<Props, State> {
};

_loadFileOptions = async () => {
// @ts-ignore
const emsClient = getEMSClient();
// @ts-ignore
const fileLayers: unknown[] = await emsClient.getFileLayers();
const fileLayers: FileLayer[] = await getEmsFileLayers();
const options = fileLayers.map((fileLayer) => {
return {
// @ts-ignore
value: fileLayer.getId(),
// @ts-ignore
label: fileLayer.getDisplayName(),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,8 @@ jest.mock('../../layers/vector_layer/vector_layer', () => {});

function makeEMSFileSource(tooltipProperties: string[]) {
const emsFileSource = new EMSFileSource({ tooltipProperties });
emsFileSource.getEMSFileLayer = async () => {
return {
getFieldsInLanguage() {
return [
{
name: 'iso2',
description: 'ISO 2 CODE',
},
];
},
};
emsFileSource.getEmsFieldLabel = async (name: string) => {
return name === 'iso2' ? 'ISO 2 CODE' : name;
};
return emsFileSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import React, { ReactElement } from 'react';
import { i18n } from '@kbn/i18n';
import { Feature } from 'geojson';
import { Adapters } from 'src/plugins/inspector/public';
import { FileLayer } from '@elastic/ems-client';
import { Attribution, ImmutableSourceProperty, SourceEditorArgs } from '../source';
import { AbstractVectorSource, GeoJsonWithMeta, IVectorSource } from '../vector_source';
import { VECTOR_SHAPE_TYPES } from '../vector_feature_types';
import { SOURCE_TYPES, FIELD_ORIGIN } from '../../../../common/constants';
// @ts-ignore
import { getEMSClient } from '../../../meta';
import { getEmsFileLayers } from '../../../meta';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
import { UpdateSourceEditor } from './update_source_editor';
import { EMSFileField } from '../../fields/ems_file_field';
Expand All @@ -23,7 +23,7 @@ import { EMSFileSourceDescriptor } from '../../../../common/descriptor_types';
import { ITooltipProperty } from '../../tooltips/tooltip_property';

export interface IEmsFileSource extends IVectorSource {
getEMSFileLayer(): Promise<unknown>;
getEmsFieldLabel(emsFieldName: string): Promise<string>;
createField({ fieldName }: { fieldName: string }): IField;
}

Expand Down Expand Up @@ -72,13 +72,9 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc
);
}

async getEMSFileLayer(): Promise<unknown> {
// @ts-ignore
const emsClient = getEMSClient();
// @ts-ignore
const emsFileLayers = await emsClient.getFileLayers();
async getEMSFileLayer(): Promise<FileLayer> {
const emsFileLayers = await getEmsFileLayers();
const emsFileLayer = emsFileLayers.find(
// @ts-ignore
(fileLayer) => fileLayer.getId() === this._descriptor.id
);
if (!emsFileLayer) {
Expand All @@ -94,19 +90,25 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc
return emsFileLayer;
}

// Map EMS field name to language specific label
async getEmsFieldLabel(emsFieldName: string): Promise<string> {
const emsFileLayer = await this.getEMSFileLayer();
const emsFields = emsFileLayer.getFieldsInLanguage();

const emsField = emsFields.find((field) => field.name === emsFieldName);
return emsField ? emsField.description : emsFieldName;
}

async getGeoJsonWithMeta(): Promise<GeoJsonWithMeta> {
const emsFileLayer = await this.getEMSFileLayer();
// @ts-ignore
const featureCollection = await AbstractVectorSource.getGeoJson({
// @ts-ignore
format: emsFileLayer.getDefaultFormatType(),
featureCollectionPath: 'data',
// @ts-ignore
fetchUrl: emsFileLayer.getDefaultFormatUrl(),
});

// @ts-ignore
const emsIdField = emsFileLayer._config.fields.find((field) => {
const emsIdField = emsFileLayer.getFields().find((field) => {
return field.type === 'id';
});
featureCollection.features.forEach((feature: Feature, index: number) => {
Expand All @@ -123,7 +125,6 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc
let emsLink;
try {
const emsFileLayer = await this.getEMSFileLayer();
// @ts-ignore
emsLink = emsFileLayer.getEMSHotLink();
} catch (error) {
// ignore error if EMS layer id could not be found
Expand All @@ -147,7 +148,6 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc
async getDisplayName(): Promise<string> {
try {
const emsFileLayer = await this.getEMSFileLayer();
// @ts-ignore
return emsFileLayer.getDisplayName();
} catch (error) {
return this._descriptor.id;
Expand All @@ -156,15 +156,12 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc

async getAttributions(): Promise<Attribution[]> {
const emsFileLayer = await this.getEMSFileLayer();
// @ts-ignore
return emsFileLayer.getAttributions();
}

async getLeftJoinFields() {
const emsFileLayer = await this.getEMSFileLayer();
// @ts-ignore
const fields = emsFileLayer.getFieldsInLanguage();
// @ts-ignore
return fields.map((f) => this.createField({ fieldName: f.name }));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import React, { Component, Fragment } from 'react';
import { EuiTitle, EuiPanel, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { TooltipSelector } from '../../../components/tooltip_selector';
// @ts-ignore
import { getEMSClient } from '../../../meta';
import { getEmsFileLayers } from '../../../meta';
import { IEmsFileSource } from './ems_file_source';
import { IField } from '../../fields/field';
import { OnSourceChangeArgs } from '../../../connected_components/layer_panel/view';
Expand Down Expand Up @@ -42,22 +41,18 @@ export class UpdateSourceEditor extends Component<Props, State> {
}

async loadFields() {
let fields;
let fields: IField[] = [];
try {
// @ts-ignore
const emsClient = getEMSClient();
// @ts-ignore
const emsFiles = await emsClient.getFileLayers();
// @ts-ignore
const taregetEmsFile = emsFiles.find((emsFile) => emsFile.getId() === this.props.layerId);
// @ts-ignore
const emsFields = taregetEmsFile.getFieldsInLanguage();
// @ts-ignore
fields = emsFields.map((field) => this.props.source.createField({ fieldName: field.name }));
const emsFiles = await getEmsFileLayers();
const targetEmsFile = emsFiles.find((emsFile) => emsFile.getId() === this.props.layerId);
if (targetEmsFile) {
fields = targetEmsFile
.getFieldsInLanguage()
.map((field) => this.props.source.createField({ fieldName: field.name }));
}
} catch (e) {
// When a matching EMS-config cannot be found, the source already will have thrown errors during the data request.
// This will propagate to the vector-layer and be displayed in the UX
fields = [];
}

if (this._isMounted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import _ from 'lodash';
import React from 'react';
import { AbstractTMSSource } from '../tms_source';
import { getEMSClient } from '../../../meta';
import { getEmsTmsServices } from '../../../meta';
import { UpdateSourceEditor } from './update_source_editor';
import { i18n } from '@kbn/i18n';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
Expand Down Expand Up @@ -66,8 +66,7 @@ export class EMSTMSSource extends AbstractTMSSource {
}

async _getEMSTMSService() {
const emsClient = getEMSClient();
const emsTMSServices = await emsClient.getTMSServices();
const emsTMSServices = await getEmsTmsServices();
const emsTileLayerId = this.getTileLayerId();
const tmsService = emsTMSServices.find((tmsService) => tmsService.getId() === emsTileLayerId);
if (!tmsService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

jest.mock('../../../meta', () => {
return {
getEMSClient: () => {
getEmsTmsServices: () => {
class MockTMSService {
constructor(config) {
this._config = config;
Expand All @@ -19,20 +19,16 @@ jest.mock('../../../meta', () => {
}
}

return {
async getTMSServices() {
return [
new MockTMSService({
id: 'road_map',
attributionMarkdown: '[foobar](http://foobar.org) | [foobaz](http://foobaz.org)',
}),
new MockTMSService({
id: 'satellite',
attributionMarkdown: '[satellite](http://satellite.org)',
}),
];
},
};
return [
new MockTMSService({
id: 'road_map',
attributionMarkdown: '[foobar](http://foobar.org) | [foobaz](http://foobaz.org)',
}),
new MockTMSService({
id: 'satellite',
attributionMarkdown: '[satellite](http://satellite.org)',
}),
];
},
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { EuiSelect, EuiFormRow } from '@elastic/eui';

import { getEMSClient } from '../../../meta';
import { getEmsTmsServices } from '../../../meta';
import { getEmsUnavailableMessage } from '../ems_unavailable_message';
import { i18n } from '@kbn/i18n';

Expand All @@ -29,8 +29,7 @@ export class TileServiceSelect extends React.Component {
}

_loadTmsOptions = async () => {
const emsClient = getEMSClient();
const emsTMSServices = await emsClient.getTMSServices();
const emsTMSServices = await getEmsTmsServices();

if (!this._isMounted) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import { KibanaRegionmapSource, sourceTitle } from './kibana_regionmap_source';
import { VectorLayer } from '../../layers/vector_layer/vector_layer';
// @ts-ignore
import { CreateSourceEditor } from './create_source_editor';
// @ts-ignore
import { getKibanaRegionList } from '../../../meta';

export const kibanaRegionMapLayerWizardConfig: LayerWizard = {
checkVisibility: () => {
checkVisibility: async () => {
const regions = getKibanaRegionList();
return regions.length;
return regions.length > 0;
},
description: i18n.translate('xpack.maps.source.kbnRegionMapDescription', {
defaultMessage: 'Vector data from hosted GeoJSON configured in kibana.yml',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { CreateSourceEditor } from './create_source_editor';
// @ts-ignore
import { KibanaTilemapSource, sourceTitle } from './kibana_tilemap_source';
import { TileLayer } from '../../layers/tile_layer/tile_layer';
// @ts-ignore
import { getKibanaTileMap } from '../../../meta';

export const kibanaBasemapLayerWizardConfig: LayerWizard = {
checkVisibility: async () => {
const tilemap = getKibanaTileMap();
// @ts-ignore
return !!tilemap.url;
},
description: i18n.translate('xpack.maps.source.kbnTMSDescription', {
Expand Down
Loading

0 comments on commit 332a138

Please sign in to comment.