-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into search-session-enhanced
- Loading branch information
Showing
52 changed files
with
3,863 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/maps/public/classes/sources/es_geo_line_source/convert_to_geojson.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { convertToGeoJson } from './convert_to_geojson'; | ||
|
||
const esResponse = { | ||
aggregations: { | ||
tracks: { | ||
buckets: { | ||
ios: { | ||
doc_count: 1, | ||
path: { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: [ | ||
[-95.339639, 41.584389], | ||
[-95.339639, 41.0], | ||
], | ||
}, | ||
properties: { | ||
complete: true, | ||
}, | ||
}, | ||
}, | ||
osx: { | ||
doc_count: 1, | ||
path: { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: [ | ||
[-97.902775, 48.940572], | ||
[-97.902775, 48.0], | ||
], | ||
}, | ||
properties: { | ||
complete: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
it('Should convert elasticsearch aggregation response into feature collection', () => { | ||
const geoJson = convertToGeoJson(esResponse, 'machine.os.keyword'); | ||
expect(geoJson.numTrimmedTracks).toBe(1); | ||
expect(geoJson.featureCollection.features.length).toBe(2); | ||
expect(geoJson.featureCollection.features[0]).toEqual({ | ||
geometry: { | ||
coordinates: [ | ||
[-95.339639, 41.584389], | ||
[-95.339639, 41.0], | ||
], | ||
type: 'LineString', | ||
}, | ||
id: 'ios', | ||
properties: { | ||
complete: true, | ||
doc_count: 1, | ||
['machine.os.keyword']: 'ios', | ||
}, | ||
type: 'Feature', | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/maps/public/classes/sources/es_geo_line_source/convert_to_geojson.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import { Feature, FeatureCollection } from 'geojson'; | ||
import { extractPropertiesFromBucket } from '../../../../common/elasticsearch_util'; | ||
|
||
const KEYS_TO_IGNORE = ['key', 'path']; | ||
|
||
export function convertToGeoJson(esResponse: any, entitySplitFieldName: string) { | ||
const features: Feature[] = []; | ||
let numTrimmedTracks = 0; | ||
|
||
const buckets = _.get(esResponse, 'aggregations.tracks.buckets', {}); | ||
const entityKeys = Object.keys(buckets); | ||
for (let i = 0; i < entityKeys.length; i++) { | ||
const entityKey = entityKeys[i]; | ||
const bucket = buckets[entityKey]; | ||
const feature = bucket.path as Feature; | ||
if (!feature.properties!.complete) { | ||
numTrimmedTracks++; | ||
} | ||
feature.id = entityKey; | ||
feature.properties = { | ||
[entitySplitFieldName]: entityKey, | ||
...feature.properties, | ||
...extractPropertiesFromBucket(bucket, KEYS_TO_IGNORE), | ||
}; | ||
features.push(feature); | ||
} | ||
|
||
return { | ||
featureCollection: { | ||
type: 'FeatureCollection', | ||
features, | ||
} as FeatureCollection, | ||
numTrimmedTracks, | ||
}; | ||
} |
151 changes: 151 additions & 0 deletions
151
x-pack/plugins/maps/public/classes/sources/es_geo_line_source/create_source_editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
|
||
import { IndexPattern } from 'src/plugins/data/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiFormRow, EuiPanel } from '@elastic/eui'; | ||
import { SingleFieldSelect } from '../../../components/single_field_select'; | ||
import { GeoIndexPatternSelect } from '../../../components/geo_index_pattern_select'; | ||
|
||
import { getGeoPointFields } from '../../../index_pattern_util'; | ||
import { GeoLineForm } from './geo_line_form'; | ||
|
||
interface Props { | ||
onSourceConfigChange: ( | ||
sourceConfig: { | ||
indexPatternId: string; | ||
geoField: string; | ||
splitField: string; | ||
sortField: string; | ||
} | null | ||
) => void; | ||
} | ||
|
||
interface State { | ||
indexPattern: IndexPattern | null; | ||
geoField: string; | ||
splitField: string; | ||
sortField: string; | ||
} | ||
|
||
export class CreateSourceEditor extends Component<Props, State> { | ||
state: State = { | ||
indexPattern: null, | ||
geoField: '', | ||
splitField: '', | ||
sortField: '', | ||
}; | ||
|
||
_onIndexPatternSelect = (indexPattern: IndexPattern) => { | ||
const pointFields = getGeoPointFields(indexPattern.fields); | ||
this.setState( | ||
{ | ||
indexPattern, | ||
geoField: pointFields.length ? pointFields[0].name : '', | ||
sortField: indexPattern.timeFieldName ? indexPattern.timeFieldName : '', | ||
}, | ||
this.previewLayer | ||
); | ||
}; | ||
|
||
_onGeoFieldSelect = (geoField?: string) => { | ||
if (geoField === undefined) { | ||
return; | ||
} | ||
|
||
this.setState( | ||
{ | ||
geoField, | ||
}, | ||
this.previewLayer | ||
); | ||
}; | ||
|
||
_onSplitFieldSelect = (newValue: string) => { | ||
this.setState( | ||
{ | ||
splitField: newValue, | ||
}, | ||
this.previewLayer | ||
); | ||
}; | ||
|
||
_onSortFieldSelect = (newValue: string) => { | ||
this.setState( | ||
{ | ||
sortField: newValue, | ||
}, | ||
this.previewLayer | ||
); | ||
}; | ||
|
||
previewLayer = () => { | ||
const { indexPattern, geoField, splitField, sortField } = this.state; | ||
|
||
const sourceConfig = | ||
indexPattern && indexPattern.id && geoField && splitField && sortField | ||
? { indexPatternId: indexPattern.id, geoField, splitField, sortField } | ||
: null; | ||
this.props.onSourceConfigChange(sourceConfig); | ||
}; | ||
|
||
_renderGeoSelect() { | ||
if (!this.state.indexPattern) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<EuiFormRow | ||
label={i18n.translate('xpack.maps.source.esGeoLine.geofieldLabel', { | ||
defaultMessage: 'Geospatial field', | ||
})} | ||
> | ||
<SingleFieldSelect | ||
placeholder={i18n.translate('xpack.maps.source.esGeoLine.geofieldPlaceholder', { | ||
defaultMessage: 'Select geo field', | ||
})} | ||
value={this.state.geoField} | ||
onChange={this._onGeoFieldSelect} | ||
fields={getGeoPointFields(this.state.indexPattern.fields)} | ||
/> | ||
</EuiFormRow> | ||
); | ||
} | ||
|
||
_renderGeoLineForm() { | ||
if (!this.state.indexPattern || !this.state.geoField) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<GeoLineForm | ||
indexPattern={this.state.indexPattern} | ||
onSortFieldChange={this._onSortFieldSelect} | ||
onSplitFieldChange={this._onSplitFieldSelect} | ||
sortField={this.state.sortField} | ||
splitField={this.state.splitField} | ||
/> | ||
); | ||
} | ||
|
||
render() { | ||
return ( | ||
<EuiPanel> | ||
<GeoIndexPatternSelect | ||
value={ | ||
this.state.indexPattern && this.state.indexPattern.id ? this.state.indexPattern.id : '' | ||
} | ||
onChange={this._onIndexPatternSelect} | ||
isGeoPointsOnly={true} | ||
/> | ||
{this._renderGeoSelect()} | ||
{this._renderGeoLineForm()} | ||
</EuiPanel> | ||
); | ||
} | ||
} |
Oops, something went wrong.