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] Improves error messages when in Dashboard #90668

Merged
merged 18 commits into from
Feb 15, 2021
Merged

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Feb 8, 2021

Summary

Fixes #86278, #90594

This PR addresses some issues when embedding a Lens visualisation into Dashboard panels.
In particular visualisation would either not show an explaining error message when failing ( #86268 ) or rendering despite not being "valid" for Lens rules ( #90594 ).

The validation logic used for Lens editor has been now integrated into the embeddable to propagate the same experience.

  • ✨ Show nice error messages when in dashboard
  • ✨ Hint to open Lens to see more errors when multiple
  • 🔥 Remove unused Frame API
  • ✅ Unit tests - Functional test

Screenshot 2021-02-08 at 19 27 59

Screenshot 2021-02-08 at 19 27 46

Checklist

@dej611 dej611 added Feature:Dashboard Dashboard related features Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 Feature:Lens v7.12.0 labels Feb 8, 2021
@dej611
Copy link
Contributor Author

dej611 commented Feb 9, 2021

@elasticmachine merge upstream

@dej611 dej611 linked an issue Feb 9, 2021 that may be closed by this pull request
@dej611 dej611 changed the title [Lens] Show Lens validation messages when in Dashboard [Lens] Improve error messages when in Dashboard Feb 9, 2021
@dej611 dej611 changed the title [Lens] Improve error messages when in Dashboard [Lens] Improves error messages when in Dashboard Feb 9, 2021
@dej611 dej611 requested a review from ThomThomson February 9, 2021 11:50
@dej611 dej611 marked this pull request as ready for review February 9, 2021 11:50
@dej611 dej611 requested a review from a team February 9, 2021 11:50
@dej611 dej611 requested a review from a team as a code owner February 9, 2021 11:50
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Changes LGTM! Code only review, mostly focused on Lens embeddable and expression wrapper.

@@ -15,3 +15,11 @@
position: static; // Let the progress indicator position itself against the outer parent
}
}

.lnsExpressionRendererEmbeddedError {
Copy link
Contributor

Choose a reason for hiding this comment

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

Following our BEM naming convention, perhaps this should be .lnsExpressionRenderer__embeddedError, similar to the class above (.lnsExpressionRenderer__component).

Presuming that to be the case, should it also be nested in the group above?

Copy link
Contributor Author

@dej611 dej611 Feb 10, 2021

Choose a reason for hiding this comment

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

At the moment the component using this class is not nested within a lnsExpressionRenderer.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the component using this class is not nested within lnsExpressionRenderer, would it be better to name the class lnsEmbeddedError in order to avoid confusion such as the above? Just helps further separate the two.

@dej611 dej611 requested a review from ryankeairns February 10, 2021 11:37
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.

Looks pretty good to me, left one typing nit.

While testing I noticed one error case we are not handling well at the moment - if the index pattern for a visualization is missing, an empty panel is rendered and the error message is logged to the console.

Screenshot 2021-02-10 at 14 31 06

I will open a separate issue for this

datasourceLayers,
}),
errors: validationResult,
};
}

export const validateDatasourceAndVisualization = (
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just realizing this function is only operating on a single datasource - I guess this is something we have to revisit once we introduce additional datasource that can be active at the same time (like SQL). Nothing for this PR though.

datasourceStates,
datasourceLayers,
});
{ datasourceLayers } as FramePublicAPI
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a little scary - can be tighten the types here a bit? I went through our current consumers and there's one place using something besides datasourceLayers - the xy visualization will check out activeData.

Can we change the type of the second parameter of getConfiguration to Pick<FramePublicAPI, 'datasourceLayers' | 'activeData'>? This should fix the type cast and we want to move away from the kitchen sink api anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's also availablePalettes which is required somewhere. I couldn't find a way to drop it for the embeddable so for now I'm loading them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Managed to isolate it and remove availablePalettes as dependency as it was unused

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.

Left a few comments/questions regarding these error messages. Nothing show-stopping, but just thought I'd bring them up. Let me know what you think.

<EuiFlexItem>
<FormattedMessage
id="xpack.lens.embeddable.moreErrors"
defaultMessage="(Edit in Lens editor to see more errors)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than having in parenthesis, can we treat this like a regular sentence?

Also, is it possible to make Edit in Lens editor a link that opens this visualization in Lens in a new tab? Offering the user a quick action to correct the problem would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rather than having in parenthesis, can we treat this like a regular sentence?

Also, is it possible to make Edit in Lens editor a link that opens this visualization in Lens in a new tab? Offering the user a quick action to correct the problem would be nice.

