-
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.
[Maps] Move legend rendering to style property (#53173)
- Loading branch information
1 parent
3ee0683
commit 87a9b6b
Showing
10 changed files
with
156 additions
and
106 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
57 changes: 0 additions & 57 deletions
57
...y/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js
This file was deleted.
Oops, something went wrong.
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
81 changes: 81 additions & 0 deletions
81
...gacy/plugins/maps/public/layers/styles/vector/properties/components/dynamic_legend_row.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,81 @@ | ||
/* | ||
* 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 _ from 'lodash'; | ||
import { RangedStyleLegendRow } from '../../../components/ranged_style_legend_row'; | ||
import { getVectorStyleLabel } from '../../components/get_vector_style_label'; | ||
|
||
const EMPTY_VALUE = ''; | ||
|
||
export class DynamicLegendRow extends React.Component { | ||
constructor() { | ||
super(); | ||
this._isMounted = false; | ||
this.state = { | ||
label: EMPTY_VALUE, | ||
}; | ||
} | ||
|
||
async _loadParams() { | ||
const label = await this.props.style.getField().getLabel(); | ||
const newState = { label }; | ||
if (this._isMounted && !_.isEqual(this.state, newState)) { | ||
this.setState(newState); | ||
} | ||
} | ||
|
||
componentDidUpdate() { | ||
this._loadParams(); | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
} | ||
|
||
componentDidMount() { | ||
this._isMounted = true; | ||
this._loadParams(); | ||
} | ||
|
||
_formatValue(value) { | ||
if (value === EMPTY_VALUE) { | ||
return value; | ||
} | ||
return this.props.style.formatField(value); | ||
} | ||
|
||
render() { | ||
const fieldMeta = this.props.style.getFieldMeta(); | ||
|
||
let minLabel = EMPTY_VALUE; | ||
let maxLabel = EMPTY_VALUE; | ||
if (fieldMeta) { | ||
const range = { min: fieldMeta.min, max: fieldMeta.max }; | ||
const min = this._formatValue(_.get(range, 'min', EMPTY_VALUE)); | ||
minLabel = | ||
this.props.style.isFieldMetaEnabled() && range && range.isMinOutsideStdRange | ||
? `< ${min}` | ||
: min; | ||
|
||
const max = this._formatValue(_.get(range, 'max', EMPTY_VALUE)); | ||
maxLabel = | ||
this.props.style.isFieldMetaEnabled() && range && range.isMaxOutsideStdRange | ||
? `> ${max}` | ||
: max; | ||
} | ||
|
||
return ( | ||
<RangedStyleLegendRow | ||
header={this.props.style.renderLegendHeader()} | ||
minLabel={minLabel} | ||
maxLabel={maxLabel} | ||
propertyLabel={getVectorStyleLabel(this.props.style.getStyleName())} | ||
fieldLabel={this.state.label} | ||
/> | ||
); | ||
} | ||
} |
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
Oops, something went wrong.