Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.12] [Maps] fix selecting EMS basemap does not populate input (#92711) #92944

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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