Skip to content

Commit

Permalink
[Maps] clear transient layer when required fields are cleared (#31726)
Browse files Browse the repository at this point in the history
* [Maps] clear transient layer when required fields are cleared

* review feedback
  • Loading branch information
nreese authored Feb 22, 2019
1 parent 4c5d281 commit 0b14bb4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
6 changes: 6 additions & 0 deletions x-pack/plugins/maps/public/components/layer_addpanel/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export class AddLayerPanel extends Component {
}

_previewLayer = (source) => {
if (!source) {
this.setState({ layer: null });
this.props.removeTransientLayer();
return;
}

this.setState({
layer: source.createDefaultLayer({}, this.props.mapColors)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,11 @@ export class CreateSourceEditor extends Component {
geoField,
requestType
} = this.state;
if (indexPatternId && geoField) {
this.props.onSelect({
indexPatternId,
geoField,
requestType: requestType.value
});
}

const sourceConfig = (indexPatternId && geoField)
? { indexPatternId, geoField, requestType: requestType.value }
: null;
this.props.onSelect(sourceConfig);
};

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

static renderEditor({ onPreviewSource, inspectorAdapters }) {
const onSelect = (sourceConfig) => {
if (!sourceConfig) {
onPreviewSource(null);
return;
}

const sourceDescriptor = ESGeoGridSource.createDescriptor(sourceConfig);
const source = new ESGeoGridSource(sourceDescriptor, inspectorAdapters);
onPreviewSource(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,11 @@ export class CreateSourceEditor extends Component {
indexPatternId,
geoField,
} = this.state;
if (indexPatternId && geoField) {
this.props.onSelect({
indexPatternId,
geoField,
});
}

const sourceConfig = (indexPatternId && geoField)
? { indexPatternId, geoField }
: null;
this.props.onSelect(sourceConfig);
}

_onNoIndexPatterns = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ export class ESSearchSource extends AbstractESSource {
static description = 'Geospatial data from a Kibana index pattern';

static renderEditor({ onPreviewSource, inspectorAdapters }) {
const onSelect = (layerConfig) => {
const layerSource = new ESSearchSource({
const onSelect = (sourceConfig) => {
if (!sourceConfig) {
onPreviewSource(null);
return;
}

const source = new ESSearchSource({
id: uuid(),
...layerConfig
...sourceConfig
}, inspectorAdapters);
onPreviewSource(layerSource);
onPreviewSource(source);
};
return (<CreateSourceEditor onSelect={onSelect}/>);
}
Expand Down

0 comments on commit 0b14bb4

Please sign in to comment.