From 0c24ff9d5d5d933cd9b58371c299c447c4e67b92 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 15 Dec 2021 16:55:08 +0100 Subject: [PATCH] InfluxDB: fix accessibility problems (#42553) (#43161) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * influxdb: influxql: query editor a11y fixes * configure datasource page a11y fixes * fixed unit test * better a11y * better a11y for the query editor * simplify code * updated tests * removed explicit aria-label (cherry picked from commit 50c6c7a528561b5233c5e0d39afb5d1e5d35d47e) Co-authored-by: Gábor Farkas --- .../src/components/Segment/SegmentSection.tsx | 5 +- .../influxdb/components/ConfigEditor.test.tsx | 11 + .../influxdb/components/ConfigEditor.tsx | 28 ++- .../components/QueryEditorModeSwitcher.tsx | 2 + .../VisualInfluxQLEditor/Editor.tsx | 11 +- .../VisualInfluxQLEditor/FormatAsSection.tsx | 4 +- .../OrderByTimeSection.tsx | 4 +- .../__snapshots__/ConfigEditor.test.tsx.snap | 188 +++--------------- 8 files changed, 83 insertions(+), 170 deletions(-) diff --git a/packages/grafana-ui/src/components/Segment/SegmentSection.tsx b/packages/grafana-ui/src/components/Segment/SegmentSection.tsx index 8cc5b7f751d..a724c310391 100644 --- a/packages/grafana-ui/src/components/Segment/SegmentSection.tsx +++ b/packages/grafana-ui/src/components/Segment/SegmentSection.tsx @@ -12,11 +12,14 @@ import { InlineFieldRow } from '../Forms/InlineFieldRow'; */ export const SegmentSection = ({ label, + htmlFor, children, fill, }: { // Name of the section label: string; + // htmlFor for the label + htmlFor?: string; // List of components in the section children: React.ReactNode; // Fill the space at the end @@ -26,7 +29,7 @@ export const SegmentSection = ({ return ( <> - + {label} {children} diff --git a/public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx b/public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx index 611aaae250a..8e8e6ed069d 100644 --- a/public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx +++ b/public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx @@ -2,6 +2,17 @@ import React from 'react'; import { shallow } from 'enzyme'; import ConfigEditor, { Props } from './ConfigEditor'; +jest.mock('lodash', () => { + const uniqueId = (prefix: string) => `${prefix}42`; + + const orig = jest.requireActual('lodash'); + + return { + ...orig, + uniqueId, + }; +}); + const setup = (propOverrides?: object) => { const props: Props = { options: { diff --git a/public/app/plugins/datasource/influxdb/components/ConfigEditor.tsx b/public/app/plugins/datasource/influxdb/components/ConfigEditor.tsx index 13d5995670b..c4513b61a8c 100644 --- a/public/app/plugins/datasource/influxdb/components/ConfigEditor.tsx +++ b/public/app/plugins/datasource/influxdb/components/ConfigEditor.tsx @@ -1,4 +1,5 @@ import React, { PureComponent } from 'react'; +import { uniqueId } from 'lodash'; import { DataSourcePluginOptionsEditorProps, SelectableValue, @@ -9,8 +10,8 @@ import { onUpdateDatasourceSecureJsonDataOption, updateDatasourcePluginJsonDataOption, } from '@grafana/data'; -import { Alert, DataSourceHttpSettings, InfoBox, InlineField, InlineFormLabel, LegacyForms } from '@grafana/ui'; -const { Select, Input, SecretFormField } = LegacyForms; +import { Alert, DataSourceHttpSettings, InfoBox, InlineField, InlineFormLabel, LegacyForms, Select } from '@grafana/ui'; +const { Input, SecretFormField } = LegacyForms; import { InfluxOptions, InfluxSecureJsonData, InfluxVersion } from '../types'; const httpModes = [ @@ -41,9 +42,12 @@ export class ConfigEditor extends PureComponent { maxSeries: '', }; + htmlPrefix: string; + constructor(props: Props) { super(props); this.state.maxSeries = props.options.jsonData.maxSeries?.toString() || ''; + this.htmlPrefix = uniqueId('influxdb-config'); } // 1x @@ -83,14 +87,18 @@ export class ConfigEditor extends PureComponent { const { options } = this.props; const { secureJsonFields } = options; const secureJsonData = (options.secureJsonData || {}) as InfluxSecureJsonData; + const { htmlPrefix } = this; return ( <>
- Organization + + Organization +
{ const { options } = this.props; const { secureJsonFields } = options; const secureJsonData = (options.secureJsonData || {}) as InfluxSecureJsonData; + const { htmlPrefix } = this; return ( <> @@ -169,9 +178,12 @@ export class ConfigEditor extends PureComponent {
- Database + + Database +
{
- User + + User +
{
httpMode.value === options.jsonData.httpMode)} @@ -258,6 +275,7 @@ export class ConfigEditor extends PureComponent {
Database @@ -149,6 +131,7 @@ exports[`Render should disable basic auth password input 1`] = ` > @@ -163,6 +146,7 @@ exports[`Render should disable basic auth password input 1`] = ` > User @@ -171,6 +155,7 @@ exports[`Render should disable basic auth password input 1`] = ` > @@ -201,6 +186,7 @@ exports[`Render should disable basic auth password input 1`] = ` > Database @@ -448,6 +397,7 @@ exports[`Render should hide basic auth fields when switch off 1`] = ` > @@ -462,6 +412,7 @@ exports[`Render should hide basic auth fields when switch off 1`] = ` > User @@ -470,6 +421,7 @@ exports[`Render should hide basic auth fields when switch off 1`] = ` > @@ -500,6 +452,7 @@ exports[`Render should hide basic auth fields when switch off 1`] = ` > Database @@ -747,6 +663,7 @@ exports[`Render should hide white listed cookies input when browser access chose > @@ -761,6 +678,7 @@ exports[`Render should hide white listed cookies input when browser access chose > User @@ -769,6 +687,7 @@ exports[`Render should hide white listed cookies input when browser access chose > @@ -799,6 +718,7 @@ exports[`Render should hide white listed cookies input when browser access chose > Database @@ -1046,6 +929,7 @@ exports[`Render should render component 1`] = ` > @@ -1060,6 +944,7 @@ exports[`Render should render component 1`] = ` > User @@ -1068,6 +953,7 @@ exports[`Render should render component 1`] = ` > @@ -1098,6 +984,7 @@ exports[`Render should render component 1`] = ` >