Tried to implement the Edit in Lens button with the same logic of the Edit action (dropdown context menu) but it's not trivial. Perhaps it could be done as a follow up?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure! Let me know if you'd like me to open an issue for it.

Comment on lines 73 to 87
<div className="lnsExpressionRenderer__embeddedError">
<EuiFlexGroup
direction="column"
justifyContent="center"
alignItems="center"
style={{ maxWidth: '100%' }}
data-test-subj="embeddable-lens-failure"
>
<EuiFlexItem grow={false}>
<EuiIcon type="alert" size="xl" color="danger" />
</EuiFlexItem>
{customError || defaultMessage}
{moreErrors}
</EuiFlexGroup>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is using an EuiFlexGroup as shown here the standard for displaying Dashboard error messages? I'd think it would be cleaner/easier to just use an EuiEmptyPrompt instead, since it already bakes in icon, text and action buttons. You could then also put your messages in a more semantic p elements, rather than the current EuiFlexItem wrappers. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice idea. I used the same structure as in the Lens workspace but this one looks nicer.

@flash1293
Copy link
Contributor

@elasticmachine merge upstream

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 and works as expected, LGTM. Thanks for the functional test, I think this is a thing that can break easily without anyone noticing.

@dej611
Copy link
Contributor Author

dej611 commented Feb 11, 2021

Latest version using EuiEmptyPrompt:

Screenshot 2021-02-11 at 11 44 29

Screenshot 2021-02-11 at 11 44 42

@dej611
Copy link
Contributor Author

dej611 commented Feb 11, 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.

Tested and LGTM, but probably needs one more pass

title,
description,
const datasourceId = getActiveDatasourceIdFromDoc(doc);
if (datasourceId == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Strict equality works here, I'm surprised the linter allows ==

Suggested change
if (datasourceId == null) {
if (datasourceId === null) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any particular meaning for null and undefined here, or do they have the same meaning?

eslint has a special option for null or undefined case in the rule eqeqeq, which is usually enabled.
As in steps 2 and 3 of the ECMA262 Abstract Equality spec the == operator treat them the same exact way. So unless specific distinct meaning of the two there's no difference.

await embeddable.initializeSavedVis({} as LensEmbeddableInput);
embeddable.render(mountpoint);

expect(expressionRenderer).toHaveBeenCalledTimes(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This expect isn't really asserting what the title of the test says it does, can you align the two?

@dej611
Copy link
Contributor Author

dej611 commented Feb 15, 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 892.3KB 894.6KB +2.3KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
lens 34.7KB 34.7KB +22.0B

History

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

@mbondyra
Copy link
Contributor

I checked this PR last week and I forgot to confirm my comments 🤦 But all has been addressed in the meantime so approving!

@dej611 dej611 merged commit e9e7453 into elastic:master Feb 15, 2021
@dej611 dej611 deleted the fix/86278 branch February 15, 2021 12:00
dej611 added a commit to dej611/kibana that referenced this pull request Feb 15, 2021
jloleysens added a commit to jloleysens/kibana that referenced this pull request Feb 15, 2021
…ndition-for-hiding-recommded-allocation

* 'master' of github.com:elastic/kibana:
  [Discover] Fix toggling multi fields from doc view table (elastic#91121)
  [ML] Data Frame Analytics: ROC Curve Chart (elastic#89991)
  skip flaky suite (elastic#86948)
  skip flaky suite (elastic#91191)
  Fix date histogram time zone for rollup index (elastic#90632)
  [Search Source] Fix retrieval of unmapped fields; Add field filters (elastic#89837)
  [Logs UI] Use useMlHref hook for ML links (elastic#90935)
  Fix values of `products.min_price` field in Kibana sample ecommerce data set (elastic#90428)
  [APM] Darker shade for Error group details labels (elastic#91349)
  [Lens] Adjust new copy for 7.12 (elastic#90413)
  [ML] Unskip test. Fix modelMemoryLimit value. (elastic#91280)
  [Lens] Fix empty display name issue in XY chart (elastic#91132)
  [Lens] Improves error messages when in Dashboard (elastic#90668)
  [Lens] Keyboard-selected items follow user traversal of drop zones (elastic#90546)
  [Lens] Improves ranking feature in Top values (elastic#90749)
  [ILM] Rollover min age tooltip and copy fixes (elastic#91110)

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts
dej611 added a commit that referenced this pull request Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Dashboard Dashboard related features Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.12.0 v8.0.0
Projects
None yet
9 participants