Skip to content

Commit 33c068b

Browse files
committed
fix: review
1 parent f303d38 commit 33c068b

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
import {useChangedQuerySettings} from '../../../../utils/hooks/useChangedQuerySettings';
4343
import {useLastQueryExecutionSettings} from '../../../../utils/hooks/useLastQueryExecutionSettings';
4444
import {YQL_LANGUAGE_ID} from '../../../../utils/monaco/constats';
45-
import {updateErrorsHighlighting} from '../../../../utils/monaco/highlightErrors';
45+
import {useUpdateErrorsHighlighting} from '../../../../utils/monaco/highlightErrors';
4646
import {QUERY_ACTIONS} from '../../../../utils/query';
4747
import type {InitialPaneState} from '../../utils/paneVisibilityToggleHelpers';
4848
import {
@@ -90,6 +90,8 @@ export default function QueryEditor(props: QueryEditorProps) {
9090
const input = useTypedSelector(selectUserInput);
9191
const showPreview = useTypedSelector(selectShowPreview);
9292

93+
const updateErrorsHighlighting = useUpdateErrorsHighlighting();
94+
9395
const isResultLoaded = Boolean(result);
9496

9597
const [querySettings] = useQueryExecutionSettings();

src/utils/monaco/highlightErrors.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1+
import React from 'react';
2+
13
import {parseYqlQueryWithoutCursor} from '@gravity-ui/websql-autocomplete/yql';
24
import {MarkerSeverity, editor} from 'monaco-editor';
35

46
import i18n from './i18n';
57

68
const owner = 'ydb';
79

8-
let errorsHighlightingTimeoutId: ReturnType<typeof setTimeout>;
10+
export function useUpdateErrorsHighlighting() {
11+
const errorsHighlightingTimerRef = React.useRef<number>();
12+
13+
React.useEffect(() => {
14+
return () => {
15+
if (errorsHighlightingTimerRef.current) {
16+
clearTimeout(errorsHighlightingTimerRef.current);
17+
}
18+
};
19+
}, []);
20+
21+
const updateErrorsHighlighting = React.useCallback(() => {
22+
unHighlightErrors();
923

10-
export function updateErrorsHighlighting() {
11-
unHighlightErrors();
24+
if (errorsHighlightingTimerRef.current) {
25+
clearTimeout(errorsHighlightingTimerRef.current);
26+
}
27+
errorsHighlightingTimerRef.current = window.setTimeout(() => highlightErrors(), 500);
28+
}, []);
1229

13-
clearTimeout(errorsHighlightingTimeoutId);
14-
errorsHighlightingTimeoutId = setTimeout(() => highlightErrors(), 500);
30+
return updateErrorsHighlighting;
1531
}
1632

1733
function highlightErrors() {

0 commit comments

Comments
 (0)