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

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Feb 18, 2021

Summary

Fixes #89708

This PR introduces the new chart switcher in Lens, which is designed to better handle more charts in the future.

One chart type selected:
Screenshot 2021-02-18 at 15 05 25

With multiple XY chart types (no selection but correct label on toolbar):

Screenshot 2021-02-18 at 15 04 24

In case of "data loss" when changing chart type (notice the icon is on the right rather than left as in the original mockup in the issue):
Screenshot 2021-02-18 at 15 04 07
Screenshot 2021-02-18 at 15 06 59

Search working:
Screenshot 2021-02-18 at 15 04 34

Unit and functional tests required a small amount of changes to work, but the none has been disabled and the same behaviour can be reproduced as the previous implementation.

Checklist

@dej611 dej611 added release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure labels Feb 18, 2021
@dej611 dej611 marked this pull request as ready for review February 18, 2021 16:23
@dej611 dej611 requested a review from a team February 18, 2021 16:23
@dej611 dej611 requested a review from a team as a code owner February 18, 2021 16:23
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@@ -7,6 +7,17 @@

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

// 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

@@ -439,6 +439,9 @@ export const visualizationTypes: VisualizationType[] = [
label: i18n.translate('xpack.lens.xyVisualization.barLabel', {
defaultMessage: 'Bar',
}),
groupLabel: i18n.translate('xpack.lens.xyVisualization.barGroupLabel', {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we repeat this copy 4 times for Bar and then another one 4 times for line or area. Maybe it's worth to assign it to variable and then read it here?

@@ -16,18 +16,29 @@ export const CHART_NAMES = {
label: i18n.translate('xpack.lens.pie.donutLabel', {
defaultMessage: 'Donut',
}),
groupLabel: i18n.translate('xpack.lens.pie.groupLabel', {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: same comment about repeating the same copy 3 times

}
return [{ key: group, label: group, isGroupLabel: true }].concat(
visualizations.map((v) => ({
'aria-label': v.label,
Copy link
Contributor

@mbondyra mbondyra Feb 19, 2021

Choose a reason for hiding this comment

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

can we use full label for aria-label, so eg. Horizontal Bar instead of H. Bar?

Suggested change
'aria-label': v.label,
'aria-label': v.fullLabel,
title: v.fullLabel,

Can we also add title so when you hover, you see the whole title?
image

Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

Tested in Chrome and Safari. Code LGTM with small comments. I'll approve once we'll get an OK from design team that the design changes are fine (in case if you'd have to change big chunks of code because of it)

@flash1293
Copy link
Contributor

Didn't test yet, but we've talked about an option to scroll to the currently active section on open (if available). Do you think that would be easy to add?

@dej611
Copy link
Contributor Author

dej611 commented Feb 19, 2021

@flash1293 I forgot about that. Will add it.
@mbondyra thanks for the review! Will integrate your feedback ASAP.

@dej611
Copy link
Contributor Author

dej611 commented Feb 19, 2021

@flash1293 the scroll to item behaviour is not exposed yet in the EuiSelectable component.
Unless strictly required I propose we could add it later on when EUI adds the method for it?

@MichaelMarcialis
Copy link
Contributor

@dej611: This is looking great! While I was playing around with your branch this afternoon, two items caught my eye that I wanted to ask about.

  1. It appears that you're keeping the previous chart naming convention (which included abbreviations). With the move to this more linear listing the chart types, I was hoping we could do away with the abbreviation of chart types altogether and adopt the updated names suggested in my designs, as text width is now less of a concern. Would it be possible to change them?

image

  1. When using the search bar to filter chart types, it appears that the height of the menu does not decrease when the number of items is smaller than the maximum height of the menu. This ends up leaving a big blank space at the bottom of the menu. Can this be corrected to match the designs?

image

Regarding the swapping of sides for the alert icon tooltip, I'm good with that. There are a few other small design deviations (such as popover padding, border divider between search and selectable list, etc.), but I think changing those here would demand that we make those changes in other menus across Lens for consistency (such as the index patterns menu). If that's beyond the scope of this PR, I'm happy to put on my todo list for a later time. Thanks!

@flash1293
Copy link
Contributor

the scroll to item behaviour is not exposed yet in the EuiSelectable component.
Unless strictly required I propose we could add it later on when EUI adds the method for it?

I see, with virtualized scrolling it's hard to add it from the outside. In that case I guess we can live with postponing this.

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Found a crash when I tested it!

@@ -7,6 +7,17 @@

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

// 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.

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

for (const visualizationType of v.visualizationTypes) {
const isSearchMatch =
visualizationType.label.toLowerCase().includes(lowercasedSearchTerm) ||
visualizationType.fullLabel?.toLowerCase().includes(lowercasedSearchTerm);
Copy link
Contributor

Choose a reason for hiding this comment

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

So we're only looking at the i18n text for the search? I guess this makes sense...

onChange={(newOptions) => {
const id = newOptions.find(({ checked }) => checked === 'on')!.value!;
commitSelection(visualizationsLookup[id].selection);
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

We've had this bug before, but this appears to be a pretty big one. Lens crashes if you select the currently selected option.

},
{
id: 'line',
icon: LensIconChartLine,
label: i18n.translate('xpack.lens.xyVisualization.lineLabel', {
defaultMessage: 'Line',
}),
groupLabel: groupLabelForLineAndArea,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is Line the last chart in the "Line and area" group?

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this was done to match the designs, as the designs sort both the chart groups and chart items in alpha order.

@dej611
Copy link
Contributor Author

dej611 commented Feb 23, 2021

@elasticmachine merge upstream

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

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

Thanks for making those earlier changes, @dej611. I left a few additional wording suggestions below to better match the designs. After those wording changes are made, could you also ensure that the chart groups and the items within each group in alpha order?

Aside from that, this looks good from my perspective. Approving now so I don't hold you up further.

},
{
id: 'line',
icon: LensIconChartLine,
label: i18n.translate('xpack.lens.xyVisualization.lineLabel', {
defaultMessage: 'Line',
}),
groupLabel: groupLabelForLineAndArea,
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this was done to match the designs, as the designs sort both the chart groups and chart items in alpha order.

Comment on lines 277 to 294
<EuiIconTip
aria-label={i18n.translate('xpack.lens.chartSwitch.dataLossLabel', {
defaultMessage: 'Data loss',
})}
type="alert"
color="warning"
title={i18n.translate('xpack.lens.chartSwitch.dataLossLabel', {
defaultMessage: 'Data loss',
})}
content={i18n.translate('xpack.lens.chartSwitch.dataLossDescription', {
defaultMessage:
'Switching to this chart will lose some of the configuration',
})}
iconProps={{
className: 'lnsChartSwitch__chartIcon',
'data-test-subj': `lnsChartSwitchPopoverAlert_${v.id}`,
}}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggesting the following changes to better match the design.

Suggested change
<EuiIconTip
aria-label={i18n.translate('xpack.lens.chartSwitch.dataLossLabel', {
defaultMessage: 'Data loss',
})}
type="alert"
color="warning"
title={i18n.translate('xpack.lens.chartSwitch.dataLossLabel', {
defaultMessage: 'Data loss',
})}
content={i18n.translate('xpack.lens.chartSwitch.dataLossDescription', {
defaultMessage:
'Switching to this chart will lose some of the configuration',
})}
iconProps={{
className: 'lnsChartSwitch__chartIcon',
'data-test-subj': `lnsChartSwitchPopoverAlert_${v.id}`,
}}
/>
<EuiIconTip
aria-label={i18n.translate('xpack.lens.chartSwitch.dataLossLabel', {
defaultMessage: 'Warning',
})}
type="alert"
color="warning"
content={i18n.translate('xpack.lens.chartSwitch.dataLossDescription', {
defaultMessage:
'Selecting this chart type will result in a partial loss of currently applied configuration selections.',
})}
iconProps={{
className: 'lnsChartSwitch__chartIcon',
'data-test-subj': `lnsChartSwitchPopoverAlert_${v.id}`,
}}
/>

},
{
id: 'bar_stacked',
icon: LensIconChartBarStacked,
label: i18n.translate('xpack.lens.xyVisualization.stackedBarLabel', {
defaultMessage: 'Stacked bar',
defaultMessage: 'Bar stacked',
Copy link
Contributor

Choose a reason for hiding this comment

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

To be consistent with naming and match the designs.

Suggested change
defaultMessage: 'Bar stacked',
defaultMessage: 'Bar vertical stacked',

},
{
id: 'bar_percentage_stacked',
icon: LensIconChartBarPercentage,
label: i18n.translate('xpack.lens.xyVisualization.stackedPercentageBarLabel', {
defaultMessage: 'Percentage bar',
defaultMessage: 'Bar percentage bar',
Copy link
Contributor

Choose a reason for hiding this comment

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

To be consistent with naming and match the designs.

Suggested change
defaultMessage: 'Bar percentage bar',
defaultMessage: 'Bar vertical percentage',

@@ -439,6 +446,7 @@ export const visualizationTypes: VisualizationType[] = [
label: i18n.translate('xpack.lens.xyVisualization.barLabel', {
defaultMessage: 'Bar',
Copy link
Contributor

Choose a reason for hiding this comment

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

To be consistent with naming and match the designs.

Suggested change
defaultMessage: 'Bar',
defaultMessage: 'Bar vertical',

},
{
id: 'area',
icon: LensIconChartArea,
label: i18n.translate('xpack.lens.xyVisualization.areaLabel', {
defaultMessage: 'Area',
}),
groupLabel: groupLabelForLineAndArea,
},
{
id: 'area_stacked',
icon: LensIconChartAreaStacked,
label: i18n.translate('xpack.lens.xyVisualization.stackedAreaLabel', {
defaultMessage: 'Stacked area',
Copy link
Contributor

Choose a reason for hiding this comment

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

To be consistent with naming and match the designs.

Suggested change
defaultMessage: 'Stacked area',
defaultMessage: 'Area stacked',

},
{
id: 'area_stacked',
icon: LensIconChartAreaStacked,
label: i18n.translate('xpack.lens.xyVisualization.stackedAreaLabel', {
defaultMessage: 'Stacked area',
}),
groupLabel: groupLabelForLineAndArea,
},
{
id: 'area_percentage_stacked',
icon: LensIconChartAreaPercentage,
label: i18n.translate('xpack.lens.xyVisualization.stackedPercentageAreaLabel', {
defaultMessage: 'Percentage area',
Copy link
Contributor

Choose a reason for hiding this comment

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

To be consistent with naming and match the designs.

Suggested change
defaultMessage: 'Percentage area',
defaultMessage: 'Area percentage',

@@ -47,6 +47,9 @@ export const datatableVisualization: Visualization<DatatableVisualizationState>
label: i18n.translate('xpack.lens.datatable.label', {
defaultMessage: 'Data table',
Copy link
Contributor

Choose a reason for hiding this comment

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

To be consistent with naming and match the designs.

Suggested change
defaultMessage: 'Data table',
defaultMessage: 'Table',

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested in Chrome and this LGTM. I think we should kick off a flaky test runner for this - I see some flakiness potential here :)

@@ -54,6 +51,18 @@ interface Props {
>;
}

interface SelectableEntry {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: You can replace this by type SelectableEntry = EuiSelectableOption<{ value: string }>.

There's one small issue with the type of the array returned in 272 because concat is not playing nice, but you can cast it using as SelectableEntry[]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that was the main reason to redeclare it from scratch. I'll see if it's possible to fix it without force casting it. In case it's not possible, I'll force cast 😅

@dej611 dej611 requested a review from mbondyra February 25, 2021 08:50
@dej611
Copy link
Contributor Author

dej611 commented Feb 25, 2021

@elasticmachine merge upstream

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Co-authored-by: Wylie Conlon <wylieconlon@gmail.com>
@dej611
Copy link
Contributor Author

dej611 commented Mar 1, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 918.2KB 920.8KB +2.6KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@dej611 dej611 merged commit 03cc5cc into elastic:master Mar 2, 2021
@dej611 dej611 deleted the lens/new-chart-switcher branch March 2, 2021 10:25
dej611 added a commit to dej611/kibana that referenced this pull request Mar 2, 2021
Co-authored-by: Wylie Conlon <wylieconlon@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 2, 2021
* master: (42 commits)
  [Lens] Introduces new chart switcher (elastic#91844)
  [Lens] fix selection when dragging (elastic#93034)
  Converts usage collection README to .mdx (elastic#92982)
  Fix expanding document when using saved search data grid (elastic#92999)
  [SECURITY SOLUTIONS] Bug case connector (elastic#93104)
  [Security Solution] [Timeline] Bugfix to include unmapped fields in the timeline event details JSON (elastic#92025)
  [Alerting][Docs] Changed alerting documentation to point to a single source of explaining the configurations. (elastic#92942)
  [APM] Fix hidden search bar in error pages while loading (elastic#84476) (elastic#93139)
  [DOCS] Fixes links for machine learning alerts (elastic#92744)
  [Security Solution][Detections] -Fixes rule edit flow bug with max_signals (elastic#92748)
  [SecuritySolution][Case] Disable cases on detections in read-only mode (elastic#93010)
  [Security Solution][Case][Bug] Prevent closing collection when pushing (elastic#93095)
  [Security Solution][Detections][7.12] Critical Threshold Rule Fixes (elastic#92667)
  Bump ems landing page to 7.12 (elastic#93065)
  [App Search] Implement various Relevance Tuning states and form actions (elastic#92644)
  [actions] for simplistic email servers, set rejectUnauthorized to false (elastic#91760)
  [Security Solution][Case] Migrate category & subcategory fields of ServiceNow ITSM connector (elastic#93092)
  Hide instances latency distribution chart (elastic#92869)
  [Maps] fix MapboxDraw import from pointing to dist just pointing to folder (elastic#93087)
  [Maps] fix results trimmed tooltip message doubles feature count for line and polygon features (elastic#92932)
  ...
v1v added a commit to shahzad31/kibana that referenced this pull request Mar 2, 2021
… playwright-ftr-e2e

* 'playwright-ftr-e2e' of github.com:shahzad31/kibana: (38 commits)
  [chore] Enable core's eslint rule: `@ts-expect-error` (elastic#93086)
  [Lens] Introduces new chart switcher (elastic#91844)
  [Lens] fix selection when dragging (elastic#93034)
  Converts usage collection README to .mdx (elastic#92982)
  Fix expanding document when using saved search data grid (elastic#92999)
  [SECURITY SOLUTIONS] Bug case connector (elastic#93104)
  [Security Solution] [Timeline] Bugfix to include unmapped fields in the timeline event details JSON (elastic#92025)
  [Alerting][Docs] Changed alerting documentation to point to a single source of explaining the configurations. (elastic#92942)
  [APM] Fix hidden search bar in error pages while loading (elastic#84476) (elastic#93139)
  [DOCS] Fixes links for machine learning alerts (elastic#92744)
  [Security Solution][Detections] -Fixes rule edit flow bug with max_signals (elastic#92748)
  [SecuritySolution][Case] Disable cases on detections in read-only mode (elastic#93010)
  [Security Solution][Case][Bug] Prevent closing collection when pushing (elastic#93095)
  [Security Solution][Detections][7.12] Critical Threshold Rule Fixes (elastic#92667)
  Bump ems landing page to 7.12 (elastic#93065)
  [App Search] Implement various Relevance Tuning states and form actions (elastic#92644)
  [actions] for simplistic email servers, set rejectUnauthorized to false (elastic#91760)
  [Security Solution][Case] Migrate category & subcategory fields of ServiceNow ITSM connector (elastic#93092)
  Hide instances latency distribution chart (elastic#92869)
  [Maps] fix MapboxDraw import from pointing to dist just pointing to folder (elastic#93087)
  ...
dej611 added a commit that referenced this pull request Mar 2, 2021
Co-authored-by: Wylie Conlon <wylieconlon@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Wylie Conlon <wylieconlon@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Change chart switcher design
7 participants