Skip to content

Commit 3411cad

Browse files
committed
fix: review fixes
1 parent 98f4ff2 commit 3411cad

File tree

6 files changed

+33
-61
lines changed

6 files changed

+33
-61
lines changed

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import React from 'react';
33
import {ArrowUpRightFromSquare} from '@gravity-ui/icons';
44
import {Button, Tooltip} from '@gravity-ui/uikit';
55

6+
import {planToSvgApi} from '../../../../store/reducers/planToSvg';
67
import type {QueryPlan, ScriptPlan} from '../../../../types/api/query';
78

8-
import {usePlanToSvg} from './hooks';
99
import i18n from './i18n';
1010

1111
function getButtonView(error: string | null, isLoading: boolean) {
@@ -21,17 +21,36 @@ interface PlanToSvgButtonProps {
2121
}
2222

2323
export function PlanToSvgButton({plan, database}: PlanToSvgButtonProps) {
24-
const {error, blobUrl, isLoading, isUninitialized} = usePlanToSvg(database, plan);
24+
const [error, setError] = React.useState<string | null>(null);
25+
const [blobUrl, setBlobUrl] = React.useState<string | null>(null);
26+
const [getPlanToSvg, {isLoading}] = planToSvgApi.usePlanToSvgQueryMutation();
2527

2628
const handleClick = React.useCallback(() => {
27-
if (blobUrl) {
28-
window.open(blobUrl, '_blank');
29-
}
30-
}, [blobUrl]);
29+
getPlanToSvg({plan, database})
30+
.unwrap()
31+
.then((result) => {
32+
if (blobUrl) {
33+
URL.revokeObjectURL(blobUrl);
34+
}
3135

32-
if (isUninitialized) {
33-
return null;
34-
}
36+
const blob = new Blob([result], {type: 'image/svg+xml'});
37+
const url = URL.createObjectURL(blob);
38+
setBlobUrl(url);
39+
setError(null);
40+
window.open(url, '_blank');
41+
})
42+
.catch((err) => {
43+
setError(JSON.stringify(err));
44+
});
45+
}, [blobUrl, database, getPlanToSvg, plan]);
46+
47+
React.useEffect(() => {
48+
return () => {
49+
if (blobUrl) {
50+
URL.revokeObjectURL(blobUrl);
51+
}
52+
};
53+
}, [blobUrl]);
3554

3655
return (
3756
<Tooltip
@@ -41,7 +60,7 @@ export function PlanToSvgButton({plan, database}: PlanToSvgButtonProps) {
4160
view={getButtonView(error, isLoading)}
4261
loading={isLoading}
4362
onClick={handleClick}
44-
disabled={isLoading || !blobUrl}
63+
disabled={isLoading}
4564
>
4665
{i18n('text_plan-svg')}
4766
<Button.Icon>

src/containers/Tenant/Query/ExecuteResult/hooks.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"trace": "Trace",
99
"title.truncated": "Truncated",
1010
"title.result": "Result",
11-
"text_plan-svg": "Plan SVG",
11+
"text_plan-svg": "Execution plan",
1212
"text_open-plan-svg": "Open execution plan in new window",
1313
"text_error-plan-svg": "Error: {{error}}"
1414
}

src/containers/UserSettings/i18n/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"settings.usePaginatedTables.title": "Use paginated tables",
3434
"settings.usePaginatedTables.description": " Use table with data load on scroll for Nodes and Storage tabs. It will increase performance, but could work unstable",
3535

36-
"settings.useShowPlanToSvg.title": "Use show plan to svg",
36+
"settings.useShowPlanToSvg.title": "Plan to svg",
3737
"settings.useShowPlanToSvg.description": " Show \"Plan to svg\" button in query result widow (if query was executed with full stats option).",
3838

3939
"settings.showDomainDatabase.title": "Show domain database",

src/services/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {AxiosRequestConfig} from 'axios';
44
import axiosRetry from 'axios-retry';
55

66
import {backend as BACKEND, metaBackend as META_BACKEND} from '../store';
7-
import type {PlanToSvgQueryParams} from '../store/reducers/planToSvgQuery';
7+
import type {PlanToSvgQueryParams} from '../store/reducers/planToSvg';
88
import type {TMetaInfo} from '../types/api/acl';
99
import type {TQueryAutocomplete} from '../types/api/autocomplete';
1010
import type {CapabilitiesResponse} from '../types/api/capabilities';

src/store/reducers/planToSvgQuery.ts renamed to src/store/reducers/planToSvg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface PlanToSvgQueryParams {
77
database: string;
88
}
99

10-
export const planToSvgQueryApi = api.injectEndpoints({
10+
export const planToSvgApi = api.injectEndpoints({
1111
endpoints: (build) => ({
1212
planToSvgQuery: build.mutation<string, PlanToSvgQueryParams>({
1313
queryFn: async ({plan, database}, {signal}) => {

0 commit comments

Comments
 (0)