Skip to content
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

[Look&Feel] Apply missing guidance for visBuilder #7341

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/7341.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
refactor:
- [Look&Feel] Apply guidance for visBuilder ([#7341](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7341))
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
EuiModalHeader,
EuiModalHeaderTitle,
EuiCompressedSwitch,
EuiText,
} from '@elastic/eui';
import { FormattedMessage } from '@osd/i18n/react';
import React, { Component } from 'react';
Expand Down Expand Up @@ -100,10 +101,14 @@ export default class ApplyFiltersPopoverContent extends Component<Props, State>
<React.Fragment>
<EuiModalHeader>
<EuiModalHeaderTitle>
<FormattedMessage
id="data.filter.applyFilters.popupHeader"
defaultMessage="Select filters to apply"
/>
<EuiText size="s">
<h2>
<FormattedMessage
id="data.filter.applyFilters.popupHeader"
defaultMessage="Select filters to apply"
/>
</h2>
</EuiText>
</EuiModalHeaderTitle>
</EuiModalHeader>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
// @ts-ignore
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { IndexPatternField } from '../../../../../data/common';
// @ts-ignore
import { findTestSubject } from '@elastic/eui/lib/test';
Comment on lines +7 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious are these ignored elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least in that folder they are - field_details.test.tsx and /utils/get_field_details.test.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the field details component includes my field bucket component, I mostly used the setup found in field_details.test.tsx

import { FieldBucket } from './field_bucket';
import { Bucket } from './types';

const mockUseIndexPatterns = jest.fn(() => ({ selected: 'mockIndexPattern' }));
const mockUseOnAddFilter = jest.fn();
jest.mock('../../utils/use', () => ({
useIndexPatterns: jest.fn(() => mockUseIndexPatterns),
useOnAddFilter: jest.fn(() => mockUseOnAddFilter),
}));

describe('visBuilder field bucket', function () {
function mountComponent(field: IndexPatternField, bucket: Bucket) {
const compProps = { field, bucket };
return mountWithIntl(<FieldBucket {...compProps} />);
}

it('should render with buttons if field is filterable', async () => {
const field = new IndexPatternField(
{
name: 'bytes',
type: 'number',
esTypes: ['long'],
count: 10,
scripted: false,
searchable: true,
aggregatable: true,
readFromDocValues: true,
},
'bytes'
);
const bucket = {
display: `display`,
value: `value`,
percent: 25,
count: 100,
};
const comp = mountComponent(field, bucket);
const addButton = findTestSubject(comp, 'plus-bytes-value');
const minusButton = findTestSubject(comp, 'minus-bytes-value');
expect(addButton.length).toBe(1);
expect(minusButton.length).toBe(1);

addButton.simulate('click');
minusButton.simulate('click');
expect(mockUseOnAddFilter).toHaveBeenCalledTimes(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EuiFlexItem,
EuiSpacer,
EuiProgress,
EuiToolTip,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';

Expand All @@ -35,13 +36,22 @@ export function FieldBucket({ bucket, field }: FieldBucketProps) {
// We need this to communicate to users when a top value is actually an empty string
defaultMessage: 'Empty string',
});
const addText = i18n.translate('visBuilder.fieldSelector.detailsView.filterValueButtonToolTip', {
defaultMessage: 'Filter for value',
});
const addLabel = i18n.translate(
'visBuilder.fieldSelector.detailsView.filterValueButtonAriaLabel',
{
defaultMessage: 'Filter for {fieldName}: "{value}"',
values: { fieldName, value },
}
);
const removeText = i18n.translate(
'visBuilder.fieldSelector.detailsView.filterOutValueButtonToolTip',
{
defaultMessage: 'Filter out value',
}
);
const removeLabel = i18n.translate(
'visBuilder.fieldSelector.detailsView.filterOutValueButtonAriaLabel',
{
Expand Down Expand Up @@ -84,22 +94,26 @@ export function FieldBucket({ bucket, field }: FieldBucketProps) {
{isFilterableField && (
<EuiFlexItem grow={false}>
<div>
<EuiSmallButtonIcon
className="vbFieldDetails__filterButton"
iconSize="s"
iconType="plusInCircle"
onClick={() => onAddFilter(field, value, '+')}
aria-label={addLabel}
data-test-subj={`plus-${fieldName}-${value}`}
/>
<EuiSmallButtonIcon
className="vbFieldDetails__filterButton"
iconSize="s"
iconType="minusInCircle"
onClick={() => onAddFilter(field, value, '-')}
aria-label={removeLabel}
data-test-subj={`minus-${fieldName}-${value}`}
/>
<EuiToolTip content={addText} delay="long" position="bottom">
<EuiSmallButtonIcon
className="vbFieldDetails__filterButton"
iconSize="s"
iconType="plusInCircle"
onClick={() => onAddFilter(field, value, '+')}
aria-label={addLabel}
data-test-subj={`plus-${fieldName}-${value}`}
/>
</EuiToolTip>
<EuiToolTip content={removeText} delay="long" position="bottom">
<EuiSmallButtonIcon
className="vbFieldDetails__filterButton"
iconSize="s"
iconType="minusInCircle"
onClick={() => onAddFilter(field, value, '-')}
aria-label={removeLabel}
data-test-subj={`minus-${fieldName}-${value}`}
/>
</EuiToolTip>
</div>
</EuiFlexItem>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function FieldDetailsView({ field, details }: FieldDetailsProps) {

return (
<>
<EuiPopoverTitle>{title}</EuiPopoverTitle>
<EuiPopoverTitle tabIndex={0}>{title}</EuiPopoverTitle>
<div className="vbFieldDetails" data-test-subj="fieldDetailsContainer">
{error ? (
<EuiText size="xs" data-test-subj="fieldDetailsError">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function DefaultEditorControls({
data-test-subj="visualizeEditorRenderButton"
disabled={!isDirty}
fill
iconType="play"
iconType="refresh"
onClick={applyChanges}
size="s"
>
Expand Down
Loading