From 0a0c5ccc2e72c16aad7db8cdafbc97c113939113 Mon Sep 17 00:00:00 2001 From: Anton Standrik Date: Fri, 16 Aug 2024 14:46:17 +0300 Subject: [PATCH] feat: [query settings] display trace level selector --- src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx | 4 ++-- .../Query/QuerySettingsDialog/QuerySettingsDialog.tsx | 5 ++--- src/containers/UserSettings/i18n/en.json | 3 --- src/containers/UserSettings/settings.tsx | 9 +-------- src/services/settings.ts | 2 -- src/store/reducers/capabilities/hooks.ts | 4 ++++ src/types/api/capabilities.ts | 2 +- src/utils/constants.ts | 2 -- src/utils/hooks/useQueryExecutionSettings.ts | 9 +++------ 9 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx b/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx index 7c61be48a..6b98f9835 100644 --- a/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx +++ b/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx @@ -10,6 +10,7 @@ import {MonacoEditor} from '../../../../components/MonacoEditor/MonacoEditor'; import SplitPane from '../../../../components/SplitPane'; import type {RootState} from '../../../../store'; import {cancelQueryApi} from '../../../../store/reducers/cancelQuery'; +import {useTracingLevelOptionAvailable} from '../../../../store/reducers/capabilities/hooks'; import { executeQueryApi, goToNextQuery, @@ -29,7 +30,6 @@ import {cn} from '../../../../utils/cn'; import { DEFAULT_IS_QUERY_RESULT_COLLAPSED, DEFAULT_SIZE_RESULT_PANE_KEY, - ENABLE_TRACING_LEVEL_KEY, LAST_USED_QUERY_ACTION_KEY, QUERY_USE_MULTI_SCHEMA_KEY, } from '../../../../utils/constants'; @@ -103,7 +103,7 @@ function QueryEditor(props: QueryEditorProps) { const [resultType, setResultType] = React.useState>(); const [isResultLoaded, setIsResultLoaded] = React.useState(false); const [querySettings] = useQueryExecutionSettings(); - const [enableTracingLevel] = useSetting(ENABLE_TRACING_LEVEL_KEY); + const enableTracingLevel = useTracingLevelOptionAvailable(); const [lastQueryExecutionSettings, setLastQueryExecutionSettings] = useLastQueryExecutionSettings(); const {resetBanner} = useChangedQuerySettings(); diff --git a/src/containers/Tenant/Query/QuerySettingsDialog/QuerySettingsDialog.tsx b/src/containers/Tenant/Query/QuerySettingsDialog/QuerySettingsDialog.tsx index 7af6d08ea..f32b63316 100644 --- a/src/containers/Tenant/Query/QuerySettingsDialog/QuerySettingsDialog.tsx +++ b/src/containers/Tenant/Query/QuerySettingsDialog/QuerySettingsDialog.tsx @@ -3,16 +3,15 @@ import React from 'react'; import {Dialog, Link as ExternalLink, Flex, TextInput} from '@gravity-ui/uikit'; import {Controller, useForm} from 'react-hook-form'; +import {useTracingLevelOptionAvailable} from '../../../../store/reducers/capabilities/hooks'; import { selectQueryAction, setQueryAction, } from '../../../../store/reducers/queryActions/queryActions'; import type {QuerySettings} from '../../../../types/store/query'; import {cn} from '../../../../utils/cn'; -import {ENABLE_TRACING_LEVEL_KEY} from '../../../../utils/constants'; import { useQueryExecutionSettings, - useSetting, useTypedDispatch, useTypedSelector, } from '../../../../utils/hooks'; @@ -71,7 +70,7 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm defaultValues: initialValues, }); - const [enableTracingLevel] = useSetting(ENABLE_TRACING_LEVEL_KEY); + const enableTracingLevel = useTracingLevelOptionAvailable(); return (
diff --git a/src/containers/UserSettings/i18n/en.json b/src/containers/UserSettings/i18n/en.json index 48034eeed..84d1cdbfd 100644 --- a/src/containers/UserSettings/i18n/en.json +++ b/src/containers/UserSettings/i18n/en.json @@ -39,9 +39,6 @@ "settings.showDomainDatabase.title": "Show domain database", - "settings.enableTracingLevel.title": "Enable tracing level select", - "settings.enableTracingLevel.description": "Caution: Enabling this setting may break running of queries", - "settings.queryUseMultiSchema.title": "Allow queries with multiple result sets", "settings.queryUseMultiSchema.description": "Use 'multi' schema for queries. It enables queries with multiple result sets. It returns nothing on versions 23-3 and older", diff --git a/src/containers/UserSettings/settings.tsx b/src/containers/UserSettings/settings.tsx index 90dc2220c..015e56545 100644 --- a/src/containers/UserSettings/settings.tsx +++ b/src/containers/UserSettings/settings.tsx @@ -6,7 +6,6 @@ import { AUTOCOMPLETE_ON_ENTER, BINARY_DATA_IN_PLAIN_TEXT_DISPLAY, ENABLE_AUTOCOMPLETE, - ENABLE_TRACING_LEVEL_KEY, INVERTED_DISKS_KEY, LANGUAGE_KEY, QUERY_USE_MULTI_SCHEMA_KEY, @@ -113,12 +112,6 @@ export const showDomainDatabase: SettingProps = { title: i18n('settings.showDomainDatabase.title'), }; -export const enableTracingLevel: SettingProps = { - settingKey: ENABLE_TRACING_LEVEL_KEY, - title: i18n('settings.enableTracingLevel.title'), - description: i18n('settings.enableTracingLevel.description'), -}; - export const queryUseMultiSchemaSetting: SettingProps = { settingKey: QUERY_USE_MULTI_SCHEMA_KEY, title: i18n('settings.queryUseMultiSchema.title'), @@ -167,7 +160,7 @@ export const experimentsSection: SettingsSection = { export const devSettingsSection: SettingsSection = { id: 'devSettingsSection', title: i18n('section.dev-setting'), - settings: [enableAutocompleteSetting, autocompleteOnEnterSetting, enableTracingLevel], + settings: [enableAutocompleteSetting, autocompleteOnEnterSetting], }; export const aboutSettingsSection: SettingsSection = { diff --git a/src/services/settings.ts b/src/services/settings.ts index 3191c8e50..bfe6b777f 100644 --- a/src/services/settings.ts +++ b/src/services/settings.ts @@ -6,7 +6,6 @@ import { BINARY_DATA_IN_PLAIN_TEXT_DISPLAY, DEFAULT_QUERY_SETTINGS, ENABLE_AUTOCOMPLETE, - ENABLE_TRACING_LEVEL_KEY, INVERTED_DISKS_KEY, IS_HOTKEYS_HELP_HIDDEN_KEY, LANGUAGE_KEY, @@ -48,7 +47,6 @@ export const DEFAULT_USER_SETTINGS = { [AUTOCOMPLETE_ON_ENTER]: true, [IS_HOTKEYS_HELP_HIDDEN_KEY]: false, [AUTO_REFRESH_INTERVAL]: 0, - [ENABLE_TRACING_LEVEL_KEY]: false, [SHOW_DOMAIN_DATABASE_KEY]: false, [LAST_QUERY_EXECUTION_SETTINGS_KEY]: undefined, [QUERY_SETTINGS_BANNER_LAST_CLOSED_KEY]: undefined, diff --git a/src/store/reducers/capabilities/hooks.ts b/src/store/reducers/capabilities/hooks.ts index 6df63b997..4abb49f43 100644 --- a/src/store/reducers/capabilities/hooks.ts +++ b/src/store/reducers/capabilities/hooks.ts @@ -16,3 +16,7 @@ export const useDiskPagesAvailable = () => { // It's enough to check only pdisk handler return useGetFeatureVersion('/pdisk/info') > 0; }; + +export const useTracingLevelOptionAvailable = () => { + return useGetFeatureVersion('/viewer/query') > 2; +}; diff --git a/src/types/api/capabilities.ts b/src/types/api/capabilities.ts index 297d11e6b..6fc70dbfc 100644 --- a/src/types/api/capabilities.ts +++ b/src/types/api/capabilities.ts @@ -6,4 +6,4 @@ export interface CapabilitiesResponse { } // Add feature name before using it -export type Capability = '/pdisk/info' | '/scheme/directory'; +export type Capability = '/pdisk/info' | '/scheme/directory' | '/viewer/query'; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 04c409805..842af39f7 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -159,5 +159,3 @@ export const ENABLE_AUTOCOMPLETE = 'enableAutocomplete'; export const AUTOCOMPLETE_ON_ENTER = 'autocompleteOnEnter'; export const IS_HOTKEYS_HELP_HIDDEN_KEY = 'isHotKeysHelpHidden'; - -export const ENABLE_TRACING_LEVEL_KEY = 'enableTracingLevel'; diff --git a/src/utils/hooks/useQueryExecutionSettings.ts b/src/utils/hooks/useQueryExecutionSettings.ts index 5bba35824..0425b87a1 100644 --- a/src/utils/hooks/useQueryExecutionSettings.ts +++ b/src/utils/hooks/useQueryExecutionSettings.ts @@ -1,14 +1,11 @@ +import {useTracingLevelOptionAvailable} from '../../store/reducers/capabilities/hooks'; import type {QuerySettings} from '../../types/store/query'; -import { - DEFAULT_QUERY_SETTINGS, - ENABLE_TRACING_LEVEL_KEY, - QUERY_EXECUTION_SETTINGS_KEY, -} from '../constants'; +import {DEFAULT_QUERY_SETTINGS, QUERY_EXECUTION_SETTINGS_KEY} from '../constants'; import {useSetting} from './useSetting'; export const useQueryExecutionSettings = () => { - const [enableTracingLevel] = useSetting(ENABLE_TRACING_LEVEL_KEY); + const enableTracingLevel = useTracingLevelOptionAvailable(); const [setting, setSetting] = useSetting(QUERY_EXECUTION_SETTINGS_KEY); return [