From 9a8125ca3b14e148b1afda89e922e440923060af Mon Sep 17 00:00:00 2001 From: Laura Benz <48948963+L-M-K-B@users.noreply.github.com> Date: Wed, 5 Jul 2023 08:47:38 +0200 Subject: [PATCH] Elasticsearch: Replace duplicate IconButton component (#71050) * refactor: replace IconButtons * refactor: replace tooltip text in order to make it more universal * refactor: remove additional IconButton * refactor: add aria-labels * refactor: fix test --- .../components/AddRemove.test.tsx | 8 ++--- .../elasticsearch/components/AddRemove.tsx | 10 ++++-- .../elasticsearch/components/IconButton.tsx | 34 ------------------- .../BucketAggregationsEditor/index.tsx | 12 +++++-- .../MetricAggregationsEditor/index.tsx | 12 +++++-- .../components/QueryEditor/QueryEditorRow.tsx | 4 +-- 6 files changed, 32 insertions(+), 48 deletions(-) delete mode 100644 public/app/plugins/datasource/elasticsearch/components/IconButton.tsx diff --git a/public/app/plugins/datasource/elasticsearch/components/AddRemove.test.tsx b/public/app/plugins/datasource/elasticsearch/components/AddRemove.test.tsx index ac04cec7aca..d968f58eb72 100644 --- a/public/app/plugins/datasource/elasticsearch/components/AddRemove.test.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/AddRemove.test.tsx @@ -18,8 +18,8 @@ describe('AddRemove Button', () => { it('Should only show the add button', () => { render(); - expect(screen.getByText('add')).toBeInTheDocument(); - expect(screen.queryByText('remove')).not.toBeInTheDocument(); + expect(screen.getByLabelText('Add')).toBeInTheDocument(); + expect(screen.queryByLabelText('Remove')).not.toBeInTheDocument(); }); }); @@ -29,7 +29,7 @@ describe('AddRemove Button', () => { render(); - expect(screen.getAllByText('remove')).toHaveLength(items.length); + expect(screen.getAllByLabelText('Remove')).toHaveLength(items.length); }); it('Should show the add button only once', () => { @@ -37,7 +37,7 @@ describe('AddRemove Button', () => { render(); - expect(screen.getAllByText('add')).toHaveLength(1); + expect(screen.getAllByLabelText('Add')).toHaveLength(1); }); }); }); diff --git a/public/app/plugins/datasource/elasticsearch/components/AddRemove.tsx b/public/app/plugins/datasource/elasticsearch/components/AddRemove.tsx index 935167f9ae0..f2765277cd2 100644 --- a/public/app/plugins/datasource/elasticsearch/components/AddRemove.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/AddRemove.tsx @@ -1,7 +1,7 @@ import { css } from '@emotion/css'; import React from 'react'; -import { IconButton } from './IconButton'; +import { Button } from '@grafana/ui'; interface Props { index: number; @@ -21,9 +21,13 @@ export const AddRemove = ({ index, onAdd, onRemove, elements }: Props) => { display: flex; `} > - {index === 0 && } + {index === 0 && ( + -); diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/index.tsx b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/index.tsx index 01ae496ea67..dfd631f3c59 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/index.tsx +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/index.tsx @@ -1,7 +1,8 @@ import React from 'react'; +import { Button } from '@grafana/ui'; + import { useDispatch } from '../../../hooks/useStatelessReducer'; -import { IconButton } from '../../IconButton'; import { useQuery } from '../ElasticsearchQueryContext'; import { QueryEditorRow } from '../QueryEditorRow'; @@ -29,7 +30,14 @@ export const BucketAggregationsEditor = ({ nextId }: Props) => { {index === 0 && ( - dispatch(addBucketAggregation(nextId))} label="add" /> +