Skip to content

Commit

Permalink
Some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa committed Nov 15, 2022
1 parent 2463d6a commit cad6f55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class RenderCompleteDispatcher {
if (!this.el) return;
this.count++;
this.el.setAttribute('data-render-complete', 'true');
this.el.setAttribute('data-loading', 'false');
this.el.setAttribute('data-rendering-count', String(this.count));
}

Expand Down
16 changes: 9 additions & 7 deletions x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,6 @@ export class Embeddable
});
};

private onError: ExpressionWrapperProps['onExpressionError'] = () => {
this.renderComplete.dispatchError();
};

getExecutionContext() {
if (this.savedVis) {
const parentContext = this.parent?.getInput().executionContext || this.input.executionContext;
Expand Down Expand Up @@ -711,12 +707,19 @@ export class Embeddable

this.domNode.setAttribute('data-shared-item', '');

const error = this.getError();

this.updateOutput({
...this.getOutput(),
loading: true,
error: this.getError(),
error,
});
this.renderComplete.dispatchInProgress();

if (error) {
this.renderComplete.dispatchError();
} else {
this.renderComplete.dispatchInProgress();
}

const input = this.getInput();

Expand Down Expand Up @@ -746,7 +749,6 @@ export class Embeddable
style={input.style}
executionContext={this.getExecutionContext()}
canEdit={this.getIsEditable() && input.viewMode === 'edit'}
onExpressionError={this.onError}
onRuntimeError={(message) => {
this.updateOutput({ error: new Error(message) });
this.logError('runtime');
Expand Down
32 changes: 3 additions & 29 deletions x-pack/plugins/lens/public/embeddable/expression_wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useRef } from 'react';
import React from 'react';
import { I18nProvider } from '@kbn/i18n-react';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiFlexGroup, EuiFlexItem, EuiText, EuiIcon, EuiEmptyPrompt } from '@elastic/eui';
Expand Down Expand Up @@ -45,7 +45,6 @@ export interface ExpressionWrapperProps {
className?: string;
canEdit: boolean;
onRuntimeError: (message?: string) => void;
onExpressionError: () => void;
executionContext?: KibanaExecutionContext;
lensInspector: LensInspector;
noPadding?: boolean;
Expand All @@ -54,28 +53,9 @@ export interface ExpressionWrapperProps {
interface VisualizationErrorProps {
errors: ExpressionWrapperProps['errors'];
canEdit: boolean;
onExpressionError: ExpressionWrapperProps['onExpressionError'];
searchSessionId?: string;
}

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
?.map(({ longMessage }) => longMessage)
.join('-')}`;

const keyRef = useRef(rerenderKey);
// Skip error logging when no search session id is passed
if (keyRef.current !== rerenderKey) {
keyRef.current = rerenderKey;
onExpressionError();
}

export function VisualizationErrorPanel({ errors, canEdit }: VisualizationErrorProps) {
const showMore = errors && errors.length > 1;
const canFixInLens = canEdit && errors?.some(({ type }) => type === 'fixable');
return (
Expand Down Expand Up @@ -141,20 +121,14 @@ export function ExpressionWrapper({
errors,
canEdit,
onRuntimeError,
onExpressionError,
executionContext,
lensInspector,
noPadding,
}: ExpressionWrapperProps) {
return (
<I18nProvider>
{errors || expression === null || expression === '' ? (
<VisualizationErrorPanel
errors={errors}
canEdit={canEdit}
onExpressionError={onExpressionError}
searchSessionId={searchSessionId}
/>
<VisualizationErrorPanel errors={errors} canEdit={canEdit} />
) : (
<div className={classNames('lnsExpressionRenderer', className)} style={style}>
<ExpressionRendererComponent
Expand Down

0 comments on commit cad6f55

Please sign in to comment.