[Lens] Label placeholder always defaults to the lens proposed text (#124222)

* [Lens] Label placeholder always defaults to the lens proposed text

* Fix bug
This commit is contained in:
Stratoula Kalafateli 2022-02-02 13:36:01 +02:00 committed by GitHub
parent fd0e1aed0e
commit a5ee534bad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View file

@ -638,7 +638,6 @@ export function DimensionEditor(props: DimensionEditorProps) {
() =>
String(
selectedColumn &&
!selectedColumn.customLabel &&
operationDefinitionMap[selectedColumn.operationType].getDefaultLabel(
selectedColumn,
state.indexPatterns[state.layers[layerId].indexPatternId],
@ -767,6 +766,7 @@ export function DimensionEditor(props: DimensionEditorProps) {
// re-render the input from scratch to obtain new "initial value" if the underlying default label changes
key={defaultLabel}
value={selectedColumn.label}
defaultValue={defaultLabel}
onChange={(value) => {
updateLayer({
columns: {

View file

@ -33,11 +33,17 @@ export function isQuickFunction(operationType: string) {
export const LabelInput = ({
value,
onChange,
defaultValue,
}: {
value: string;
onChange: (value: string) => void;
defaultValue?: string;
}) => {
const { inputValue, handleInputChange, initialValue } = useDebouncedValue({ onChange, value });
const { inputValue, handleInputChange, initialValue } = useDebouncedValue({
onChange,
value,
defaultValue,
});
return (
<EuiFormRow

View file

@ -21,9 +21,11 @@ export const useDebouncedValue = <T>(
{
onChange,
value,
defaultValue,
}: {
onChange: (val: T) => void;
value: T;
defaultValue?: T;
},
{ allowFalsyValue }: { allowFalsyValue?: boolean } = {}
) => {
@ -32,7 +34,7 @@ export const useDebouncedValue = <T>(
const shouldUpdateWithFalsyValue = Boolean(allowFalsyValue);
// Save the initial value
const initialValue = useRef(value);
const initialValue = useRef(defaultValue ?? value);
const flushChangesTimeout = useRef<NodeJS.Timeout | undefined>();