-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add rows limit to query settings #1291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
60b550e
5469b74
a970b28
df16b2d
e55c633
b87e848
f572b1a
adf896f
410a10f
56f9e3f
df1c0bb
07abc0f
cdadfbf
c3fe9af
dcb0f95
67b9d0d
2c30b28
470d285
f64c011
514265d
e0d310d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| flex: 6; | ||
| } | ||
|
|
||
| &__limit-rows, | ||
| &__timeout { | ||
| width: 33.3%; | ||
| margin-right: var(--g-spacing-2); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,22 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {Dialog, Link as ExternalLink, Flex, TextInput} from '@gravity-ui/uikit'; | ||
| import {zodResolver} from '@hookform/resolvers/zod'; | ||
| import {Controller, useForm} from 'react-hook-form'; | ||
| import {z} from 'zod'; | ||
|
|
||
| import {useTracingLevelOptionAvailable} from '../../../../store/reducers/capabilities/hooks'; | ||
| import { | ||
| selectQueryAction, | ||
| setQueryAction, | ||
| } from '../../../../store/reducers/queryActions/queryActions'; | ||
| import type {QuerySettings} from '../../../../types/store/query'; | ||
| import type { | ||
| QueryMode, | ||
| QuerySettings, | ||
| StatisticsMode, | ||
| TracingLevel, | ||
| TransactionMode, | ||
| } from '../../../../types/store/query'; | ||
| import {cn} from '../../../../utils/cn'; | ||
| import { | ||
| useQueryExecutionSettings, | ||
|
|
@@ -24,6 +32,33 @@ import './QuerySettingsDialog.scss'; | |
|
|
||
| const b = cn('ydb-query-settings-dialog'); | ||
|
|
||
| const validationSchema = z.object({ | ||
| timeout: z.string().refine( | ||
| (value) => { | ||
| if (!value) { | ||
| return true; | ||
| } | ||
| const num = Number(value); | ||
| return !isNaN(num) && num > 0; | ||
| }, | ||
| {message: i18n('form.validation.timeout')}, | ||
| ), | ||
ValeraS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| limitRows: z.string().refine( | ||
| (value) => { | ||
| if (!value) { | ||
| return true; | ||
| } | ||
| const num = Number(value); | ||
| return !isNaN(num) && num > 0 && num <= 100000; | ||
| }, | ||
| {message: i18n('form.validation.limitRows')}, | ||
| ), | ||
ValeraS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| queryMode: z.custom<QueryMode>(), | ||
| transactionMode: z.custom<TransactionMode>(), | ||
| statisticsMode: z.custom<StatisticsMode>().optional(), | ||
| tracingLevel: z.custom<TracingLevel>().optional(), | ||
ValeraS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| export function QuerySettingsDialog() { | ||
| const dispatch = useTypedDispatch(); | ||
| const queryAction = useTypedSelector(selectQueryAction); | ||
|
|
@@ -66,8 +101,13 @@ interface QuerySettingsFormProps { | |
| } | ||
|
|
||
| function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsFormProps) { | ||
| const {control, handleSubmit} = useForm<QuerySettings>({ | ||
| const { | ||
| control, | ||
| handleSubmit, | ||
| formState: {errors}, | ||
| } = useForm<QuerySettings>({ | ||
| defaultValues: initialValues, | ||
| resolver: zodResolver(validationSchema), | ||
| }); | ||
|
|
||
| const enableTracingLevel = useTracingLevelOptionAvailable(); | ||
|
|
@@ -85,6 +125,7 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm | |
| control={control} | ||
| render={({field}) => ( | ||
| <QuerySettingsSelect | ||
| id="queryMode" | ||
| setting={field.value} | ||
| onUpdateSetting={field.onChange} | ||
| settingOptions={QUERY_SETTINGS_FIELD_SETTINGS.queryMode.options} | ||
|
|
@@ -104,10 +145,14 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm | |
| render={({field}) => ( | ||
| <React.Fragment> | ||
| <TextInput | ||
| id="timeout" | ||
| type="number" | ||
| {...field} | ||
| className={b('timeout')} | ||
| placeholder="60" | ||
| validationState={errors.timeout ? 'invalid' : undefined} | ||
| errorMessage={errors.timeout?.message} | ||
| errorPlacement="inside" | ||
| /> | ||
| <span className={b('timeout-suffix')}> | ||
| {i18n('form.timeout.seconds')} | ||
|
|
@@ -128,6 +173,7 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm | |
| control={control} | ||
| render={({field}) => ( | ||
| <QuerySettingsSelect | ||
| id="tracingLevel" | ||
| setting={field.value} | ||
| onUpdateSetting={field.onChange} | ||
| settingOptions={ | ||
|
|
@@ -149,6 +195,7 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm | |
| control={control} | ||
| render={({field}) => ( | ||
| <QuerySettingsSelect | ||
| id="transactionMode" | ||
| setting={field.value} | ||
| onUpdateSetting={field.onChange} | ||
| settingOptions={ | ||
|
|
@@ -169,6 +216,7 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm | |
| control={control} | ||
| render={({field}) => ( | ||
| <QuerySettingsSelect | ||
| id="statisticsMode" | ||
| setting={field.value} | ||
| onUpdateSetting={field.onChange} | ||
| settingOptions={ | ||
|
|
@@ -179,6 +227,29 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm | |
| /> | ||
| </div> | ||
| </Flex> | ||
| <Flex direction="row" alignItems="flex-start" className={b('dialog-row')}> | ||
| <label htmlFor="limitRows" className={b('field-title')}> | ||
ValeraS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {QUERY_SETTINGS_FIELD_SETTINGS.limitRows.title} | ||
| </label> | ||
| <div className={b('control-wrapper')}> | ||
| <Controller | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add validation in |
||
| name="limitRows" | ||
| control={control} | ||
| render={({field}) => ( | ||
| <TextInput | ||
| id="limitRows" | ||
| type="number" | ||
| {...field} | ||
| className={b('limit-rows')} | ||
| placeholder="10000" | ||
| validationState={errors.limitRows ? 'invalid' : undefined} | ||
| errorMessage={errors.limitRows?.message} | ||
| errorPlacement="inside" | ||
| /> | ||
| )} | ||
| /> | ||
| </div> | ||
| </Flex> | ||
| </Dialog.Body> | ||
| <Dialog.Footer | ||
| textButtonApply={i18n('button-done')} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,6 +233,7 @@ export const executeQueryApi = api.injectEndpoints({ | |
| querySettings.tracingLevel && enableTracingLevel | ||
| ? TracingLevelNumber[querySettings.tracingLevel] | ||
| : undefined, | ||
| limit_rows: querySettings.limitRows || undefined, | ||
|
||
| transaction_mode: | ||
| querySettings.transactionMode === 'implicit' | ||
| ? undefined | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.