diff --git a/public/app/features/plugins/sql/components/configuration/ConnectionLimits.tsx b/public/app/features/plugins/sql/components/configuration/ConnectionLimits.tsx index d7f97b8620b..10f0eebb147 100644 --- a/public/app/features/plugins/sql/components/configuration/ConnectionLimits.tsx +++ b/public/app/features/plugins/sql/components/configuration/ConnectionLimits.tsx @@ -1,20 +1,29 @@ import React from 'react'; import { DataSourceSettings } from '@grafana/data'; +import { ConfigSubSection, Stack } from '@grafana/experimental'; import { config } from '@grafana/runtime'; -import { FieldSet, InlineField, InlineFieldRow, InlineSwitch } from '@grafana/ui'; -import { NumberInput } from 'app/core/components/OptionsUI/NumberInput'; +import { Field, Icon, InlineLabel, Input, Label, Switch, Tooltip } from '@grafana/ui'; import { SQLConnectionLimits, SQLOptions } from '../../types'; interface Props { onOptionsChange: Function; options: DataSourceSettings; - labelWidth: number; +} + +function toNumber(text: string): number { + if (text.trim() === '') { + // calling `Number('')` returns zero, + // so we have to handle this case + return NaN; + } + + return Number(text); } export const ConnectionLimits = (props: Props) => { - const { onOptionsChange, options, labelWidth } = props; + const { onOptionsChange, options } = props; const jsonData = options.jsonData; const autoIdle = jsonData.maxIdleConnsAuto !== undefined ? jsonData.maxIdleConnsAuto : false; @@ -81,67 +90,140 @@ export const ConnectionLimits = (props: Props) }); }; + const labelWidth = 40; + return ( -
- - The maximum number of open connections to the database.If Max idle connections is greater than 0 and - the Max open connections is less than Max idle connections, then - Max idle connections will be reduced to match the Max open connections limit. If set to 0, - there is no limit on the number of open connections. - + + + + Max open + + The maximum number of open connections to the database. If Max idle connections is greater + than 0 and the Max open connections is less than Max idle connections, then + Max idle connections will be reduced to match the Max open connections limit. If set + to 0, there is no limit on the number of open connections. + + } + > + + + + } - labelWidth={labelWidth} - label="Max open" > - - - - - The maximum number of connections in the idle connection pool.If Max open connections is greater - than 0 but less than the Max idle connections, then the Max idle connections will be reduced - to match the Max open connections limit. If set to 0, no idle connections are retained. - - } - labelWidth={labelWidth} - label="Max idle" - > - { + const newVal = toNumber(e.currentTarget.value); + if (!Number.isNaN(newVal)) { + onMaxConnectionsChanged(newVal); + } + }} + width={labelWidth} + /> + + + + + Auto Max Idle + + If enabled, automatically set the number of Maximum idle connections to the same value as + Max open connections. If the number of maximum open connections is not set it will be set to + the default ({config.sqlConnectionLimits.maxIdleConns}). + + } + > + + + + + } + > + + + + + + Max idle + + The maximum number of connections in the idle connection pool.If Max open connections is + greater than 0 but less than the Max idle connections, then the Max idle connections{' '} + will be reduced to match the Max open connections limit. If set to 0, no idle connections are + retained. + + } + > + + + + + } + > + {autoIdle ? ( + {options.jsonData.maxIdleConns} + ) : ( + { + const newVal = toNumber(e.currentTarget.value); + if (!Number.isNaN(newVal)) { + onJSONDataNumberChanged('maxIdleConns')(newVal); + } + }} + width={labelWidth} + disabled={autoIdle} /> - - - If enabled, automatically set the number of Maximum idle connections to the same value as - Max open connections. If the number of maximum open connections is not set it will be set to the - default ({config.sqlConnectionLimits.maxIdleConns}). - - } - > - - - - + + + + Max lifetime + + The maximum amount of time in seconds a connection may be reused. If set to 0, connections are + reused forever. + + } + > + + + + + } > - - -
+ defaultValue={jsonData.connMaxLifetime} + onChange={(e) => { + const newVal = toNumber(e.currentTarget.value); + if (!Number.isNaN(newVal)) { + onJSONDataNumberChanged('connMaxLifetime')(newVal); + } + }} + width={labelWidth} + /> + + ); }; diff --git a/public/app/plugins/datasource/mssql/configuration/ConfigurationEditor.tsx b/public/app/plugins/datasource/mssql/configuration/ConfigurationEditor.tsx index 22a56cc03eb..19e1e8a42c8 100644 --- a/public/app/plugins/datasource/mssql/configuration/ConfigurationEditor.tsx +++ b/public/app/plugins/datasource/mssql/configuration/ConfigurationEditor.tsx @@ -38,7 +38,6 @@ import { MssqlSecureOptions, } from '../types'; -const SHORT_WIDTH = 15; const LONG_WIDTH = 40; export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps) => { @@ -297,7 +296,7 @@ export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps - + - + diff --git a/public/app/plugins/datasource/postgres/configuration/ConfigurationEditor.tsx b/public/app/plugins/datasource/postgres/configuration/ConfigurationEditor.tsx index 253ed18d71e..0c9baf22211 100644 --- a/public/app/plugins/datasource/postgres/configuration/ConfigurationEditor.tsx +++ b/public/app/plugins/datasource/postgres/configuration/ConfigurationEditor.tsx @@ -246,7 +246,7 @@ export const PostgresConfigEditor = (props: DataSourcePluginOptionsEditorProps

) : null} - +