-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65ac8d6
commit f9f653e
Showing
29 changed files
with
741 additions
and
45 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
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/maps/public/components/draw_control/_index.scss
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,7 @@ | ||
.drawControl { | ||
position: absolute; | ||
top: 10px; | ||
width: 200px; | ||
padding: 0; | ||
left: 46px; | ||
} |
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/maps/public/components/draw_control/index.js
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,31 @@ | ||
/* | ||
* 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 { connect } from 'react-redux'; | ||
import { DrawControl } from './view'; | ||
import { getDrawState, getUniqueIndexPatternIds } from '../../selectors/map_selectors'; | ||
import { DRAW_STATE_TYPE, updateDrawStateWithOptions } from '../../actions/store_actions'; | ||
import { getIsReadOnly } from '../../store/ui'; | ||
|
||
function mapStateToProps(state = {}) { | ||
return { | ||
isReadOnly: getIsReadOnly(state), | ||
drawState: getDrawState(state), | ||
uniqueIndexPatternIds: getUniqueIndexPatternIds(state) | ||
}; | ||
} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return { | ||
initiateDraw: (options) => { | ||
dispatch(updateDrawStateWithOptions(DRAW_STATE_TYPE.ACTIVE, options)); | ||
}, | ||
|
||
}; | ||
} | ||
|
||
const connectedViewControl = connect(mapStateToProps, mapDispatchToProps)(DrawControl); | ||
export { connectedViewControl as DrawControl }; |
107 changes: 107 additions & 0 deletions
107
x-pack/plugins/maps/public/components/draw_control/initiate_draw_button.js
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,107 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { | ||
EuiButton, | ||
EuiPopover | ||
} from '@elastic/eui'; | ||
import { IpSelectionList } from './ip_selection_list'; | ||
import { DRAW_STATE_TYPE } from '../../actions/store_actions'; | ||
import _ from 'lodash'; | ||
import { getIndexPatternsFromIds } from '../../index_pattern_util'; | ||
|
||
export class InitiateDrawButton extends React.Component { | ||
|
||
state = { | ||
openPopover: false, | ||
uniqueIndexPatternsAndGeoFields: [] | ||
}; | ||
|
||
_openIndexPatternSelection = () => { | ||
if (this._isMounted) { | ||
this.setState({ openPopover: true }); | ||
} | ||
}; | ||
|
||
_closePopover = () => { | ||
if (this._isMounted) { | ||
this.setState({ openPopover: false }); | ||
} | ||
}; | ||
|
||
_onSelect = (e) => { | ||
this._closePopover(); | ||
this.props.initiateDraw(e); | ||
}; | ||
|
||
async _getuniqueIndexPatternAndFieldCombos() { | ||
|
||
const indexPatterns = await getIndexPatternsFromIds(this.props.uniqueIndexPatternIds); | ||
try { | ||
|
||
const uniqueIndexPatternsAndGeofields = []; | ||
indexPatterns.forEach((indexPattern) => { | ||
indexPattern.fields.forEach(field => { | ||
if (field.type === 'geo_point') { | ||
uniqueIndexPatternsAndGeofields.push({ | ||
geoField: field.name, | ||
indexPatternTitle: indexPattern.title, | ||
indexPatternId: indexPattern.id | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
|
||
if (this._isMounted && !_.isEqual(this.state.uniqueIndexPatternsAndGeoFields, uniqueIndexPatternsAndGeofields)) { | ||
this.setState({ | ||
uniqueIndexPatternsAndGeoFields: uniqueIndexPatternsAndGeofields, | ||
openPopover: false | ||
}); | ||
} | ||
} catch(e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
this._isMounted = true; | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
} | ||
|
||
componentDidUpdate() { | ||
this._getuniqueIndexPatternAndFieldCombos(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<EuiPopover | ||
button={ | ||
<EuiButton | ||
disabled={this.props.drawState.type === DRAW_STATE_TYPE.ACTIVE && this.state.uniqueIndexPatternsAndGeoFields.length !== 0} | ||
fill | ||
size="s" | ||
onClick={this._openIndexPatternSelection} | ||
> | ||
{this.props.buttonText} | ||
</EuiButton> | ||
} | ||
isOpen={this.state.openPopover} | ||
closePopover={this._closePopover} | ||
anchorPosition="downLeft" | ||
> | ||
<IpSelectionList indexPatternsAndGeoFields={this.state.uniqueIndexPatternsAndGeoFields} onSelect={this._onSelect}/> | ||
</EuiPopover> | ||
); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/maps/public/components/draw_control/ip_selection_list.js
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,46 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { | ||
EuiFlexGroup, | ||
EuiButton, | ||
EuiFlexItem | ||
} from '@elastic/eui'; | ||
|
||
|
||
export class IpSelectionList extends React.Component { | ||
|
||
|
||
_renderList() { | ||
return this.props.indexPatternsAndGeoFields.map((indexPatternAndGeoField, index) => { | ||
|
||
const onClick = () => { | ||
this.props.onSelect(indexPatternAndGeoField); | ||
}; | ||
|
||
return ( | ||
<EuiFlexItem key={index}> | ||
<EuiButton | ||
onClick={onClick} | ||
> | ||
{`${indexPatternAndGeoField.indexPatternTitle}.${indexPatternAndGeoField.geoField}`} | ||
</EuiButton> | ||
</EuiFlexItem> | ||
); | ||
}); | ||
|
||
} | ||
|
||
render() { | ||
|
||
return ( | ||
<EuiFlexGroup direction="column"> | ||
{this._renderList()} | ||
</EuiFlexGroup> | ||
); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
x-pack/plugins/maps/public/components/draw_control/view.js
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,55 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { InitiateDrawButton } from './initiate_draw_button'; | ||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem | ||
} from '@elastic/eui'; | ||
|
||
|
||
|
||
import { DRAW_STATE_DRAW_TYPE } from '../../actions/store_actions'; | ||
|
||
export class DrawControl extends React.Component { | ||
|
||
_initiateDraw = (drawType, e) => { | ||
this.props.initiateDraw({ drawType, ...e }); | ||
}; | ||
|
||
render() { | ||
|
||
if (!this.props.isReadOnly) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="drawControl"> | ||
<EuiFlexGroup direction="row"> | ||
<EuiFlexItem> | ||
<InitiateDrawButton | ||
initiateDraw={(e) => this._initiateDraw(DRAW_STATE_DRAW_TYPE.POLYGON, e)} | ||
uniqueIndexPatternIds={this.props.uniqueIndexPatternIds} | ||
drawState={this.props.drawState} | ||
buttonText="Draw polygon" | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<InitiateDrawButton | ||
initiateDraw={(e) => this._initiateDraw(DRAW_STATE_DRAW_TYPE.BOUNDS, e)} | ||
uniqueIndexPatternIds={this.props.uniqueIndexPatternIds} | ||
drawState={this.props.drawState} | ||
buttonText="Draw bounds" | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
|
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
Oops, something went wrong.