Skip to content

Commit 04b4313

Browse files
authored
fix: unnecessary background refresh on query page (#1256)
1 parent 4bf43af commit 04b4313

File tree

21 files changed

+239
-241
lines changed

21 files changed

+239
-241
lines changed

package-lock.json

-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"path-to-regexp": "^3.0.0",
3939
"qs": "^6.12.0",
4040
"react-error-boundary": "^4.0.13",
41-
"react-freeze": "^1.0.4",
4241
"react-helmet-async": "^2.0.5",
4342
"react-hook-form": "^7.52.1",
4443
"react-json-inspector": "^7.1.1",

src/components/NotRenderUntilFirstVisible/NotRenderUntilFirstVisible.scss

-3
This file was deleted.

src/components/NotRenderUntilFirstVisible/NotRenderUntilFirstVisible.tsx

-23
This file was deleted.

src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import React from 'react';
2-
31
import {useThemeValue} from '@gravity-ui/uikit';
42

5-
import NotRenderUntilFirstVisible from '../../../components/NotRenderUntilFirstVisible/NotRenderUntilFirstVisible';
63
import {TENANT_PAGES_IDS} from '../../../store/reducers/tenant/constants';
74
import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../../types/additionalProps';
85
import type {EPathType} from '../../../types/api/schema';
@@ -31,23 +28,22 @@ function ObjectGeneral(props: ObjectGeneralProps) {
3128

3229
const renderPageContent = () => {
3330
const {type, additionalTenantProps, additionalNodesProps, tenantName, path} = props;
34-
35-
return (
36-
<React.Fragment>
37-
<NotRenderUntilFirstVisible show={tenantPage === TENANT_PAGES_IDS.query}>
38-
<Query tenantName={tenantName} path={path} theme={theme} type={type} />
39-
</NotRenderUntilFirstVisible>
40-
<NotRenderUntilFirstVisible show={tenantPage === TENANT_PAGES_IDS.diagnostics}>
31+
switch (tenantPage) {
32+
case TENANT_PAGES_IDS.query: {
33+
return <Query tenantName={tenantName} path={path} theme={theme} type={type} />;
34+
}
35+
default: {
36+
return (
4137
<Diagnostics
4238
type={type}
4339
tenantName={tenantName}
4440
path={path}
4541
additionalTenantProps={additionalTenantProps}
4642
additionalNodesProps={additionalNodesProps}
4743
/>
48-
</NotRenderUntilFirstVisible>
49-
</React.Fragment>
50-
);
44+
);
45+
}
46+
}
5147
};
5248

5349
return (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@import '../../../../styles/mixins.scss';
2+
3+
.cancel-query-button {
4+
&__stop-button {
5+
&_error {
6+
@include query-buttons-animations();
7+
}
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
3+
import {StopFill} from '@gravity-ui/icons';
4+
import {Button, Icon} from '@gravity-ui/uikit';
5+
6+
import {cancelQueryApi} from '../../../../store/reducers/cancelQuery';
7+
import {cn} from '../../../../utils/cn';
8+
import i18n from '../i18n';
9+
10+
import './CancelQueryButton.scss';
11+
12+
const b = cn('cancel-query-button');
13+
14+
interface CancelQueryButtonProps {
15+
queryId: string;
16+
tenantName: string;
17+
}
18+
19+
export function CancelQueryButton({queryId, tenantName}: CancelQueryButtonProps) {
20+
const [sendCancelQuery, cancelQueryResponse] = cancelQueryApi.useCancelQueryMutation();
21+
22+
const onStopButtonClick = React.useCallback(() => {
23+
sendCancelQuery({queryId, database: tenantName});
24+
}, [queryId, sendCancelQuery, tenantName]);
25+
26+
return (
27+
<Button
28+
loading={cancelQueryResponse.isLoading}
29+
onClick={onStopButtonClick}
30+
className={b('stop-button', {error: Boolean(cancelQueryResponse.error)})}
31+
>
32+
<Icon data={StopFill} size={16} />
33+
{i18n('action.stop')}
34+
</Button>
35+
);
36+
}

src/containers/Tenant/Query/ExecuteResult/ExecuteResult.scss

-6
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,4 @@
7878
&__elapsed-label {
7979
margin-left: var(--g-spacing-3);
8080
}
81-
82-
&__stop-button {
83-
&_error {
84-
@include query-buttons-animations();
85-
}
86-
}
8781
}

src/containers/Tenant/Query/ExecuteResult/ExecuteResult.tsx

+19-32
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
22

3-
import {StopFill} from '@gravity-ui/icons';
43
import type {ControlGroupOption} from '@gravity-ui/uikit';
5-
import {Button, Icon, RadioButton, Tabs} from '@gravity-ui/uikit';
4+
import {RadioButton, Tabs} from '@gravity-ui/uikit';
65
import JSONTree from 'react-json-inspector';
76

87
import {ClipboardButton} from '../../../../components/ClipboardButton';
@@ -17,13 +16,14 @@ import {QueryResultTable} from '../../../../components/QueryResultTable/QueryRes
1716
import {disableFullscreen} from '../../../../store/reducers/fullscreen';
1817
import type {ColumnType, KeyValueRow, TKqpStatsQuery} from '../../../../types/api/query';
1918
import type {ValueOf} from '../../../../types/common';
20-
import type {IQueryResult} from '../../../../types/store/query';
19+
import type {ExecuteQueryResult} from '../../../../types/store/executeQuery';
2120
import {getArray} from '../../../../utils';
2221
import {cn} from '../../../../utils/cn';
2322
import {getStringifiedData} from '../../../../utils/dataFormatters/dataFormatters';
2423
import {useTypedDispatch} from '../../../../utils/hooks';
2524
import {parseQueryError} from '../../../../utils/query';
2625
import {PaneVisibilityToggleButtons} from '../../utils/paneVisibilityToggleHelpers';
26+
import {CancelQueryButton} from '../CancelQueryButton/CancelQueryButton';
2727
import {SimplifiedPlan} from '../ExplainResult/components/SimplifiedPlan/SimplifiedPlan';
2828
import {ResultIssues} from '../Issues/Issues';
2929
import {QueryDuration} from '../QueryDuration/QueryDuration';
@@ -49,34 +49,28 @@ const resultOptionsIds = {
4949
type SectionID = ValueOf<typeof resultOptionsIds>;
5050

5151
interface ExecuteResultProps {
52-
data: IQueryResult | undefined;
53-
error: unknown;
54-
cancelError: unknown;
52+
result: ExecuteQueryResult;
5553
isResultsCollapsed?: boolean;
54+
theme?: string;
55+
tenantName: string;
5656
onCollapseResults: VoidFunction;
5757
onExpandResults: VoidFunction;
58-
onStopButtonClick: VoidFunction;
59-
theme?: string;
60-
loading?: boolean;
61-
cancelQueryLoading?: boolean;
6258
}
6359

6460
export function ExecuteResult({
65-
data,
66-
error,
67-
cancelError,
61+
result,
6862
isResultsCollapsed,
63+
theme,
64+
tenantName,
6965
onCollapseResults,
7066
onExpandResults,
71-
onStopButtonClick,
72-
theme,
73-
loading,
74-
cancelQueryLoading,
7567
}: ExecuteResultProps) {
7668
const [selectedResultSet, setSelectedResultSet] = React.useState(0);
7769
const [activeSection, setActiveSection] = React.useState<SectionID>(resultOptionsIds.result);
7870
const dispatch = useTypedDispatch();
7971

72+
const {error, isLoading, queryId, data} = result;
73+
8074
const stats: TKqpStatsQuery | undefined = data?.stats;
8175
const resultsSetsCount = data?.resultSets?.length;
8276
const isMulti = resultsSetsCount && resultsSetsCount > 0;
@@ -111,10 +105,10 @@ export function ExecuteResult({
111105
};
112106

113107
const renderResultTable = (
114-
result: KeyValueRow[] | undefined,
108+
resultSet: KeyValueRow[] | undefined,
115109
columns: ColumnType[] | undefined,
116110
) => {
117-
return <QueryResultTable data={result} columns={columns} settings={{sortable: false}} />;
111+
return <QueryResultTable data={resultSet} columns={columns} settings={{sortable: false}} />;
118112
};
119113

120114
const renderResult = () => {
@@ -243,8 +237,8 @@ export function ExecuteResult({
243237
<React.Fragment>
244238
<div className={b('controls')}>
245239
<div className={b('controls-right')}>
246-
<QueryExecutionStatus error={error} loading={loading} />
247-
{!error && !loading && (
240+
<QueryExecutionStatus error={error} loading={isLoading} />
241+
{!error && !isLoading && (
248242
<React.Fragment>
249243
{stats?.DurationUs !== undefined && (
250244
<QueryDuration duration={Number(stats.DurationUs)} />
@@ -261,17 +255,10 @@ export function ExecuteResult({
261255
)}
262256
</React.Fragment>
263257
)}
264-
{loading ? (
258+
{isLoading ? (
265259
<React.Fragment>
266260
<ElapsedTime className={b('elapsed-time')} />
267-
<Button
268-
loading={cancelQueryLoading}
269-
onClick={onStopButtonClick}
270-
className={b('stop-button', {error: Boolean(cancelError)})}
271-
>
272-
<Icon data={StopFill} size={16} />
273-
{i18n('action.stop')}
274-
</Button>
261+
<CancelQueryButton queryId={queryId} tenantName={tenantName} />
275262
</React.Fragment>
276263
) : null}
277264
{data?.traceId ? <TraceButton traceId={data.traceId} /> : null}
@@ -287,8 +274,8 @@ export function ExecuteResult({
287274
/>
288275
</div>
289276
</div>
290-
{loading || isQueryCancelledError(error) ? null : <QuerySettingsBanner />}
291-
<LoaderWrapper loading={loading}>
277+
{isLoading || isQueryCancelledError(error) ? null : <QuerySettingsBanner />}
278+
<LoaderWrapper loading={isLoading}>
292279
<Fullscreen>{renderResultSection()}</Fullscreen>
293280
</LoaderWrapper>
294281
</React.Fragment>

src/containers/Tenant/Query/ExecuteResult/i18n/en.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"action.result": "Result",
44
"action.stats": "Stats",
55
"action.schema": "Schema",
6-
"action.stop": "Stop",
76
"action.explain-plan": "Explain Plan",
87
"action.copy": "Copy {{activeSection}}",
98
"trace": "Trace"

src/containers/Tenant/Query/ExplainResult/ExplainResult.scss

-6
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,4 @@
4343
&__elapsed-label {
4444
margin-left: var(--g-spacing-3);
4545
}
46-
47-
&__stop-button {
48-
&_error {
49-
@include query-buttons-animations();
50-
}
51-
}
5246
}

0 commit comments

Comments
 (0)