Skip to content

Commit

Permalink
Add missing aria-label for discover page (#6898) (#6987)
Browse files Browse the repository at this point in the history
* add missing aria-label for discover page
* Update snapshot
* add localization and make it human-readable

---------

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
  • Loading branch information
abbyhu2000 committed Jun 10, 2024
1 parent 0d06e3f commit 438e22a
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/plugins/data/public/ui/filter_bar/filter_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* under the License.
*/

import { i18n } from '@osd/i18n';
import {
EuiButtonEmpty,
EuiFlexGroup,
Expand Down Expand Up @@ -112,6 +113,9 @@ function FilterBarUI(props: Props) {
size="xs"
onClick={() => setIsAddFilterPopoverOpen(true)}
data-test-subj="addFilter"
aria-label={i18n.translate('data.filter.filterBar.addFilterButtonLabel', {
defaultMessage: 'Add filter',
})}
className="globalFilterBar__addButton"
>
+{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import {
EuiButtonEmpty,
EuiForm,
Expand Down Expand Up @@ -48,6 +49,9 @@ export function LegacyQueryLanguageSwitcher(props: Props) {
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
className="euiFormControlLayout__append dqlQueryBar__languageSwitcherButton"
data-test-subj={'switchQueryLanguageButton'}
aria-label={i18n.translate('data.query.queryBar.switchQueryLanguageButtonLabel', {
defaultMessage: 'Change query language',
})}
>
{props.language === 'lucene' ? luceneLabel : dqlLabel}
</EuiButtonEmpty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
* under the License.
*/

import { i18n } from '@osd/i18n';
import dateMath from '@elastic/datemath';
import classNames from 'classnames';
import React, { useState } from 'react';
import { i18n } from '@osd/i18n';

import {
EuiButton,
Expand Down Expand Up @@ -314,6 +314,9 @@ export default function QueryBarTopRow(props: QueryBarTopRowProps) {
isLoading={props.isLoading}
onClick={onClickSubmitButton}
data-test-subj="querySubmitButton"
aria-label={i18n.translate('data.query.queryBar.querySubmitButtonLabel', {
defaultMessage: 'Submit query',
})}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import React, { useState } from 'react';
import { EuiPanel } from '@elastic/eui';
import { IndexPattern, getServices } from '../../../opensearch_dashboards_services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import './_table_header.scss';

import { i18n } from '@osd/i18n';
import React from 'react';
import { IndexPattern } from '../../../opensearch_dashboards_services';
import { TableHeaderColumn } from './table_header_column';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import './_table_header.scss';

import React, { ReactNode } from 'react';
import { i18n } from '@osd/i18n';
import React, { ReactNode } from 'react';
import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';
import { SortOrder } from '../../../saved_searches/types';

Expand Down Expand Up @@ -168,7 +168,14 @@ export function TableHeaderColumn({
];

return (
<th data-test-subj="docTableHeaderField" className="docTableHeaderField">
<th
data-test-subj="docTableHeaderField"
className="docTableHeaderField"
role="columnheader"
aria-label={i18n.translate('discover.defaultTable.docTableHeaderLabel', {
defaultMessage: `Discover table column: ${name}`,
})}
>
<span data-test-subj={`docTableHeader-${name}`}>
{displayName}
{buttons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* GitHub history for details.
*/

import { i18n } from '@osd/i18n';
import React, { useState, useCallback } from 'react';
import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiIcon } from '@elastic/eui';
import dompurify from 'dompurify';
Expand Down Expand Up @@ -53,7 +54,9 @@ const TableRowUI = ({
color="text"
onClick={handleExpanding}
iconType={isExpanded ? 'arrowDown' : 'arrowRight'}
aria-label="Next"
aria-label={i18n.translate('discover.defaultTable.docTableExpandToggleColumnLabel', {
defaultMessage: `Toggle row details`,
})}
data-test-subj="docTableExpandToggleColumn"
/>
</td>
Expand Down Expand Up @@ -141,7 +144,6 @@ const TableRowUI = ({
</EuiFlexItem>
<EuiFlexItem>
<h4
data-test-subj="docTableRowDetailsTitle"
className="euiTitle euiTitle--xsmall"
i18n-id="discover.docTable.tableRow.detailHeading"
i18n-default-message="Expanded document"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiListGroupItemProps, EuiLink } from '@elastic/eui';
import { getDocViewsLinksRegistry } from '../../../opensearch_dashboards_services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ const FieldList = ({
onClick={() => setExpanded(!expanded)}
size="xs"
className="dscSideBar_fieldGroup"
aria-label={i18n.translate('discover.fieldChooser.fieldGroupLabel', {
defaultMessage: title,
})}
>
{title}
</EuiButtonEmpty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* under the License.
*/

import { i18n } from '@osd/i18n';
import classNames from 'classnames';
import React, { ReactNode } from 'react';
import { FieldMapping, DocViewFilterFn } from '../../doc_views/doc_views_types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export const getTopNavLinks = (
});
},
testId: 'discoverNewButton',
ariaLabel: i18n.translate('discover.topNav.discoverNewButtonLabel', {
defaultMessage: `New Search`,
}),
};

const saveSearch: TopNavMenuData = {
Expand All @@ -69,6 +72,9 @@ export const getTopNavLinks = (
defaultMessage: 'Save Search',
}),
testId: 'discoverSaveButton',
ariaLabel: i18n.translate('discover.topNav.discoverSaveButtonLabel', {
defaultMessage: `Save search`,
}),
run: async () => {
const onSave = async ({
newTitle,
Expand Down Expand Up @@ -165,6 +171,9 @@ export const getTopNavLinks = (
defaultMessage: 'Open Saved Search',
}),
testId: 'discoverOpenButton',
ariaLabel: i18n.translate('discover.topNav.discoverOpenButtonLabel', {
defaultMessage: `Open Saved Search`,
}),
run: () => {
const flyoutSession = services.overlays.openFlyout(
toMountPoint(
Expand Down Expand Up @@ -192,6 +201,9 @@ export const getTopNavLinks = (
defaultMessage: 'Share Search',
}),
testId: 'shareTopNavButton',
ariaLabel: i18n.translate('discover.topNav.discoverShareButtonLabel', {
defaultMessage: `Share search`,
}),
run: async (anchorElement) => {
const state: DiscoverState = store!.getState().discover; // store is defined before the view is loaded
const sharingData = await getSharingData({
Expand Down Expand Up @@ -224,6 +236,9 @@ export const getTopNavLinks = (
defaultMessage: 'Open Inspector for search',
}),
testId: 'openInspectorButton',
ariaLabel: i18n.translate('discover.topNav.discoverInspectorButtonLabel', {
defaultMessage: `Open Inspector for search`,
}),
run() {
inspector.open(inspectorAdapters, {
title: savedSearch?.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import React, { useEffect, useState, useRef, useCallback } from 'react';
import { EuiButtonIcon, EuiContextMenu, EuiPanel, EuiPopover, EuiSwitch } from '@elastic/eui';
import { TopNav } from './top_nav';
Expand Down Expand Up @@ -104,6 +105,9 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
button={
<EuiButtonIcon
data-test-subj="discoverOptionsButton"
aria-label={i18n.translate('discover.canvas.discoverOptionsButtonLabel', {
defaultMessage: 'Options for discover',
})}
size="s"
iconType="gear"
onClick={() => setOptionsOpen(!isOptionsOpen)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import { EuiButtonProps } from '@elastic/eui';
import { EuiIconType } from '@elastic/eui/src/components/icon/icon';
import { string } from 'mathjs';

export type TopNavMenuAction = (anchorElement: HTMLElement) => void;

Expand All @@ -42,6 +43,7 @@ export interface TopNavMenuData {
className?: string;
disableButton?: boolean | (() => boolean);
tooltip?: string | (() => string | undefined);
ariaLabel?: string;
emphasize?: boolean;
iconType?: EuiIconType;
iconSide?: EuiButtonProps['iconSide'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function TopNavMenuItem(props: TopNavMenuData) {
iconSide: props.iconSide,
'data-test-subj': props.testId,
className: props.className,
'aria-label': props.ariaLabel,
};

let component;
Expand Down

0 comments on commit 438e22a

Please sign in to comment.