Skip to content

Commit f9345c3

Browse files
committed
Use debounce when autoapply enabled
1 parent 9c895d1 commit f9345c3

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

  • src/legacy/ui/public/vis/editors/default/components/sidebar

src/legacy/ui/public/vis/editors/default/components/sidebar/controls.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
import React, { useCallback, useEffect, useState } from 'react';
20+
import React, { useCallback, useState } from 'react';
2121
import {
2222
EuiFlexGroup,
2323
EuiFlexItem,
@@ -28,6 +28,8 @@ import {
2828
} from '@elastic/eui';
2929
import { FormattedMessage } from '@kbn/i18n/react';
3030
import { i18n } from '@kbn/i18n';
31+
import { useDebounce } from 'react-use';
32+
3133
import { Vis } from 'ui/vis';
3234
import { discardChanges, EditorAction } from './state';
3335

@@ -53,11 +55,15 @@ function DefaultEditorControls({
5355
const toggleAutoApply = useCallback(e => setAutoApplyEnabled(e.target.checked), []);
5456
const onClickDiscard = useCallback(() => dispatch(discardChanges(vis)), [dispatch, vis]);
5557

56-
useEffect(() => {
57-
if (autoApplyEnabled && isDirty) {
58-
applyChanges();
59-
}
60-
}, [isDirty, autoApplyEnabled, applyChanges]);
58+
useDebounce(
59+
() => {
60+
if (autoApplyEnabled && isDirty) {
61+
applyChanges();
62+
}
63+
},
64+
300,
65+
[isDirty, autoApplyEnabled, applyChanges]
66+
);
6167

6268
return (
6369
<div className="visEditorSidebar__controls">

0 commit comments

Comments
 (0)