Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import type {ValueOf} from '../../../../types/common';
import type {ExecuteQueryResult} from '../../../../types/store/executeQuery';
import {getArray} from '../../../../utils';
import {cn} from '../../../../utils/cn';
import {USE_SHOW_PLAN_SVG_KEY} from '../../../../utils/constants';
import {getStringifiedData} from '../../../../utils/dataFormatters/dataFormatters';
import {useTypedDispatch} from '../../../../utils/hooks';
import {useSetting, useTypedDispatch} from '../../../../utils/hooks';
import {parseQueryError} from '../../../../utils/query';
import {PaneVisibilityToggleButtons} from '../../utils/paneVisibilityToggleHelpers';
import {CancelQueryButton} from '../CancelQueryButton/CancelQueryButton';
Expand All @@ -30,6 +31,7 @@ import {QuerySettingsBanner} from '../QuerySettingsBanner/QuerySettingsBanner';
import {getPreparedResult} from '../utils/getPreparedResult';
import {isQueryCancelledError} from '../utils/isQueryCancelledError';

import {PlanToSvgButton} from './PlanToSvgButton';
import {TraceButton} from './TraceButton';
import i18n from './i18n';
import {getPlan} from './utils';
Expand Down Expand Up @@ -67,6 +69,7 @@ export function ExecuteResult({
const [selectedResultSet, setSelectedResultSet] = React.useState(0);
const [activeSection, setActiveSection] = React.useState<SectionID>(resultOptionsIds.result);
const dispatch = useTypedDispatch();
const [useShowPlanToSvg] = useSetting<boolean>(USE_SHOW_PLAN_SVG_KEY);

const {error, isLoading, queryId, data} = result;

Expand Down Expand Up @@ -273,6 +276,9 @@ export function ExecuteResult({
{data?.traceId ? (
<TraceButton traceId={data.traceId} isTraceReady={result.isTraceReady} />
) : null}
{data?.plan && useShowPlanToSvg ? (
<PlanToSvgButton plan={data?.plan} database={tenantName} />
) : null}
</div>
<div className={b('controls-left')}>
{renderClipboardButton()}
Expand Down
72 changes: 72 additions & 0 deletions src/containers/Tenant/Query/ExecuteResult/PlanToSvgButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';

import {ArrowUpRightFromSquare} from '@gravity-ui/icons';
import {Button, Tooltip} from '@gravity-ui/uikit';

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

import i18n from './i18n';

function getButtonView(error: string | null, isLoading: boolean) {
if (error) {
return 'flat-danger';
}
return isLoading ? 'flat-secondary' : 'flat-info';
}

interface PlanToSvgButtonProps {
plan: QueryPlan | ScriptPlan;
database: string;
}

export function PlanToSvgButton({plan, database}: PlanToSvgButtonProps) {
const [error, setError] = React.useState<string | null>(null);
const [blobUrl, setBlobUrl] = React.useState<string | null>(null);
const [getPlanToSvg, {isLoading}] = planToSvgApi.usePlanToSvgQueryMutation();

const handleClick = React.useCallback(() => {
getPlanToSvg({plan, database})
.unwrap()
.then((result) => {
if (blobUrl) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove this check. blobUrl will be revoked in cleanup function of useEffect.

URL.revokeObjectURL(blobUrl);
}

const blob = new Blob([result], {type: 'image/svg+xml'});
const url = URL.createObjectURL(blob);
setBlobUrl(url);
setError(null);
window.open(url, '_blank');
})
.catch((err) => {
setError(JSON.stringify(err));
});
}, [blobUrl, database, getPlanToSvg, plan]);

React.useEffect(() => {
return () => {
if (blobUrl) {
URL.revokeObjectURL(blobUrl);
}
};
}, [blobUrl]);

return (
<Tooltip
content={error ? i18n('text_error-plan-svg', {error}) : i18n('text_open-plan-svg')}
>
<Button
view={getButtonView(error, isLoading)}
loading={isLoading}
onClick={handleClick}
disabled={isLoading}
>
{i18n('text_plan-svg')}
<Button.Icon>
<ArrowUpRightFromSquare />
</Button.Icon>
</Button>
</Tooltip>
);
}
5 changes: 4 additions & 1 deletion src/containers/Tenant/Query/ExecuteResult/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"action.copy": "Copy {{activeSection}}",
"trace": "Trace",
"title.truncated": "Truncated",
"title.result": "Result"
"title.result": "Result",
"text_plan-svg": "Execution plan",
"text_open-plan-svg": "Open execution plan in new window",
"text_error-plan-svg": "Error: {{error}}"
}
3 changes: 3 additions & 0 deletions src/containers/UserSettings/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"settings.usePaginatedTables.title": "Use paginated tables",
"settings.usePaginatedTables.description": " Use table with data load on scroll for Nodes and Storage tabs. It will increase performance, but could work unstable",

"settings.useShowPlanToSvg.title": "Plan to svg",
"settings.useShowPlanToSvg.description": " Show \"Plan to svg\" button in query result widow (if query was executed with full stats option).",

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

"settings.useClusterBalancerAsBackend.title": "Use cluster balancer as backend",
Expand Down
9 changes: 8 additions & 1 deletion src/containers/UserSettings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
THEME_KEY,
USE_CLUSTER_BALANCER_AS_BACKEND_KEY,
USE_PAGINATED_TABLES_KEY,
USE_SHOW_PLAN_SVG_KEY,
} from '../../utils/constants';
import {Lang, defaultLang} from '../../utils/i18n';

Expand Down Expand Up @@ -96,6 +97,12 @@ export const usePaginatedTables: SettingProps = {
description: i18n('settings.usePaginatedTables.description'),
};

export const useShowPlanToSvgTables: SettingProps = {
settingKey: USE_SHOW_PLAN_SVG_KEY,
title: i18n('settings.useShowPlanToSvg.title'),
description: i18n('settings.useShowPlanToSvg.description'),
};

export const showDomainDatabase: SettingProps = {
settingKey: SHOW_DOMAIN_DATABASE_KEY,
title: i18n('settings.showDomainDatabase.title'),
Expand Down Expand Up @@ -138,7 +145,7 @@ export const appearanceSection: SettingsSection = {
export const experimentsSection: SettingsSection = {
id: 'experimentsSection',
title: i18n('section.experiments'),
settings: [usePaginatedTables],
settings: [usePaginatedTables, useShowPlanToSvgTables],
};
export const devSettingsSection: SettingsSection = {
id: 'devSettingsSection',
Expand Down
17 changes: 17 additions & 0 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {AxiosRequestConfig} from 'axios';
import axiosRetry from 'axios-retry';

import {backend as BACKEND, metaBackend as META_BACKEND} from '../store';
import type {PlanToSvgQueryParams} from '../store/reducers/planToSvg';
import type {TMetaInfo} from '../types/api/acl';
import type {TQueryAutocomplete} from '../types/api/autocomplete';
import type {CapabilitiesResponse} from '../types/api/capabilities';
Expand Down Expand Up @@ -578,6 +579,22 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
},
);
}
planToSvg({database, plan}: PlanToSvgQueryParams, {signal}: {signal?: AbortSignal} = {}) {
return this.post<string>(
this.getPath('/viewer/plan2svg'),
plan,
{database},
{
requestConfig: {
signal,
responseType: 'text',
headers: {
Accept: 'image/svg+xml',
},
},
},
);
}
getHotKeys(
{path, database, enableSampling}: {path: string; database: string; enableSampling: boolean},
{concurrentId, signal}: AxiosOptions = {},
Expand Down
2 changes: 2 additions & 0 deletions src/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
THEME_KEY,
USE_CLUSTER_BALANCER_AS_BACKEND_KEY,
USE_PAGINATED_TABLES_KEY,
USE_SHOW_PLAN_SVG_KEY,
} from '../utils/constants';
import {DEFAULT_QUERY_SETTINGS, QUERY_ACTIONS} from '../utils/query';
import {parseJson} from '../utils/utils';
Expand All @@ -37,6 +38,7 @@ export const DEFAULT_USER_SETTINGS = {
[ASIDE_HEADER_COMPACT_KEY]: true,
[PARTITIONS_HIDDEN_COLUMNS_KEY]: [],
[USE_PAGINATED_TABLES_KEY]: true,
[USE_SHOW_PLAN_SVG_KEY]: false,
[USE_CLUSTER_BALANCER_AS_BACKEND_KEY]: true,
[ENABLE_AUTOCOMPLETE]: true,
[AUTOCOMPLETE_ON_ENTER]: true,
Expand Down
31 changes: 31 additions & 0 deletions src/store/reducers/planToSvg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type {QueryPlan, ScriptPlan} from '../../types/api/query';

import {api} from './api';

export interface PlanToSvgQueryParams {
plan: ScriptPlan | QueryPlan;
database: string;
}

export const planToSvgApi = api.injectEndpoints({
endpoints: (build) => ({
planToSvgQuery: build.mutation<string, PlanToSvgQueryParams>({
queryFn: async ({plan, database}, {signal}) => {
try {
const response = await window.api.planToSvg(
{
database,
plan,
},
{signal},
);

return {data: response};
} catch (error) {
return {error};
}
},
}),
}),
overrideExisting: 'throw',
});
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export const TENANT_INITIAL_PAGE_KEY = 'saved_tenant_initial_tab';
// Old key value for backward compatibility
export const USE_PAGINATED_TABLES_KEY = 'useBackendParamsForTables';

export const USE_SHOW_PLAN_SVG_KEY = 'useShowPlanToSvg';

// Setting to hide domain in database list
export const SHOW_DOMAIN_DATABASE_KEY = 'showDomainDatabase';

Expand Down
Loading