Skip to content

Commit e973bae

Browse files
astandrikAnton Standrik
andauthored
fix: make plan to svg more comprehensive (#1658)
Co-authored-by: Anton Standrik <astandrik@Antons-MacBook-Air.local>
1 parent fd60b9d commit e973bae

File tree

7 files changed

+58
-33
lines changed

7 files changed

+58
-33
lines changed

src/containers/Tenant/Query/QuerySettingsDialog/QuerySettingsDialog.tsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import {Dialog, Link as ExternalLink, Flex, TextInput} from '@gravity-ui/uikit';
3+
import {Dialog, Link as ExternalLink, Flex, TextInput, Tooltip} from '@gravity-ui/uikit';
44
import {zodResolver} from '@hookform/resolvers/zod';
55
import {Controller, useForm} from 'react-hook-form';
66

@@ -11,8 +11,10 @@ import {
1111
} from '../../../../store/reducers/queryActions/queryActions';
1212
import type {QuerySettings} from '../../../../types/store/query';
1313
import {cn} from '../../../../utils/cn';
14+
import {USE_SHOW_PLAN_SVG_KEY} from '../../../../utils/constants';
1415
import {
1516
useQueryExecutionSettings,
17+
useSetting,
1618
useTypedDispatch,
1719
useTypedSelector,
1820
} from '../../../../utils/hooks';
@@ -77,6 +79,7 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm
7779
resolver: zodResolver(querySettingsValidationSchema),
7880
});
7981

82+
const [useShowPlanToSvg] = useSetting<boolean>(USE_SHOW_PLAN_SVG_KEY);
8083
const enableTracingLevel = useTracingLevelOptionAvailable();
8184

