From 72166f9e5fe3f2e431862dd12469990f5ffdd25f Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 3 Jan 2020 08:14:19 -0500 Subject: [PATCH] [Maps] pass getFieldFormatter to DynamicTextProperty --- .../components/label/dynamic_label_editor.js | 32 +++++++++++++++++ .../components/label/static_label_editor.js | 34 +++++++++++++++++++ .../layers/styles/vector/vector_style.js | 8 ++++- .../maps/public/layers/util/can_skip_fetch.js | 2 +- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/label/dynamic_label_editor.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/components/label/static_label_editor.js diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/label/dynamic_label_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/label/dynamic_label_editor.js new file mode 100644 index 0000000000000..3c9499dbafa8e --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/label/dynamic_label_editor.js @@ -0,0 +1,32 @@ +/* + * 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 React from 'react'; +import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { FieldSelect } from '../field_select'; + +export function DynamicLabelEditor(props) { + const styleOptions = props.styleProperty.getOptions(); + + const onFieldChange = ({ field }) => { + props.onDynamicStyleChange(props.styleProperty.getStyleName(), { ...styleOptions, field }); + }; + + return ( + + {props.staticDynamicSelect} + + + + + ); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/label/static_label_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/label/static_label_editor.js new file mode 100644 index 0000000000000..df00fa3cbbe2a --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/label/static_label_editor.js @@ -0,0 +1,34 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { EuiFieldText, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; + +export function StaticLabelEditor(props) { + const onValueChange = event => { + props.onStaticStyleChange(props.styleProperty.getStyleName(), { value: event.target.value }); + }; + + return ( + + {props.staticDynamicSelect} + + + + + ); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index dc688d1291518..ae434f5002800 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -613,7 +613,13 @@ export class VectorStyle extends AbstractStyle { return new StaticTextProperty(descriptor.options, VECTOR_STYLES.LABEL_TEXT); } else if (descriptor.type === DynamicStyleProperty.type) { const field = this._makeField(descriptor.options.field); - return new DynamicTextProperty(descriptor.options, VECTOR_STYLES.LABEL_TEXT, field); + return new DynamicTextProperty( + descriptor.options, + VECTOR_STYLES.LABEL_TEXT, + field, + this._getFieldMeta, + this._getFieldFormatter + ); } else { throw new Error(`${descriptor} not implemented`); } diff --git a/x-pack/legacy/plugins/maps/public/layers/util/can_skip_fetch.js b/x-pack/legacy/plugins/maps/public/layers/util/can_skip_fetch.js index d9182be56a75f..7abfee1b184f0 100644 --- a/x-pack/legacy/plugins/maps/public/layers/util/can_skip_fetch.js +++ b/x-pack/legacy/plugins/maps/public/layers/util/can_skip_fetch.js @@ -168,5 +168,5 @@ export function canSkipFormattersUpdate({ prevDataRequest, nextMeta }) { return false; } - return !_.isEqual(prevMeta.fieldNames, nextMeta.fieldNames); + return _.isEqual(prevMeta.fieldNames, nextMeta.fieldNames); }