Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ import { OperationMetadata } from '../../types';

jest.mock('../loader');
jest.mock('../state_helpers');
jest.mock('lodash', () => {
const original = jest.requireActual('lodash');

return {
...original,
debounce: (fn: unknown) => fn,
};
});

const expectedIndexPatterns = {
1: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import './popover_editor.scss';
import _ from 'lodash';
import React, { useState, useMemo } from 'react';
import React, { useState, useMemo, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import {
EuiFlexItem,
Expand Down Expand Up @@ -56,6 +56,31 @@ function asOperationOptions(operationTypes: OperationType[], compatibleWithCurre
}));
}

const LabelInput = ({ value, onChange }: { value: string; onChange: (value: string) => void }) => {
const [inputValue, setInputValue] = useState(value);

useEffect(() => {
setInputValue(value);
}, [value, setInputValue]);

const onChangeDebounced = useMemo(() => _.debounce(onChange, 256), [onChange]);

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const val = String(e.target.value);
setInputValue(val);
onChangeDebounced(val);
};

return (
<EuiFieldText
compressed
data-test-subj="indexPattern-label-edit"
value={inputValue}
onChange={handleInputChange}
/>
);
};

export function PopoverEditor(props: PopoverEditorProps) {
const {
selectedColumn,
Expand Down Expand Up @@ -320,11 +345,9 @@ export function PopoverEditor(props: PopoverEditorProps) {
})}
display="rowCompressed"
>
<EuiFieldText
compressed
data-test-subj="indexPattern-label-edit"
<LabelInput
value={selectedColumn.label}
onChange={(e) => {
onChange={(value) => {
setState({
...state,
layers: {
Expand All @@ -335,7 +358,7 @@ export function PopoverEditor(props: PopoverEditorProps) {
...state.layers[layerId].columns,
[columnId]: {
...selectedColumn,
label: e.target.value,
label: value,
customLabel: true,
},
},
Expand Down