-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Expression handling #37876
[Lens] Expression handling #37876
Changes from 16 commits
d2f3702
fc85182
1333bad
6cd0027
acd6126
aff1980
9a54c1e
88aef13
71f2699
f6c7ca9
fcf0993
3d4cf08
7d7a072
616985c
843c541
bcc847c
fc629ce
df15757
5a6f644
44d9238
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Ast, fromExpression } from '@kbn/interpreter/common'; | ||
import { Visualization, Datasource, DatasourcePublicAPI } from '../../types'; | ||
|
||
export function buildExpression( | ||
visualization: Visualization, | ||
visualizationState: unknown, | ||
datasource: Datasource, | ||
datasourceState: unknown, | ||
datasourcePublicAPI: DatasourcePublicAPI | ||
): Ast | undefined { | ||
const datasourceExpression = datasource.toExpression(datasourceState); | ||
const visualizationExpression = visualization.toExpression( | ||
visualizationState, | ||
datasourcePublicAPI | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the assumption that both datasource and visualization will always return a useful expression is the cause of the problem. I think we've seen that in Canvas, using sample data to replace a real data set is confusing to users. Visualizations without data might be able to render some kind of frame, but are otherwise meaningless. So here's a proposal:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, I implemented it like this. If one of the two doesn't provide an expression, nothing is rendered. I went with |
||
|
||
try { | ||
const parsedDatasourceExpression = | ||
typeof datasourceExpression === 'string' | ||
? fromExpression(datasourceExpression) | ||
: datasourceExpression; | ||
const parsedVisualizationExpression = | ||
typeof visualizationExpression === 'string' | ||
? fromExpression(visualizationExpression) | ||
: visualizationExpression; | ||
return { | ||
type: 'expression', | ||
chain: [...parsedDatasourceExpression.chain, ...parsedVisualizationExpression.chain], | ||
}; | ||
} catch (_) { | ||
return undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should do something with the error. If this fails, swallowing the error will make it difficult to diagnose. If we don't know what to do, I'd remove the try / catch and add a TODO comment. At least then, we get an explicit error which we can analyze in the console. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I moved the catch to the workspace panel and show the underlying error there. I don't like letting the exception bubble up and crash Kibana because errors in the expression are a nice error boundary. In most cases it is probably possible to recover from the error without losing state. We probably wont keep the very prominent error message in the workspace panel for the final release, but for beta it's nice to debug easily. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it
unknown
? It seems it would be either a string or an Error object, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use unknown for stuff I'm not sure about the shape. It is an object in practice but as these types are only temporary anyway I didn't bother defining it because I don't rely on it anywhere.