Skip to content

Commit

Permalink
[Maps] pass getFieldFormatter to DynamicTextProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Jan 3, 2020
1 parent b7c5350 commit 72166f9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
<EuiFlexGroup gutterSize="none" justifyContent="flexEnd">
<EuiFlexItem grow={false}>{props.staticDynamicSelect}</EuiFlexItem>
<EuiFlexItem>
<FieldSelect
fields={props.fields}
selectedFieldName={_.get(styleOptions, 'field.name')}
onChange={onFieldChange}
compressed
/>
</EuiFlexItem>
</EuiFlexGroup>
);
}
Original file line number Diff line number Diff line change
@@ -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 (
<EuiFlexGroup gutterSize="none" justifyContent="flexEnd">
<EuiFlexItem grow={false}>{props.staticDynamicSelect}</EuiFlexItem>
<EuiFlexItem>
<EuiFieldText
placeholder={i18n.translate('xpack.maps.styles.staticLabel.valuePlaceholder', {
defaultMessage: 'symbol label',
})}
value={props.styleProperty.getOptions().value}
onChange={onValueChange}
aria-label={i18n.translate('xpack.maps.styles.staticLabel.valueAriaLabel', {
defaultMessage: 'symbol label',
})}
compressed
/>
</EuiFlexItem>
</EuiFlexGroup>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ export function canSkipFormattersUpdate({ prevDataRequest, nextMeta }) {
return false;
}

return !_.isEqual(prevMeta.fieldNames, nextMeta.fieldNames);
return _.isEqual(prevMeta.fieldNames, nextMeta.fieldNames);
}

0 comments on commit 72166f9

Please sign in to comment.