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

[Lens] Introduces new chart switcher #91844

Merged
merged 21 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5fd3f23
:sparkles: First implementation completed
dej611 Feb 17, 2021
d28a394
:white_check_mark: fix unit tests
dej611 Feb 17, 2021
78b8218
:white_check_mark: Fix functional tests
dej611 Feb 18, 2021
b9b28aa
Merge remote-tracking branch 'upstream/master' into lens/new-chart-sw…
dej611 Feb 18, 2021
89bcb5d
:label: Fix type checks
dej611 Feb 18, 2021
5a8195e
:bulb: Add more explanation for the mock
dej611 Feb 19, 2021
0340e4e
:speech_balloon: Use full label for aria label
dej611 Feb 19, 2021
79a6731
:recycle: Refactored group labels
dej611 Feb 19, 2021
2cc0032
Merge remote-tracking branch 'upstream/master' into lens/new-chart-sw…
dej611 Feb 22, 2021
7abba6c
:lipstick: Adapt list height based on result size
dej611 Feb 22, 2021
0bd7e7c
:recycle: Write numbers as constants
dej611 Feb 22, 2021
0a060ea
:speech_balloon: Revisit vis labels as suggested
dej611 Feb 22, 2021
40f1d19
Merge branch 'master' into lens/new-chart-switcher
kibanamachine Feb 23, 2021
28035d8
:ok_hand: Integrated feedback
dej611 Feb 23, 2021
09b9ff2
:bug: Fix some more copy and failing tests
dej611 Feb 23, 2021
208cdfb
:bug: Fix i18n check
dej611 Feb 24, 2021
71ec4be
:label: Refactor type
dej611 Feb 24, 2021
41e21b0
Merge branch 'master' into lens/new-chart-switcher
kibanamachine Feb 25, 2021
dc262c3
Update x-pack/plugins/lens/public/xy_visualization/visualization.tsx
dej611 Mar 1, 2021
99d5be4
Merge branch 'master' into lens/new-chart-switcher
kibanamachine Mar 1, 2021
9986e6e
:bug: Fix unit test
dej611 Mar 1, 2021
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 @@ -10,7 +10,7 @@ import { render } from 'react-dom';
import { Ast } from '@kbn/interpreter/common';
import { I18nProvider } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import type {
import {
SuggestionRequest,
Visualization,
VisualizationSuggestion,
Expand All @@ -37,15 +37,20 @@ export interface DatatableVisualizationState {
sorting?: SortingState;
}

const visualizationLabel = i18n.translate('xpack.lens.datatable.label', {
defaultMessage: 'Table',
});

export const datatableVisualization: Visualization<DatatableVisualizationState> = {
id: 'lnsDatatable',

visualizationTypes: [
{
id: 'lnsDatatable',
icon: LensIconChartDatatable,
label: i18n.translate('xpack.lens.datatable.label', {
defaultMessage: 'Data table',
label: visualizationLabel,
groupLabel: i18n.translate('xpack.lens.datatable.groupLabel', {
defaultMessage: 'Tabular and single value',
}),
},
],
Expand All @@ -68,9 +73,7 @@ export const datatableVisualization: Visualization<DatatableVisualizationState>
getDescription() {
return {
icon: LensIconChartDatatable,
label: i18n.translate('xpack.lens.datatable.label', {
defaultMessage: 'Data table',
}),
label: visualizationLabel,
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('ConfigPanel', () => {
icon: 'empty',
id: 'testVis',
label: 'TEST1',
groupLabel: 'testVisGroup',
},
],
};
Expand All @@ -85,6 +86,7 @@ describe('ConfigPanel', () => {
icon: 'empty',
id: 'testVis2',
label: 'TEST2',
groupLabel: 'testVis2Group',
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('LayerPanel', () => {
icon: 'empty',
id: 'testVis',
label: 'TEST1',
groupLabel: 'testVisGroup',
},
],
};
Expand All @@ -94,6 +95,7 @@ describe('LayerPanel', () => {
icon: 'empty',
id: 'testVis2',
label: 'TEST2',
groupLabel: 'testVis2Group',
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@

import React, { ReactElement } from 'react';
import { ReactWrapper } from 'enzyme';

// Tests are executed in a jsdom environment who does not have sizing methods,
// thus the AutoSizer will always compute a 0x0 size space
// Mock the AutoSizer inside EuiSelectable (Chart Switch) and return some dimensions > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Could you leave more detailed info why we have to do this (that the Autosizer behaves in particular way here)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed with Marta- can you specifically say that Jest tests render using jsdom and jsdom does not implement any sizing methods

jest.mock('react-virtualized-auto-sizer', () => {
return function (props: {
children: (dimensions: { width: number; height: number }) => React.ReactNode;
}) {
const { children, ...otherProps } = props;
return <div {...otherProps}>{children({ width: 100, height: 100 })}</div>;
};
});

import { EuiPanel, EuiToolTip } from '@elastic/eui';
import { mountWithIntl as mount } from '@kbn/test/jest';
import { EditorFrame } from './editor_frame';
Expand Down Expand Up @@ -83,6 +96,7 @@ describe('editor_frame', () => {
icon: 'empty',
id: 'testVis',
label: 'TEST1',
groupLabel: 'testVisGroup',
},
],
};
Expand All @@ -94,6 +108,7 @@ describe('editor_frame', () => {
icon: 'empty',
id: 'testVis2',
label: 'TEST2',
groupLabel: 'testVis2Group',
},
],
};
Expand Down Expand Up @@ -1372,6 +1387,7 @@ describe('editor_frame', () => {
icon: 'empty',
id: 'testVis3',
label: 'TEST3',
groupLabel: 'testVis3Group',
},
],
getSuggestions: () => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ img.lnsChartSwitch__chartIcon { // stylelint-disable-line selector-no-qualifying
}

.lnsChartSwitch__search {
width: 4 * $euiSizeXXL;
width: 7 * $euiSizeXXL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ import {
createMockFramePublicAPI,
createMockDatasource,
} from '../../mocks';
import { EuiKeyPadMenuItem } from '@elastic/eui';

// Tests are executed in a jsdom environment who does not have sizing methods,
// thus the AutoSizer will always compute a 0x0 size space
// Mock the AutoSizer inside EuiSelectable (Chart Switch) and return some dimensions > 0
jest.mock('react-virtualized-auto-sizer', () => {
return function (props: {
children: (dimensions: { width: number; height: number }) => React.ReactNode;
}) {
const { children } = props;
return <div>{children({ width: 100, height: 100 })}</div>;
};
});

import { mountWithIntl as mount } from '@kbn/test/jest';
import { Visualization, FramePublicAPI, DatasourcePublicAPI } from '../../../types';
import { Action } from '../state_management';
Expand All @@ -30,6 +42,7 @@ describe('chart_switch', () => {
icon: 'empty',
id,
label: `Label ${id}`,
groupLabel: `${id}Group`,
},
],
initialize: jest.fn((_frame, state?: unknown) => {
Expand Down Expand Up @@ -70,16 +83,19 @@ describe('chart_switch', () => {
icon: 'empty',
id: 'subvisC1',
label: 'C1',
groupLabel: 'visCGroup',
},
{
icon: 'empty',
id: 'subvisC2',
label: 'C2',
groupLabel: 'visCGroup',
},
{
icon: 'empty',
id: 'subvisC3',
label: 'C3',
groupLabel: 'visCGroup',
},
],
getVisualizationTypeId: jest.fn((state) => state.type),
Expand Down Expand Up @@ -166,10 +182,7 @@ describe('chart_switch', () => {

function getMenuItem(subType: string, component: ReactWrapper) {
showFlyout(component);
return component
.find(EuiKeyPadMenuItem)
.find(`[data-test-subj="lnsChartSwitchPopover_${subType}"]`)
.first();
return component.find(`[data-test-subj="lnsChartSwitchPopover_${subType}"]`).first();
}

it('should use suggested state if there is a suggestion from the target visualization', () => {
Expand Down Expand Up @@ -281,7 +294,12 @@ describe('chart_switch', () => {
/>
);

expect(getMenuItem('visB', component).prop('betaBadgeIconType')).toEqual('alert');
expect(
getMenuItem('visB', component)
.find('[data-test-subj="lnsChartSwitchPopoverAlert_visB"]')
.first()
.props().type
).toEqual('alert');
});

it('should indicate data loss if not all layers will be used', () => {
Expand All @@ -301,7 +319,12 @@ describe('chart_switch', () => {
/>
);

expect(getMenuItem('visB', component).prop('betaBadgeIconType')).toEqual('alert');
expect(
getMenuItem('visB', component)
.find('[data-test-subj="lnsChartSwitchPopoverAlert_visB"]')
.first()
.props().type
).toEqual('alert');
});

it('should support multi-layer suggestions without data loss', () => {
Expand Down Expand Up @@ -344,7 +367,9 @@ describe('chart_switch', () => {
/>
);

expect(getMenuItem('visB', component).prop('betaBadgeIconType')).toBeUndefined();
expect(
getMenuItem('visB', component).find('[data-test-subj="lnsChartSwitchPopoverAlert_visB"]')
).toHaveLength(0);
});

it('should indicate data loss if no data will be used', () => {
Expand All @@ -365,7 +390,12 @@ describe('chart_switch', () => {
/>
);

expect(getMenuItem('visB', component).prop('betaBadgeIconType')).toEqual('alert');
expect(
getMenuItem('visB', component)
.find('[data-test-subj="lnsChartSwitchPopoverAlert_visB"]')
.first()
.props().type
).toEqual('alert');
});

it('should not indicate data loss if there is no data', () => {
Expand All @@ -387,7 +417,9 @@ describe('chart_switch', () => {
/>
);

expect(getMenuItem('visB', component).prop('betaBadgeIconType')).toBeUndefined();
expect(
getMenuItem('visB', component).find('[data-test-subj="lnsChartSwitchPopoverAlert_visB"]')
).toHaveLength(0);
});

it('should not show a warning when the subvisualization is the same', () => {
Expand All @@ -411,7 +443,11 @@ describe('chart_switch', () => {
/>
);

expect(getMenuItem('subvisC2', component).prop('betaBadgeIconType')).not.toBeDefined();
expect(
getMenuItem('subvisC2', component).find(
'[data-test-subj="lnsChartSwitchPopoverAlert_subvisC2"]'
)
).toHaveLength(0);
});

it('should get suggestions when switching subvisualization', () => {
Expand Down
Loading