Skip to content

Commit

Permalink
[Maps] source renderEditor clean-up (#41124) (#41143)
Browse files Browse the repository at this point in the history
* [Maps] cleanup Source renderEditor callback to have more consistent naming across sources

* more clean-up
  • Loading branch information
nreese authored Jul 15, 2019
1 parent e0f1a98 commit 9779d94
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class EMSFileCreateSourceEditor extends React.Component {
this.setState({ selectedOption: selectedOptions[0] });

const emsFileId = selectedOptions[0].value;
this.props.onChange(emsFileId);
this.props.onSourceConfigChange({ id: emsFileId });
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export class EMSFileSource extends AbstractVectorSource {
}

static renderEditor({ onPreviewSource, inspectorAdapters }) {
const onChange = (selectedId) => {
const emsFileSourceDescriptor = EMSFileSource.createDescriptor({ id: selectedId });
const emsFileSource = new EMSFileSource(emsFileSourceDescriptor, inspectorAdapters);
onPreviewSource(emsFileSource);
const onSourceConfigChange = (sourceConfig) => {
const sourceDescriptor = EMSFileSource.createDescriptor(sourceConfig);
const source = new EMSFileSource(sourceDescriptor, inspectorAdapters);
onPreviewSource(source);
};
return <EMSFileCreateSourceEditor onChange={onChange}/>;
return <EMSFileCreateSourceEditor onSourceConfigChange={onSourceConfigChange}/>;
}

constructor(descriptor, inspectorAdapters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const requestTypeOptions = [
export class CreateSourceEditor extends Component {

static propTypes = {
onSelect: PropTypes.func.isRequired,
onSourceConfigChange: PropTypes.func.isRequired,
};

state = {
Expand Down Expand Up @@ -141,7 +141,7 @@ export class CreateSourceEditor extends Component {
const sourceConfig = (indexPatternId && geoField)
? { indexPatternId, geoField, requestType: requestType.value }
: null;
this.props.onSelect(sourceConfig);
this.props.onSourceConfigChange(sourceConfig);
};

_onNoIndexPatterns = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class ESGeoGridSource extends AbstractESSource {
}

static renderEditor({ onPreviewSource, inspectorAdapters }) {
const onSelect = (sourceConfig) => {
const onSourceConfigChange = (sourceConfig) => {
if (!sourceConfig) {
onPreviewSource(null);
return;
Expand All @@ -83,7 +83,7 @@ export class ESGeoGridSource extends AbstractESSource {
onPreviewSource(source);
};

return (<CreateSourceEditor onSelect={onSelect}/>);
return (<CreateSourceEditor onSourceConfigChange={onSourceConfigChange}/>);
}

renderSourceSettingsEditor({ onChange }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const RESET_INDEX_PATTERN_STATE = {
export class CreateSourceEditor extends Component {

static propTypes = {
onSelect: PropTypes.func.isRequired,
onSourceConfigChange: PropTypes.func.isRequired,
};

state = {
Expand Down Expand Up @@ -142,7 +142,7 @@ export class CreateSourceEditor extends Component {
const sourceConfig = (indexPatternId && geoField)
? { indexPatternId, geoField, filterByMapBounds }
: null;
this.props.onSelect(sourceConfig);
this.props.onSourceConfigChange(sourceConfig);
}

_onNoIndexPatterns = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ESSearchSource extends AbstractESSource {
});

static renderEditor({ onPreviewSource, inspectorAdapters }) {
const onSelect = (sourceConfig) => {
const onSourceConfigChange = (sourceConfig) => {
if (!sourceConfig) {
onPreviewSource(null);
return;
Expand All @@ -45,7 +45,7 @@ export class ESSearchSource extends AbstractESSource {
}, inspectorAdapters);
onPreviewSource(source);
};
return (<CreateSourceEditor onSelect={onSelect}/>);
return (<CreateSourceEditor onSourceConfigChange={onSourceConfigChange}/>);
}

constructor(descriptor, inspectorAdapters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,45 @@ import {
import { getKibanaRegionList } from '../../../../meta';
import { i18n } from '@kbn/i18n';

export class CreateSourceEditor extends React.Component {
export function CreateSourceEditor({ onSourceConfigChange }) {

state = {
regionmapLayers: []
}

_loadList = async () => {
const list = getKibanaRegionList();
if (this._isMounted) {
this.setState({
regionmapLayers: list
});
}
const onChange = ({ target }) => {
const selectedName = target.options[target.selectedIndex].text;
onSourceConfigChange({ name: selectedName });
};

componentWillUnmount() {
this._isMounted = false;
}

componentDidMount() {
this._isMounted = true;
this._loadList();
}

render() {

const onChange = ({ target }) => {
const selectedName = target.options[target.selectedIndex].text;
this.props.onSelect({ name: selectedName });
const regionmapOptions = getKibanaRegionList().map(({ name, url }) => {
return {
value: url,
text: name
};

const regionmapOptions = this.state.regionmapLayers.map(({ name, url }) => {
return {
value: url,
text: name
};
});

return (
<EuiFormRow
label={
i18n.translate('xpack.maps.source.kbnRegionMap.vectorLayerLabel', {
defaultMessage: 'Vector layer'
})
}
helpText={this.state.regionmapLayers.length === 0 ? i18n.translate('xpack.maps.source.kbnRegionMap.noLayerAvailableHelptext', {
defaultMessage: `No vector layers are available. Ask your system administrator to set "map.regionmap" in kibana.yml.`
});

const helpText = regionmapOptions.length === 0
? i18n.translate('xpack.maps.source.kbnRegionMap.noLayerAvailableHelptext', {
defaultMessage: `No vector layers are available. Ask your system administrator to set "map.regionmap" in kibana.yml.`
})
: null;

return (
<EuiFormRow
label={
i18n.translate('xpack.maps.source.kbnRegionMap.vectorLayerLabel', {
defaultMessage: 'Vector layer'
})
: null}
>
<EuiSelect
hasNoInitialSelection
options={regionmapOptions}
onChange={onChange}
disabled={this.state.regionmapLayers.length === 0}
/>
</EuiFormRow>
);
}
}
helpText={helpText}
>
<EuiSelect
hasNoInitialSelection
options={regionmapOptions}
onChange={onChange}
disabled={regionmapOptions.length === 0}
/>
</EuiFormRow>
);
}

CreateSourceEditor.propTypes = {
onSelect: PropTypes.func.isRequired
onSourceConfigChange: PropTypes.func.isRequired
};


Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ export class KibanaRegionmapSource extends AbstractVectorSource {
;
static icon = 'logoKibana';

static createDescriptor(options) {
static createDescriptor({ name }) {
return {
type: KibanaRegionmapSource.type,
name: options.name
name: name
};
}

static renderEditor = ({ onPreviewSource, inspectorAdapters }) => {
const onSelect = (layerConfig) => {
const sourceDescriptor = KibanaRegionmapSource.createDescriptor(layerConfig);
const onSourceConfigChange = (sourceConfig) => {
const sourceDescriptor = KibanaRegionmapSource.createDescriptor(sourceConfig);
const source = new KibanaRegionmapSource(sourceDescriptor, inspectorAdapters);
onPreviewSource(source);
};

return (
<CreateSourceEditor
onSelect={onSelect}
onSourceConfigChange={onSourceConfigChange}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Component } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import {
EuiFieldText,
Expand All @@ -14,62 +14,34 @@ import {
import { getKibanaTileMap } from '../../../../meta';
import { i18n } from '@kbn/i18n';

export class CreateSourceEditor extends Component {
export function CreateSourceEditor({ onSourceConfigChange }) {

state = {
url: null
};
const tilemap = getKibanaTileMap();

_loadUrl = async () => {
const tilemap = getKibanaTileMap();
if (this._isMounted) {
this.setState(
{ url: tilemap.url },
() => {
if (this.state.url) {
this.props.previewTilemap();
}
}
);
}
};

componentWillUnmount() {
this._isMounted = false;
}

componentDidMount() {
this._isMounted = true;
this._loadUrl();
if (tilemap.url) {
onSourceConfigChange();
}

render() {

if (this.state.url === null) {//still loading
return null;
}

return (
<EuiFormRow
label={
i18n.translate('xpack.maps.source.kbnTMS.kbnTMS.urlLabel', {
defaultMessage: 'Tilemap url'
})
}
helpText={this.state.url ? null : i18n.translate('xpack.maps.source.kbnTMS.noLayerAvailableHelptext', {
defaultMessage: 'No tilemap layer is available. Ask your system administrator to set "map.tilemap.url" in kibana.yml.'
return (
<EuiFormRow
label={
i18n.translate('xpack.maps.source.kbnTMS.kbnTMS.urlLabel', {
defaultMessage: 'Tilemap url'
})
}
>
<EuiFieldText
readOnly
value={this.state.url}
/>
</EuiFormRow>
);
}
}
helpText={tilemap.url ? null : i18n.translate('xpack.maps.source.kbnTMS.noLayerAvailableHelptext', {
defaultMessage: 'No tilemap layer is available. Ask your system administrator to set "map.tilemap.url" in kibana.yml.'
})
}
>
<EuiFieldText
readOnly
value={tilemap.url}
/>
</EuiFormRow>
);
}

CreateSourceEditor.propTypes = {
previewTilemap: PropTypes.func.isRequired
onSourceConfigChange: PropTypes.func.isRequired
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export class KibanaTilemapSource extends AbstractTMSSource {
}

static renderEditor = ({ onPreviewSource, inspectorAdapters }) => {
const previewTilemap = () => {
const onSourceConfigChange = () => {
const sourceDescriptor = KibanaTilemapSource.createDescriptor();
const source = new KibanaTilemapSource(sourceDescriptor, inspectorAdapters);
onPreviewSource(source);
};
return (<CreateSourceEditor previewTilemap={previewTilemap}/>);
return (<CreateSourceEditor onSourceConfigChange={onSourceConfigChange}/>);
};

async getImmutableProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class WMSCreateSourceEditor extends Component {
const sourceConfig = (serviceUrl && layers)
? { serviceUrl, layers, styles }
: null;
this.props.previewWMS(sourceConfig);
this.props.onSourceConfigChange(sourceConfig);
}

_loadCapabilities = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class WMSSource extends AbstractTMSSource {
}

static renderEditor({ onPreviewSource, inspectorAdapters }) {
const previewWMS = (sourceConfig) => {
const onSourceConfigChange = (sourceConfig) => {
if (!sourceConfig) {
onPreviewSource(null);
return;
Expand All @@ -44,7 +44,7 @@ export class WMSSource extends AbstractTMSSource {
const source = new WMSSource(sourceDescriptor, inspectorAdapters);
onPreviewSource(source);
};
return (<WMSCreateSourceEditor previewWMS={previewWMS} />);
return (<WMSCreateSourceEditor onSourceConfigChange={onSourceConfigChange} />);
}

async getImmutableProperties() {
Expand Down
Loading

0 comments on commit 9779d94

Please sign in to comment.