Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 3 additions & 2 deletions src/containers/Tenant/Query/QueryEditor/YqlEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
selectUserInput,
} from '../../../../store/reducers/query/query';
import type {QueryAction} from '../../../../types/store/query';
import {LAST_USED_QUERY_ACTION_KEY} from '../../../../utils/constants';
import {ENABLE_CODE_ASSISTANT, LAST_USED_QUERY_ACTION_KEY} from '../../../../utils/constants';
import {
useEventHandler,
useSetting,
Expand Down Expand Up @@ -44,6 +44,7 @@ export function YqlEditor({
handleGetExplainQueryClick,
}: YqlEditorProps) {
const input = useTypedSelector(selectUserInput);
const isCodeAssistEnabled = useSetting(ENABLE_CODE_ASSISTANT);
const dispatch = useTypedDispatch();
const historyQueries = useTypedSelector(selectQueriesHistory);
const savedQueries = useSavedQueries();
Expand Down Expand Up @@ -99,7 +100,7 @@ export function YqlEditor({
}
});

if (window.api.codeAssist) {
if (window.api.codeAssist && isCodeAssistEnabled) {
registerMonacoGhost(editor);
codeAssist.prepareUserQueriesCache([
...historyQueries.map((query, index) => ({
Expand Down
3 changes: 3 additions & 0 deletions src/containers/UserSettings/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"settings.editor.autocomplete.title": "Enable autocomplete",
"settings.editor.autocomplete.description": "You're always able to get suggestions by pressing Ctrl+Space.",

"settings.editor.codeAssistant.title": "Code Assistant",
"settings.editor.codeAssistant.description": "Use Code Assistant for autocomplete.",

"settings.editor.autocomplete-on-enter.title": "Accept suggestion on Enter",
"settings.editor.autocomplete-on-enter.description": "Controls whether suggestions should be accepted on Enter, in addition to Tab. Helps to avoid ambiguity between inserting new lines or accepting suggestions.",

Expand Down
23 changes: 21 additions & 2 deletions src/containers/UserSettings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AUTOCOMPLETE_ON_ENTER,
BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
ENABLE_AUTOCOMPLETE,
ENABLE_CODE_ASSISTANT,
ENABLE_NETWORK_TABLE_KEY,
INVERTED_DISKS_KEY,
LANGUAGE_KEY,
Expand Down Expand Up @@ -120,6 +121,12 @@ export const enableAutocompleteSetting: SettingProps = {
description: i18n('settings.editor.autocomplete.description'),
};

export const enableCodeAssistantSetting: SettingProps = {
settingKey: ENABLE_CODE_ASSISTANT,
title: i18n('settings.editor.codeAssistant.title'),
description: i18n('settings.editor.codeAssistant.description'),
};

export const autocompleteOnEnterSetting: SettingProps = {
settingKey: AUTOCOMPLETE_ON_ENTER,
title: i18n('settings.editor.autocomplete-on-enter.title'),
Expand Down Expand Up @@ -192,14 +199,26 @@ export const aboutPage: SettingsPage = {
showTitle: false,
};

export function getUserSettings({singleClusterMode}: {singleClusterMode: boolean}) {
export function getUserSettings({
singleClusterMode,
codeAssistantConfigured,
}: {
singleClusterMode: boolean;
codeAssistantConfigured?: boolean;
}) {
const experiments = singleClusterMode
? experimentsPage
: createNextState(experimentsPage, (draft) => {
draft.sections[0].settings.push(useClusterBalancerAsBackendSetting);
});

const settings: YDBEmbeddedUISettings = [generalPage, editorPage, experiments, aboutPage];
const editor = codeAssistantConfigured
? createNextState(editorPage, (draft) => {
draft.sections[0].settings.push(enableCodeAssistantSetting);
})
: editorPage;

const settings: YDBEmbeddedUISettings = [generalPage, editor, experiments, aboutPage];

return settings;
}
2 changes: 2 additions & 0 deletions src/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
CASE_SENSITIVE_JSON_SEARCH,
ENABLE_AUTOCOMPLETE,
ENABLE_CODE_ASSISTANT,
ENABLE_NETWORK_TABLE_KEY,
INVERTED_DISKS_KEY,
IS_HOTKEYS_HELP_HIDDEN_KEY,
Expand Down Expand Up @@ -42,6 +43,7 @@ export const DEFAULT_USER_SETTINGS = {
[USE_SHOW_PLAN_SVG_KEY]: false,
[USE_CLUSTER_BALANCER_AS_BACKEND_KEY]: true,
[ENABLE_AUTOCOMPLETE]: true,
[ENABLE_CODE_ASSISTANT]: true,
[AUTOCOMPLETE_ON_ENTER]: true,
[IS_HOTKEYS_HELP_HIDDEN_KEY]: false,
[AUTO_REFRESH_INTERVAL]: 0,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export const USE_CLUSTER_BALANCER_AS_BACKEND_KEY = 'useClusterBalancerAsBacked';

export const ENABLE_AUTOCOMPLETE = 'enableAutocomplete';

export const ENABLE_CODE_ASSISTANT = 'enableCodeAssistant';

export const AUTOCOMPLETE_ON_ENTER = 'autocompleteOnEnter';

export const IS_HOTKEYS_HELP_HIDDEN_KEY = 'isHotKeysHelpHidden';
Expand Down
Loading