Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Feb 9, 2020
1 parent c1096bf commit c03cb7c
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ export class ColorMapSelect extends Component {
<EuiSpacer size="s" />
<ColorStopsCategorical
colorStops={this.state.customColorMap}
field={this.props.styleProperty.getField()}
getValueSuggestions={this.props.styleProperty.getValueSuggestions}
onChange={this._onCustomColorMapChange}
getValueSuggestions={this.props.getValueSuggestions}
/>
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const ColorStopsCategorical = ({
{ stop: null, color: DEFAULT_CUSTOM_COLOR }, //first stop is the "other" color
{ stop: '', color: DEFAULT_NEXT_COLOR },
],
field,
onChange,
getValueSuggestions,
}) => {
Expand Down Expand Up @@ -57,6 +58,7 @@ export const ColorStopsCategorical = ({

return (
<StopInput
field={field}
getValueSuggestions={getValueSuggestions}
value={stopValue}
onChange={onStopChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function DynamicColorForm({
color={styleOptions.color}
customColorMap={styleOptions.customColorRamp}
useCustomColorMap={_.get(styleOptions, 'useCustomColorRamp', false)}
getValueSuggestions={styleProperty.getValueSuggestions}
styleProperty={styleProperty}
/>
);
}
Expand All @@ -83,7 +83,7 @@ export function DynamicColorForm({
color={styleOptions.colorCategory}
customColorMap={styleOptions.customColorPalette}
useCustomColorMap={_.get(styleOptions, 'useCustomColorPalette', false)}
getValueSuggestions={styleProperty.getValueSuggestions}
styleProperty={styleProperty}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,47 @@
import _ from 'lodash';
import React, { Component } from 'react';

import { EuiComboBox } from '@elastic/eui';
import { EuiComboBox, EuiFieldText } from '@elastic/eui';

export class StopInput extends Component {
state = {
suggestions: [],
isLoadingSuggestions: false,
hasPrevFocus: false,
};
constructor(props) {
super(props);
this.state = {
suggestions: [],
isLoadingSuggestions: false,
hasPrevFocus: false,
fieldDataType: undefined,
localFieldTextValue: props.value,
};
}

componentDidMount() {
this._isMounted = true;
this._prevFieldName = undefined;
this._loadFieldDataType();
}

componentDidUpdate() {
this._loadFieldDataType();
}

componentWillUnmount() {
this._isMounted = false;
this._loadSuggestions.cancel();
}

async _loadFieldDataType() {
if (this.props.field.getName() === this._prevFieldName) {
return;
}

this._prevFieldName = this.props.field.getName();
const fieldDataType = await this.props.field.getDataType();
if (this._isMounted) {
this.setState({ fieldDataType });
}
}

_onFocus = () => {
if (!this.state.hasPrevFocus) {
this.setState({ hasPrevFocus: true });
Expand Down Expand Up @@ -68,7 +91,17 @@ export class StopInput extends Component {
}
}, 300);

render() {
_onFieldTextChange = event => {
this.setState({ localFieldTextValue: event.target.value });
// onChange can cause UI lag, ensure smooth input typing by debouncing onChange
this._debouncedOnFieldTextChange();
};

_debouncedOnFieldTextChange = _.debounce(() => {
this.props.onChange(this.state.localFieldTextValue);
}, 500);

_renderSuggestionInput() {
const suggestionOptions = this.state.suggestions.map(suggestion => {
return { label: `${suggestion}` };
});
Expand Down Expand Up @@ -100,4 +133,26 @@ export class StopInput extends Component {
/>
);
}

_renderTextInput() {
return (
<EuiFieldText
value={this.state.localFieldTextValue}
onChange={this._onFieldTextChange}
compressed
/>
);
}

render() {
if (!this.state.fieldDataType) {
return null;
}

// autocomplete service can not provide suggestions for non string fields (and boolean) because it uses
// term aggregation include parameter. Include paramerter uses a regular expressions that only supports string type
return this.state.fieldDataType === 'string' || this.state.fieldDataType === 'boolean'
? this._renderSuggestionInput()
: this._renderTextInput();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function DynamicIconForm({
return (
<IconMapSelect
{...styleOptions}
getValueSuggestions={styleProperty.getValueSuggestions}
styleProperty={styleProperty}
onChange={onIconMapChange}
isDarkMode={isDarkMode}
symbolOptions={symbolOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { IconStops } from './icon_stops';

export function IconMapSelect({
customIconStops,
getValueSuggestions,
iconPaletteId,
isDarkMode,
onChange,
styleProperty,
symbolOptions,
useCustomIconMap,
}) {
Expand All @@ -31,7 +31,8 @@ export function IconMapSelect({
function renderCustomIconStopsInput(onCustomMapChange) {
return (
<IconStops
getValueSuggestions={getValueSuggestions}
field={styleProperty.getField()}
getValueSuggestions={styleProperty.getValueSuggestions}
iconStops={customIconStops}
isDarkMode={isDarkMode}
onChange={onCustomMapChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const DEFAULT_ICON_STOPS = [
];

export function IconStops({
field,
getValueSuggestions,
iconStops = DEFAULT_ICON_STOPS,
isDarkMode,
Expand Down Expand Up @@ -98,7 +99,12 @@ export function IconStops({
compressed
/>
) : (
<StopInput getValueSuggestions={getValueSuggestions} value={stop} onChange={onStopChange} />
<StopInput
field={field}
getValueSuggestions={getValueSuggestions}
value={stop}
onChange={onStopChange}
/>
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ import { OrdinalFieldMetaOptionsPopover } from '../components/ordinal_field_meta
export class DynamicStyleProperty extends AbstractStyleProperty {
static type = STYLE_TYPE.DYNAMIC;

constructor(options, styleName, field, getFieldMeta, getFieldFormatter, getValueSuggestions) {
constructor(options, styleName, field, getFieldMeta, getFieldFormatter, source) {
super(options, styleName);
this._field = field;
this._getFieldMeta = getFieldMeta;
this._getFieldFormatter = getFieldFormatter;
this._getValueSuggestions = getValueSuggestions;
this._source = source;
}

getValueSuggestions = query => {
const fieldName = this.getFieldName();
return this._getValueSuggestions && fieldName
? this._getValueSuggestions(fieldName, query)
: [];
return this._source && fieldName ? this._source.getValueSuggestions(fieldName, query) : [];
};

getFieldMeta() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ export class VectorStyle extends AbstractStyle {
field,
this._getFieldMeta,
this._getFieldFormatter,
this._source.getValueSuggestions,
this._source,
isSymbolizedAsIcon
);
} else {
Expand All @@ -633,7 +633,7 @@ export class VectorStyle extends AbstractStyle {
field,
this._getFieldMeta,
this._getFieldFormatter,
this._source.getValueSuggestions
this._source
);
} else {
throw new Error(`${descriptor} not implemented`);
Expand Down Expand Up @@ -666,7 +666,7 @@ export class VectorStyle extends AbstractStyle {
field,
this._getFieldMeta,
this._getFieldFormatter,
this._source.getValueSuggestions
this._source
);
} else {
throw new Error(`${descriptor} not implemented`);
Expand All @@ -686,7 +686,7 @@ export class VectorStyle extends AbstractStyle {
field,
this._getFieldMeta,
this._getFieldFormatter,
this._source.getValueSuggestions
this._source
);
} else {
throw new Error(`${descriptor} not implemented`);
Expand Down

0 comments on commit c03cb7c

Please sign in to comment.