8285
return (
@@ -178,22 +181,29 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm
178181
<label htmlFor="statisticsMode" className={b('field-title')}>
179182
{QUERY_SETTINGS_FIELD_SETTINGS.statisticsMode.title}
180183
</label>
181-
<div className={b('control-wrapper', {statisticsMode: true})}>
182-
<Controller
183-
name="statisticsMode"
184-
control={control}
185-
render={({field}) => (
186-
<QuerySettingsSelect
187-
id="statisticsMode"
188-
setting={field.value}
189-
onUpdateSetting={field.onChange}
190-
settingOptions={
191-
QUERY_SETTINGS_FIELD_SETTINGS.statisticsMode.options
192-
}
193-
/>
194-
)}
195-
/>
196-
</div>
184+
<Tooltip
185+
disabled={!useShowPlanToSvg}
186+
openDelay={0}
187+
content={i18n('tooltip_plan-to-svg-statistics')}
188+
>
189+
<div className={b('control-wrapper', {statisticsMode: true})}>
190+
<Controller
191+
name="statisticsMode"
192+
control={control}
193+
render={({field}) => (
194+
<QuerySettingsSelect
195+
id="statisticsMode"
196+
disabled={useShowPlanToSvg}
197+
setting={field.value}
198+
onUpdateSetting={field.onChange}
199+
settingOptions={
200+
QUERY_SETTINGS_FIELD_SETTINGS.statisticsMode.options
201+
}
202+
/>
203+
)}
204+
/>
205+
</div>
206+
</Tooltip>
197207
</Flex>
198208
<Flex direction="row" alignItems="flex-start" className={b('dialog-row')}>
199209
<label htmlFor="limitRows" className={b('field-title')}>

src/containers/Tenant/Query/QuerySettingsDialog/QuerySettingsSelect.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface QuerySettingsSelectProps<T extends SelectType> {
2626
id?: string;
2727
setting: T;
2828
settingOptions: QuerySettingSelectOption<T>[];
29+
disabled?: boolean;
2930
onUpdateSetting: (mode: T) => void;
3031
}
3132

@@ -34,6 +35,7 @@ export function QuerySettingsSelect<T extends SelectType>(props: QuerySettingsSe
3435
<div className={b('selector')}>
3536
<Select<T>
3637
id={props.id}
38+
disabled={props.disabled}
3739
options={props.settingOptions}
3840
value={[props.setting]}
3941
onUpdate={(value) => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"form.tracing-level": "Tracing level",
88
"form.limit-rows": "Limit rows",
99
"button-done": "Save",
10+
"tooltip_plan-to-svg-statistics": "Statistics option is set to \"Full\" due to the enabled \"Execution plan\" experiment.\n To disable it, go to the \"Experiments\" section in the user settings.",
1011
"button-cancel": "Cancel",
1112
"form.timeout.seconds": "sec",
1213
"form.validation.timeout": "Must be positive",

src/containers/Tenant/Query/QuerySettingsDialog/i18n/ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"form.statistics-mode": "Режим сбора статистики",
77
"form.tracing-level": "Tracing level",
88
"form.limit-rows": "Лимит строк",
9+
"tooltip_plan-to-svg-statistics": "Опция статистики установлена в значение \"Full\" из-за включенного эксперимента \"Execution plan\".\n Чтобы отключить его, перейдите в раздел \"Experiments\" в настройках пользователя.",
910
"button-done": "Готово",
1011
"button-cancel": "Отменить",
1112
"form.timeout.seconds": "сек",

src/containers/UserSettings/i18n/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535

3636
"settings.enableNetworkTable.title": "Enable network table",
3737

38-
"settings.useShowPlanToSvg.title": "Plan to svg",
39-
"settings.useShowPlanToSvg.description": " Show \"Plan to svg\" button in query result widow (if query was executed with full stats option).",
38+
"settings.useShowPlanToSvg.title": "Execution plan",
39+
"settings.useShowPlanToSvg.description": " Show \"Execution plan\" button in query result widow. Opens svg with execution plan in a new window.",
4040

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import React from 'react';
2+
13
import {useTracingLevelOptionAvailable} from '../../store/reducers/capabilities/hooks';
24
import type {QuerySettings} from '../../types/store/query';
3-
import {QUERY_EXECUTION_SETTINGS_KEY} from '../constants';
4-
import {DEFAULT_QUERY_SETTINGS, querySettingsRestoreSchema} from '../query';
5+
import {QUERY_EXECUTION_SETTINGS_KEY, USE_SHOW_PLAN_SVG_KEY} from '../constants';
6+
import {DEFAULT_QUERY_SETTINGS, STATISTICS_MODES, querySettingsRestoreSchema} from '../query';
57

68
import {useSetting} from './useSetting';
79

@@ -10,13 +12,27 @@ export const useQueryExecutionSettings = () => {
1012
const [storageSettings, setSettings] = useSetting<QuerySettings>(QUERY_EXECUTION_SETTINGS_KEY);
1113

1214
const validatedSettings = querySettingsRestoreSchema.parse(storageSettings);
15+
const [useShowPlanToSvg] = useSetting<boolean>(USE_SHOW_PLAN_SVG_KEY);
16+
17+
const setQueryExecutionSettings = React.useCallback(
18+
(settings: QuerySettings) => {
19+
setSettings({
20+
...settings,
21+
statisticsMode: useShowPlanToSvg
22+
? validatedSettings.statisticsMode
23+
: settings.statisticsMode,
24+
});
25+
},
26+
[setSettings, useShowPlanToSvg, validatedSettings.statisticsMode],
27+
);
1328

1429
const settings: QuerySettings = {
1530
...validatedSettings,
31+
statisticsMode: useShowPlanToSvg ? STATISTICS_MODES.full : validatedSettings.statisticsMode,
1632
tracingLevel: enableTracingLevel
1733
? validatedSettings.tracingLevel
1834
: DEFAULT_QUERY_SETTINGS.tracingLevel,
1935
};
2036

21-
return [settings, setSettings] as const;
37+
return [settings, setQueryExecutionSettings] as const;
2238
};

tests/suites/tenant/queryEditor/planToSvg.test.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {tenantName} from '../../../utils/constants';
44
import {toggleExperiment} from '../../../utils/toggleExperiment';
55
import {TenantPage} from '../TenantPage';
66

7-
import {ButtonNames, QueryEditor} from './models/QueryEditor';
7+
import {QueryEditor} from './models/QueryEditor';
88

99
test.describe('Test Plan to SVG functionality', async () => {
1010
const testQuery = 'SELECT 1;'; // Simple query that will generate a plan
@@ -24,30 +24,25 @@ test.describe('Test Plan to SVG functionality', async () => {
2424
const queryEditor = new QueryEditor(page);
2525

2626
// 1. Turn on Plan to SVG experiment
27-
await toggleExperiment(page, 'on', 'Plan to SVG');
27+
await toggleExperiment(page, 'on', 'Execution plan');
2828

29-
// 2. Set stats level to Full
30-
await queryEditor.clickGearButton();
31-
await queryEditor.settingsDialog.changeStatsLevel('Full');
32-
await queryEditor.settingsDialog.clickButton(ButtonNames.Save);
33-
34-
// 3. Set query and run it
29+
// 2. Set query and run it
3530
await queryEditor.setQuery(testQuery);
3631
await queryEditor.clickRunButton();
3732

38-
// 4. Wait for query execution to complete
33+
// 3. Wait for query execution to complete
3934
await expect(async () => {
4035
const status = await queryEditor.getExecutionStatus();
4136
expect(status).toBe('Completed');
4237
}).toPass();
4338

44-
// 5. Check if Execution Plan button appears and click it
39+
// 4. Check if Execution Plan button appears and click it
4540
const executionPlanButton = page.locator('button:has-text("Execution plan")');
4641
await expect(executionPlanButton).toBeVisible();
4742
await executionPlanButton.click();
4843
await page.waitForTimeout(1000); // Wait for new tab to open
4944

50-
// 6. Verify we're taken to a new tab with SVG content
45+
// 5. Verify we're taken to a new tab with SVG content
5146
const svgElement = page.locator('svg').first();
5247
await expect(svgElement).toBeVisible();
5348
});

0 commit comments

Comments
 (0)