Skip to content

Commit 100f05a

Browse files
committed
fix: error handling
1 parent 107d06b commit 100f05a

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

src/components/QueryExecutionStatus/QueryExecutionStatus.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import type {LabelProps, TextProps} from '@gravity-ui/uikit';
66
import {Icon, Label, Spin, Text} from '@gravity-ui/uikit';
77

88
import {isQueryCancelledError} from '../../containers/Tenant/Query/utils/isQueryCancelledError';
9-
import {setQueryDuration} from '../../store/reducers/query/query';
9+
import {selectQueryDuration, setQueryDuration} from '../../store/reducers/query/query';
1010
import {cn} from '../../utils/cn';
1111
import {HOUR_IN_SECONDS, SECOND_IN_MS} from '../../utils/constants';
12-
import {useTypedDispatch} from '../../utils/hooks';
12+
import {useTypedDispatch, useTypedSelector} from '../../utils/hooks';
1313
import {isAxiosError} from '../../utils/response';
1414

1515
import './QueryExecutionStatus.scss';
@@ -20,20 +20,15 @@ interface QueryExecutionStatusProps {
2020
className?: string;
2121
error?: unknown;
2222
loading?: boolean;
23-
queryDuration?: number;
2423
}
2524

26-
export const QueryExecutionStatus = ({
27-
className,
28-
error,
29-
loading,
30-
queryDuration,
31-
}: QueryExecutionStatusProps) => {
25+
export const QueryExecutionStatus = ({className, error, loading}: QueryExecutionStatusProps) => {
3226
let icon: React.ReactNode;
3327
let label: string;
3428
let theme: LabelProps['theme'];
3529
let textColor: TextProps['color'];
3630
const dispatch = useTypedDispatch();
31+
const queryDuration = useTypedSelector(selectQueryDuration);
3732

3833
const isCancelled = isQueryCancelledError(error);
3934

@@ -42,7 +37,7 @@ export const QueryExecutionStatus = ({
4237
let startTime = Date.now();
4338

4439
if (loading) {
45-
setQueryDuration(0);
40+
dispatch(setQueryDuration(0));
4641
startTime = Date.now();
4742
timerId = setInterval(() => {
4843
dispatch(setQueryDuration(Date.now() - startTime));

src/containers/Tenant/Query/QueryResult/QueryResultViewer.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function QueryResultViewer({
108108
});
109109
const [useShowPlanToSvg] = useSetting<boolean>(USE_SHOW_PLAN_SVG_KEY);
110110

111-
const {error, isLoading, data = {}, queryDuration} = result;
111+
const {error, isLoading, data = {}} = result;
112112
const {preparedPlan, simplifiedPlan, stats, resultSets, ast} = data;
113113

114114
React.useEffect(() => {
@@ -217,8 +217,7 @@ export function QueryResultViewer({
217217
);
218218
};
219219

220-
const renderErrorView = () => {
221-
const isStopped = isQueryCancelledError(error);
220+
const renderCommonErrorView = (isStopped: boolean) => {
222221
return (
223222
<Flex justifyContent="center" alignItems="center" width="100%">
224223
<EmptyState
@@ -236,9 +235,11 @@ export function QueryResultViewer({
236235
};
237236

238237
const renderResultSection = () => {
238+
const isStopped = isQueryCancelledError(error);
239+
239240
if (activeSection === RESULT_OPTIONS_IDS.result) {
240-
if (error && !resultSets?.length) {
241-
return renderErrorView();
241+
if (error && isStopped) {
242+
return renderCommonErrorView(isStopped);
242243
}
243244

244245
return (
@@ -253,7 +254,7 @@ export function QueryResultViewer({
253254
}
254255

255256
if (error) {
256-
return renderErrorView();
257+
return renderCommonErrorView(isStopped);
257258
}
258259

259260
if (activeSection === RESULT_OPTIONS_IDS.schema) {
@@ -300,11 +301,7 @@ export function QueryResultViewer({
300301
onUpdate={onSelectSection}
301302
/>
302303
) : null}
303-
<QueryExecutionStatus
304-
error={error}
305-
loading={isLoading}
306-
queryDuration={queryDuration}
307-
/>
304+
<QueryExecutionStatus error={error} loading={isLoading} />
308305
{data?.traceId && isExecute ? <TraceButton traceId={data.traceId} /> : null}
309306
</div>
310307
);

src/containers/Tenant/Query/QueryResult/components/ResultSetsViewer/ResultSetsViewer.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,22 @@ export function ResultSetsViewer(props: ResultSetsViewerProps) {
6262
);
6363
};
6464

65+
const renderResults = () => {
66+
if (resultSets?.length) {
67+
if (resultSets?.length > 1) {
68+
return renderTabs();
69+
} else {
70+
return renderSingleResult();
71+
}
72+
}
73+
74+
return null;
75+
};
76+
6577
return (
6678
<div className={b('result-wrapper')}>
6779
{props.error ? <QueryResultError error={error} /> : null}
68-
{resultSets?.length && resultSets?.length > 1 ? renderTabs() : renderSingleResult()}
80+
{renderResults()}
6981
{currentResult ? (
7082
<div className={b('result')}>
7183
<QueryResultTable

src/store/reducers/query/query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ const slice = createSlice({
5454
state.result = action.payload;
5555
},
5656
setQueryDuration: (state, action: PayloadAction<number>) => {
57-
if (state.result) {
58-
state.result.queryDuration = action.payload;
59-
}
57+
state.queryDuration = action.payload;
6058
},
6159
saveQueryToHistory: (
6260
state,
@@ -136,6 +134,7 @@ const slice = createSlice({
136134
selectors: {
137135
selectQueriesHistoryFilter: (state) => state.history.filter || '',
138136
selectTenantPath: (state) => state.tenantPath,
137+
selectQueryDuration: (state) => state.queryDuration,
139138
selectResult: (state) => state.result,
140139
selectQueriesHistory: (state) => {
141140
const items = state.history.queries;
@@ -173,6 +172,7 @@ export const {
173172
selectTenantPath,
174173
selectResult,
175174
selectUserInput,
175+
selectQueryDuration,
176176
} = slice.selectors;
177177

178178
interface SendQueryParams extends QueryRequestParams {

src/store/reducers/query/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ export interface QueryResult {
5454
error?: unknown;
5555
queryId: string;
5656
isLoading: boolean;
57-
queryDuration?: number;
5857
}
5958

6059
export interface QueryState {
6160
input: string;
6261
result?: QueryResult;
62+
queryDuration?: number;
6363
history: {
6464
queries: QueryInHistory[];
6565
currentIndex: number;

0 commit comments

Comments
 (0)