-
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
[Embeddable] Add unified error UI #143367
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c76a735
Refactor embeddable error handler
dokmic db316bf
Remove embeddable error handler from the visualization embeddable
dokmic 9f2dfa1
Update Lens embeddable to handle errors correctly
dokmic 3921a05
Fix edit button label
dokmic 249d8b2
Rename embeddable error handler component
dokmic bbaaa30
Fix embeddable panel error not to overflow
dokmic 4da17ef
Fix missing data view error in the visualization embeddable
dokmic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/plugins/embeddable/public/lib/embeddables/embeddable_error_handler.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { isFunction } from 'lodash'; | ||
import React, { ReactNode, useEffect, useRef, useState } from 'react'; | ||
import { isPromise } from '@kbn/std'; | ||
import type { MaybePromise } from '@kbn/utility-types'; | ||
import type { ErrorLike } from '@kbn/expressions-plugin/common'; | ||
import type { EmbeddableInput, EmbeddableOutput, IEmbeddable } from './i_embeddable'; | ||
|
||
type IReactEmbeddable = IEmbeddable<EmbeddableInput, EmbeddableOutput, MaybePromise<ReactNode>>; | ||
|
||
interface EmbeddableErrorHandlerProps { | ||
children: IReactEmbeddable['catchError']; | ||
embeddable?: IReactEmbeddable; | ||
error: ErrorLike | string; | ||
} | ||
|
||
export function EmbeddableErrorHandler({ | ||
children, | ||
embeddable, | ||
error, | ||
}: EmbeddableErrorHandlerProps) { | ||
const [node, setNode] = useState<ReactNode>(); | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
if (!ref.current) { | ||
return; | ||
} | ||
|
||
const handler = embeddable?.catchError?.bind(embeddable) ?? children; | ||
if (!handler) { | ||
return; | ||
} | ||
|
||
const renderedNode = handler( | ||
typeof error === 'string' ? { message: error, name: '' } : error, | ||
ref.current | ||
); | ||
if (isFunction(renderedNode)) { | ||
return renderedNode; | ||
} | ||
if (isPromise(renderedNode)) { | ||
renderedNode.then(setNode); | ||
} else { | ||
setNode(renderedNode); | ||
} | ||
}, [children, embeddable, error]); | ||
|
||
return <div ref={ref}>{node}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would it make sense to also include a
title
prop (along with an appropriatetitleSize
) for thisEuiEmptyPrompt
component (either dynamic or static)? If a static title, would something likeUnable to render visualization
work?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 tried to add that similarly to the button, but it requires significant changes in the code to get the embeddable type. I would rather leave that without the title prop. Especially since the error appearance is similar to what we had before.