From 4bcb2ba1a40fca3f516723ba0d6c75ef1635ce15 Mon Sep 17 00:00:00 2001 From: Marta Bondyra Date: Mon, 14 Sep 2020 13:48:20 +0200 Subject: [PATCH] [Lens] fix performance on pie settings slider (#77181) (#77305) --- .../lens/public/pie_visualization/toolbar.tsx | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx index 9c3d0d0f34814..501a2de24d9ad 100644 --- a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx +++ b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx @@ -6,6 +6,7 @@ import './toolbar.scss'; import React, { useState } from 'react'; +import { useDebounce } from 'react-use'; import { i18n } from '@kbn/i18n'; import { EuiFlexGroup, @@ -192,19 +193,14 @@ export function PieToolbar(props: VisualizationToolbarProps - { + setValue={(value) => setState({ ...state, - layers: [{ ...layer, percentDecimals: Number(e.currentTarget.value) }], - }); - }} + layers: [{ ...layer, percentDecimals: value }], + }) + } /> @@ -279,3 +275,28 @@ export function PieToolbar(props: VisualizationToolbarProps ); } + +const DecimalPlaceSlider = ({ + value, + setValue, +}: { + value: number; + setValue: (value: number) => void; +}) => { + const [localValue, setLocalValue] = useState(value); + useDebounce(() => setValue(localValue), 256, [localValue]); + + return ( + { + setLocalValue(Number(e.currentTarget.value)); + }} + /> + ); +};