Skip to content

Commit

Permalink
[Maps] fix selecting EMS basemap does not populate input (elastic#92711
Browse files Browse the repository at this point in the history
…) (elastic#92944)

* [Maps] fix selecting EMS basemap does not populate input

* tslint
  • Loading branch information
nreese authored Feb 26, 2021
1 parent e416b9b commit 819f640
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { Component } from 'react';
import { EuiPanel } from '@elastic/eui';
import { EmsTmsSourceConfig, TileServiceSelect } from './tile_service_select';

interface Props {
onTileSelect: (sourceConfig: EmsTmsSourceConfig) => void;
}

interface State {
config?: EmsTmsSourceConfig;
}

export class CreateSourceEditor extends Component<Props, State> {
state: State = {};

componentDidMount() {
this._onTileSelect({ id: null, isAutoSelect: true });
}

_onTileSelect = (config: EmsTmsSourceConfig) => {
this.setState({ config });
this.props.onTileSelect(config);
};

render() {
return (
<EuiPanel>
<TileServiceSelect onTileSelect={this._onTileSelect} config={this.state.config} />
</EuiPanel>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiPanel } from '@elastic/eui';
import { LayerWizard, RenderWizardArguments } from '../../layers/layer_wizard_registry';
// @ts-ignore
import { EMSTMSSource, getSourceTitle } from './ems_tms_source';
// @ts-ignore
import { VectorTileLayer } from '../../layers/vector_tile_layer/vector_tile_layer';
// @ts-ignore
import { TileServiceSelect } from './tile_service_select';
import { EmsTmsSourceConfig } from './tile_service_select';
import { CreateSourceEditor } from './create_source_editor';
import { getEMSSettings } from '../../../kibana_services';
import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants';
import { WorldMapLayerIcon } from '../../layers/icons/world_map_layer_icon';
Expand Down Expand Up @@ -45,18 +44,14 @@ export const emsBaseMapLayerWizardConfig: LayerWizard = {
},
icon: WorldMapLayerIcon,
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: unknown) => {
const onSourceConfigChange = (sourceConfig: EmsTmsSourceConfig) => {
const layerDescriptor = VectorTileLayer.createDescriptor({
sourceDescriptor: EMSTMSSource.createDescriptor(sourceConfig),
});
previewLayers([layerDescriptor]);
};

return (
<EuiPanel>
<TileServiceSelect onTileSelect={onSourceConfigChange} />
</EuiPanel>
);
return <CreateSourceEditor onTileSelect={onSourceConfigChange} />;
},
title: getSourceTitle(),
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,34 @@
* 2.0.
*/

import React from 'react';
import { EuiSelect, EuiFormRow } from '@elastic/eui';
import React, { ChangeEvent, Component } from 'react';
import { EuiSelect, EuiSelectOption, EuiFormRow } from '@elastic/eui';

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

export const AUTO_SELECT = 'auto_select';

export class TileServiceSelect extends React.Component {
state = {
export interface EmsTmsSourceConfig {
id: string | null;
isAutoSelect: boolean;
}

interface Props {
config?: EmsTmsSourceConfig;
onTileSelect: (sourceConfig: EmsTmsSourceConfig) => void;
}

interface State {
emsTmsOptions: EuiSelectOption[];
hasLoaded: boolean;
}

export class TileServiceSelect extends Component<Props, State> {
private _isMounted = false;

state: State = {
emsTmsOptions: [],
hasLoaded: false,
};
Expand Down Expand Up @@ -51,7 +68,7 @@ export class TileServiceSelect extends React.Component {
this.setState({ emsTmsOptions, hasLoaded: true });
};

_onChange = (e) => {
_onChange = (e: ChangeEvent<HTMLSelectElement>) => {
const value = e.target.value;
const isAutoSelect = value === AUTO_SELECT;
this.props.onTileSelect({
Expand All @@ -63,9 +80,9 @@ export class TileServiceSelect extends React.Component {
render() {
const helpText = this.state.emsTmsOptions.length === 0 ? getEmsUnavailableMessage() : null;

let selectedId;
let selectedId: string | undefined;
if (this.props.config) {
selectedId = this.props.config.isAutoSelect ? AUTO_SELECT : this.props.config.id;
selectedId = this.props.config.isAutoSelect ? AUTO_SELECT : this.props.config.id!;
}

return (
Expand Down

0 comments on commit 819f640

Please sign in to comment.