Skip to content

Commit 5679ec3

Browse files
committed
fix
1 parent 3bfd8bc commit 5679ec3

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {isEqual} from 'lodash';
55
import {v4 as uuidv4} from 'uuid';
66

77
import SplitPane from '../../../../components/SplitPane';
8-
import {cancelQueryApi} from '../../../../store/reducers/cancelQuery';
98
import {
109
useStreamingAvailable,
1110
useTracingLevelOptionAvailable,
@@ -92,12 +91,11 @@ export default function QueryEditor(props: QueryEditorProps) {
9291
LAST_USED_QUERY_ACTION_KEY,
9392
);
9493
const [lastExecutedQueryText, setLastExecutedQueryText] = React.useState<string>('');
95-
const [isQueryStreamingEnabled] = useSetting(ENABLE_QUERY_STREAMING);
94+
const [isQueryStreamingEnabled] = useSetting<boolean>(ENABLE_QUERY_STREAMING);
9695
const isStreamingEnabled = useStreamingAvailable() && isQueryStreamingEnabled;
9796

9897
const [sendQuery] = queryApi.useUseSendQueryMutation();
9998
const [streamQuery] = queryApi.useUseStreamQueryMutation();
100-
const [sendCancelQuery, cancelQueryResponse] = cancelQueryApi.useCancelQueryMutation();
10199

102100
const runningQueryRef = React.useRef<{abort: VoidFunction} | null>(null);
103101

@@ -202,14 +200,6 @@ export default function QueryEditor(props: QueryEditorProps) {
202200
dispatchResultVisibilityState(PaneVisibilityActionTypes.triggerExpand);
203201
});
204202

205-
const handleCancelRunningQuery = React.useCallback(() => {
206-
if (isStreamingEnabled && runningQueryRef.current) {
207-
runningQueryRef.current.abort();
208-
} else if (result?.queryId) {
209-
sendCancelQuery({queryId: result?.queryId, database: tenantName});
210-
}
211-
}, [isStreamingEnabled, result?.queryId, sendCancelQuery, tenantName]);
212-
213203
const onCollapseResultHandler = () => {
214204
dispatchResultVisibilityState(PaneVisibilityActionTypes.triggerCollapse);
215205
};
@@ -231,6 +221,8 @@ export default function QueryEditor(props: QueryEditorProps) {
231221
highlightedAction={lastUsedQueryAction}
232222
tenantName={tenantName}
233223
queryId={result?.queryId}
224+
isStreamingEnabled={isStreamingEnabled}
225+
runningQueryRef={runningQueryRef}
234226
/>
235227
);
236228
};
@@ -272,12 +264,10 @@ export default function QueryEditor(props: QueryEditorProps) {
272264
theme={theme}
273265
key={result?.queryId}
274266
result={result}
275-
cancelQueryResponse={cancelQueryResponse}
276267
tenantName={tenantName}
277268
path={path}
278269
showPreview={showPreview}
279270
queryText={lastExecutedQueryText}
280-
onCancelRunningQuery={handleCancelRunningQuery}
281271
tableSettings={tableSettings}
282272
/>
283273
</div>
@@ -294,17 +284,14 @@ interface ResultProps {
294284
type?: EPathType;
295285
theme: string;
296286
result?: QueryResult;
297-
cancelQueryResponse?: Pick<QueryResult, 'isLoading' | 'error'>;
298287
tenantName: string;
299288
path: string;
300289
showPreview?: boolean;
301290
queryText: string;
302291
tableSettings?: Partial<Settings>;
303-
onCancelRunningQuery: VoidFunction;
304292
}
305293
function Result({
306294
resultVisibilityState,
307-
cancelQueryResponse,
308295
onExpandResultHandler,
309296
onCollapseResultHandler,
310297
type,
@@ -315,7 +302,6 @@ function Result({
315302
showPreview,
316303
queryText,
317304
tableSettings,
318-
onCancelRunningQuery,
319305
}: ResultProps) {
320306
if (showPreview) {
321307
return <Preview database={tenantName} path={path} type={type} />;
@@ -329,13 +315,10 @@ function Result({
329315
theme={theme}
330316
tenantName={tenantName}
331317
isResultsCollapsed={resultVisibilityState.collapsed}
332-
isCancelError={Boolean(cancelQueryResponse?.error)}
333-
isCancelling={Boolean(cancelQueryResponse?.isLoading)}
334318
tableSettings={tableSettings}
335319
onExpandResults={onExpandResultHandler}
336320
onCollapseResults={onCollapseResultHandler}
337321
queryText={queryText}
338-
onCancelRunningQuery={onCancelRunningQuery}
339322
/>
340323
);
341324
}

src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ interface QueryEditorControlsProps {
2222
highlightedAction: QueryAction;
2323
queryId?: string;
2424
tenantName: string;
25+
isStreamingEnabled?: boolean;
26+
runningQueryRef: React.MutableRefObject<{abort: VoidFunction} | null>;
2527

2628
handleGetExplainQueryClick: (text: string) => void;
2729
handleSendExecuteClick: (text: string) => void;
@@ -37,6 +39,8 @@ export const QueryEditorControls = ({
3739
highlightedAction,
3840
queryId,
3941
tenantName,
42+
isStreamingEnabled,
43+
runningQueryRef,
4044

4145
handleSendExecuteClick,
4246
onSettingsButtonClick,
@@ -67,7 +71,11 @@ export const QueryEditorControls = ({
6771
const onStopButtonClick = React.useCallback(async () => {
6872
if (queryId) {
6973
try {
70-
await sendCancelQuery({queryId, database: tenantName}).unwrap();
74+
if (isStreamingEnabled && runningQueryRef.current) {
75+
runningQueryRef.current.abort();
76+
} else if (queryId) {
77+
sendCancelQuery({queryId, database: tenantName}).unwrap();
78+
}
7179
} catch {
7280
createToast({
7381
name: 'stop-error',
@@ -78,7 +86,8 @@ export const QueryEditorControls = ({
7886
});
7987
}
8088
}
81-
}, [queryId, sendCancelQuery, tenantName]);
89+
}, [isStreamingEnabled, queryId, runningQueryRef, sendCancelQuery, tenantName]);
90+
8291
const isRunHighlighted = highlightedAction === 'execute';
8392
const isExplainHighlighted = highlightedAction === 'explain';
8493

0 commit comments

Comments
 (0)