Skip to content

Commit

Permalink
Query settings dialog and settings usage in requests (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
astandrik committed Jul 25, 2024
1 parent 248e57d commit f72690f
Show file tree
Hide file tree
Showing 20 changed files with 665 additions and 28 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"qs": "^6.12.0",
"react-error-boundary": "^4.0.13",
"react-helmet-async": "^2.0.5",
"react-hook-form": "^7.52.1",
"react-json-inspector": "^7.1.1",
"react-list": "^0.8.17",
"react-monaco-editor": "^0.55.0",
Expand Down
8 changes: 8 additions & 0 deletions src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {ExecuteResult} from '../ExecuteResult/ExecuteResult';
import {ExplainResult} from '../ExplainResult/ExplainResult';
import {Preview} from '../Preview/Preview';
import {QueryEditorControls} from '../QueryEditorControls/QueryEditorControls';
import {QuerySettingsDialog} from '../QuerySettingsDialog/QuerySettingsDialog';
import {SaveQueryDialog} from '../SaveQuery/SaveQuery';
import i18n from '../i18n';

Expand Down Expand Up @@ -212,6 +213,11 @@ function QueryEditor(props: QueryEditorProps) {
dispatchResultVisibilityState(PaneVisibilityActionTypes.triggerExpand);
};

const handleSettingsClick = () => {
setQueryAction('settings');
props.setShowPreview(false);
};

const handleGetExplainQueryClick = (mode: QueryMode | undefined) => {
const {input} = executeQuery;

Expand Down Expand Up @@ -345,6 +351,7 @@ function QueryEditor(props: QueryEditorProps) {
return (
<QueryEditorControls
onRunButtonClick={handleSendExecuteClick}
onSettingsButtonClick={handleSettingsClick}
runIsLoading={executeQueryResult.isLoading}
onExplainButtonClick={handleGetExplainQueryClick}
explainIsLoading={explainQueryResult.isLoading}
Expand Down Expand Up @@ -406,6 +413,7 @@ function QueryEditor(props: QueryEditorProps) {
</div>
</SplitPane>
<SaveQueryDialog />
<QuerySettingsDialog />
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';

import {ChevronDown, PlayFill} from '@gravity-ui/icons';
import {ChevronDown, Gear, PlayFill} from '@gravity-ui/icons';
import type {ButtonView} from '@gravity-ui/uikit';
import {Button, DropdownMenu, Icon} from '@gravity-ui/uikit';

import {LabelWithPopover} from '../../../../components/LabelWithPopover';
import {QUERY_SETTINGS, useSetting} from '../../../../lib';
import type {QueryAction, QueryMode} from '../../../../types/store/query';
import {cn} from '../../../../utils/cn';
import {QUERY_MODES, QUERY_MODES_TITLES} from '../../../../utils/query';
Expand Down Expand Up @@ -43,6 +44,7 @@ const QueryModeSelectorOptions = {

interface QueryEditorControlsProps {
onRunButtonClick: (mode?: QueryMode) => void;
onSettingsButtonClick: () => void;
runIsLoading: boolean;
onExplainButtonClick: (mode?: QueryMode) => void;
explainIsLoading: boolean;
Expand All @@ -54,14 +56,20 @@ interface QueryEditorControlsProps {

export const QueryEditorControls = ({
onRunButtonClick,
onSettingsButtonClick,
onUpdateQueryMode,
runIsLoading,
onExplainButtonClick,
explainIsLoading,
disabled,
onUpdateQueryMode,
queryMode,
highlightedAction,
}: QueryEditorControlsProps) => {
const [useQuerySettings] = useSetting<boolean>(QUERY_SETTINGS);
const runView: ButtonView | undefined = highlightedAction === 'execute' ? 'action' : undefined;
const explainView: ButtonView | undefined =
highlightedAction === 'explain' ? 'action' : undefined;

const querySelectorMenuItems = React.useMemo(() => {
return Object.entries(QueryModeSelectorOptions).map(([mode, {title, description}]) => {
return {
Expand All @@ -80,10 +88,6 @@ export const QueryEditorControls = ({
});
}, [onUpdateQueryMode]);

const runView: ButtonView | undefined = highlightedAction === 'execute' ? 'action' : undefined;
const explainView: ButtonView | undefined =
highlightedAction === 'explain' ? 'action' : undefined;

return (
<div className={b()}>
<div className={b('left')}>
Expand All @@ -94,6 +98,7 @@ export const QueryEditorControls = ({
disabled={disabled}
loading={runIsLoading}
view={runView}
className={b('run-button')}
>
<Icon data={PlayFill} size={14} />
{'Run'}
Expand All @@ -108,25 +113,38 @@ export const QueryEditorControls = ({
>
Explain
</Button>
<div className={b('mode-selector')}>
<DropdownMenu
items={querySelectorMenuItems}
popupProps={{
className: b('mode-selector__popup'),
qa: queryModeSelectorPopupQa,
}}
switcher={
<Button className={b('mode-selector__button')} qa={queryModeSelectorQa}>
<span className={b('mode-selector__button-content')}>
{`${i18n('controls.query-mode-selector_type')} ${
QueryModeSelectorOptions[queryMode].title
}`}
<Icon data={ChevronDown} />
</span>
</Button>
}
/>
</div>
{useQuerySettings ? (
<Button
onClick={onSettingsButtonClick}
loading={runIsLoading}
className={b('gear-button')}
>
<Icon data={Gear} size={16} />
</Button>
) : (
<div className={b('mode-selector')}>
<DropdownMenu
items={querySelectorMenuItems}
popupProps={{
className: b('mode-selector__popup'),
qa: queryModeSelectorPopupQa,
}}
switcher={
<Button
className={b('mode-selector__button')}
qa={queryModeSelectorQa}
>
<span className={b('mode-selector__button-content')}>
{`${i18n('controls.query-mode-selector_type')} ${
QueryModeSelectorOptions[queryMode].title
}`}
<Icon data={ChevronDown} />
</span>
</Button>
}
/>
</div>
)}
</div>
<SaveQuery isSaveButtonDisabled={disabled} />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.ydb-query-settings-dialog {
&__dialog-row {
& + & {
margin-top: var(--g-text-body-1-line-height);
}
}

&__field-title {
flex: 4;

margin-right: var(--g-spacing-3);

font-weight: 500;
line-height: var(--g-text-header-2-line-height);
white-space: nowrap;
}

.g-dialog-footer__bts-wrapper {
width: 100%;
}

&__dialog-body {
padding-top: var(--g-spacing-6);
}

&__control-wrapper {
display: flex;
flex: 6;
}

&__timeout {
width: 33.3%;
margin-right: var(--g-spacing-2);
}

&__timeout-suffix {
display: flex;
align-items: center;

color: var(--g-color-text-secondary);
}

&__documentation-link {
display: flex;
align-items: center;

margin-left: var(--g-spacing-4);

color: var(--g-color-text-secondary);
}

&__buttons-container {
display: flex;
justify-content: space-between;

width: 100%;
}

&__main-buttons {
display: flex;
gap: 10px;
}
}
Loading

0 comments on commit f72690f

Please sign in to comment.