Skip to content

Commit 7dc8be1

Browse files
committed
fix: review
1 parent 525357c commit 7dc8be1

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
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/hooks/useCancellable.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
3+
export function useCancellableFunction<T extends {cancel: () => void}>(cancellable: T) {
4+
React.useEffect(() => {
5+
return () => {
6+
cancellable.cancel();
7+
};
8+
}, [cancellable]);
9+
return cancellable;
10+
}

src/utils/monaco/highlightErrors.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1+
import React from 'react';
2+
13
import {parseYqlQueryWithoutCursor} from '@gravity-ui/websql-autocomplete/yql';
24
import {debounce} from 'lodash';
35
import {MarkerSeverity, editor} from 'monaco-editor';
46

7+
import {useCancellableFunction} from '../hooks/useCancellable';
8+
59
import i18n from './i18n';
610

711
const owner = 'ydb';
812

913
const debouncedHighlightErrors = debounce(highlightErrors, 500);
1014

11-
export function updateErrorsHighlighting() {
12-
unHighlightErrors();
15+
export function useUpdateErrorsHighlighting() {
16+
const highlightErrors = useCancellableFunction(debouncedHighlightErrors);
17+
const updateErrorsHighlighting = React.useCallback(() => {
18+
unHighlightErrors();
1319

14-
debouncedHighlightErrors();
20+
highlightErrors();
21+
}, [highlightErrors]);
22+
return updateErrorsHighlighting;
1523
}
1624

1725
function highlightErrors() {

0 commit comments

Comments
 (0)