-
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][Visualize][Embeddable] Optimize Lens embeddables on error #144015
Changes from 3 commits
512859c
cae7625
30b1e9f
2463d6a
cad6f55
735cea5
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import React, { useRef } from 'react'; | ||
import { I18nProvider } from '@kbn/i18n-react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiText, EuiIcon, EuiEmptyPrompt } from '@elastic/eui'; | ||
|
@@ -45,6 +45,7 @@ export interface ExpressionWrapperProps { | |
className?: string; | ||
canEdit: boolean; | ||
onRuntimeError: () => void; | ||
onExpressionError: () => void; | ||
executionContext?: KibanaExecutionContext; | ||
lensInspector: LensInspector; | ||
noPadding?: boolean; | ||
|
@@ -53,9 +54,28 @@ export interface ExpressionWrapperProps { | |
interface VisualizationErrorProps { | ||
errors: ExpressionWrapperProps['errors']; | ||
canEdit: boolean; | ||
onExpressionError: ExpressionWrapperProps['onExpressionError']; | ||
searchSessionId?: string; | ||
} | ||
|
||
export function VisualizationErrorPanel({ errors, canEdit }: VisualizationErrorProps) { | ||
export function VisualizationErrorPanel({ | ||
errors, | ||
canEdit, | ||
onExpressionError, | ||
searchSessionId, | ||
}: VisualizationErrorProps) { | ||
// use a combination of sessionid + error messages to decide whether to trigger a rerender | ||
const rerenderKey = `${searchSessionId || ''}-${errors | ||
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. not sure that I fully understand why we need in include 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. What if we exclude
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. Using the |
||
?.map(({ longMessage }) => longMessage) | ||
.join('-')}`; | ||
|
||
const keyRef = useRef(rerenderKey); | ||
// Skip error logging when no search session id is passed | ||
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 don't think this comment is relevant.
|
||
if (keyRef.current !== rerenderKey) { | ||
keyRef.current = rerenderKey; | ||
onExpressionError(); | ||
} | ||
|
||
const showMore = errors && errors.length > 1; | ||
const canFixInLens = canEdit && errors?.some(({ type }) => type === 'fixable'); | ||
return ( | ||
|
@@ -121,14 +141,20 @@ export function ExpressionWrapper({ | |
errors, | ||
canEdit, | ||
onRuntimeError, | ||
onExpressionError, | ||
executionContext, | ||
lensInspector, | ||
noPadding, | ||
}: ExpressionWrapperProps) { | ||
return ( | ||
<I18nProvider> | ||
{errors || expression === null || expression === '' ? ( | ||
<VisualizationErrorPanel errors={errors} canEdit={canEdit} /> | ||
<VisualizationErrorPanel | ||
errors={errors} | ||
canEdit={canEdit} | ||
onExpressionError={onExpressionError} | ||
searchSessionId={searchSessionId} | ||
/> | ||
) : ( | ||
<div className={classNames('lnsExpressionRenderer', className)} style={style}> | ||
<ExpressionRendererComponent | ||
|
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.
👍
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.
@vadimkibana for followup work, we could accept an optional Error parameter, and use it to update the contents of a
data-render-error
attribute with a message. WDYT?