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

Display correct reset terminology for single layer visualizations #94539

Merged
merged 4 commits into from
Mar 16, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ describe('LayerPanel', () => {
);
});

it('should show to reset visualization for visualizations only allowing a single layer', () => {
const layerPanelAttributes = getDefaultProps();
delete layerPanelAttributes.activeVisualization.removeLayer;
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} />);
expect(component.find('[data-test-subj="lnsLayerRemove"]').first().text()).toContain(
'Reset visualization'
);
});

it('should call the clear callback', () => {
const cb = jest.fn();
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} onRemoveLayer={cb} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export function LayerPanel(
onRemoveLayer={onRemoveLayer}
layerIndex={layerIndex}
isOnlyLayer={isOnlyLayer}
activeVisualization={activeVisualization}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,54 @@
import React from 'react';
import { EuiButtonEmpty } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { Visualization } from '../../../types';

export function RemoveLayerButton({
onRemoveLayer,
layerIndex,
isOnlyLayer,
activeVisualization,
}: {
onRemoveLayer: () => void;
layerIndex: number;
isOnlyLayer: boolean;
activeVisualization: Visualization;
}) {
let ariaLabel;
let componentText;

if (!activeVisualization.removeLayer) {
ariaLabel = i18n.translate('xpack.lens.resetVisualizationAriaLabel', {
defaultMessage: 'Reset visualization',
});
componentText = i18n.translate('xpack.lens.resetVisualization', {
defaultMessage: 'Reset visualization',
});
} else if (isOnlyLayer) {
ariaLabel = i18n.translate('xpack.lens.resetLayerAriaLabel', {
defaultMessage: 'Reset layer {index}',
values: { index: layerIndex + 1 },
});
componentText = i18n.translate('xpack.lens.resetLayer', {
defaultMessage: 'Reset layer',
});
} else {
ariaLabel = i18n.translate('xpack.lens.deleteLayerAriaLabel', {
defaultMessage: `Delete layer {index}`,
values: { index: layerIndex + 1 },
});
componentText = i18n.translate('xpack.lens.deleteLayer', {
defaultMessage: `Delete layer`,
});
}

return (
<EuiButtonEmpty
size="xs"
iconType="trash"
color="danger"
data-test-subj="lnsLayerRemove"
aria-label={
isOnlyLayer
? i18n.translate('xpack.lens.resetLayerAriaLabel', {
defaultMessage: 'Reset layer {index}',
values: { index: layerIndex + 1 },
})
: i18n.translate('xpack.lens.deleteLayerAriaLabel', {
defaultMessage: `Delete layer {index}`,
values: { index: layerIndex + 1 },
})
}
aria-label={ariaLabel}
onClick={() => {
// If we don't blur the remove / clear button, it remains focused
// which is a strange UX in this case. e.target.blur doesn't work
Expand All @@ -49,13 +70,7 @@ export function RemoveLayerButton({
onRemoveLayer();
}}
>
{isOnlyLayer
? i18n.translate('xpack.lens.resetLayer', {
defaultMessage: 'Reset layer',
})
: i18n.translate('xpack.lens.deleteLayer', {
defaultMessage: `Delete layer`,
})}
{componentText}
</EuiButtonEmpty>
);
}
1 change: 1 addition & 0 deletions x-pack/plugins/lens/public/editor_frame_service/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function createMockVisualization(): jest.Mocked<Visualization> {
return {
id: 'TEST_VIS',
clearLayer: jest.fn((state, _layerId) => state),
removeLayer: jest.fn(),
getLayerIds: jest.fn((_state) => ['layer1']),
visualizationTypes: [
{
Expand Down