-
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
cfc16dc
commit 7762c1d
Showing
10 changed files
with
168 additions
and
141 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
4 changes: 2 additions & 2 deletions
4
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.drawControl { | ||
position: absolute; | ||
top: 12px; | ||
top: 10px; | ||
width: 200px; | ||
padding: 0; | ||
margin: 0 auto; | ||
left: 46px; | ||
} |
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
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> | ||
); | ||
} | ||
|
||
} |
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.