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][Expressions] Fixes react Error When Rendering Recoverable Error #196285

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,27 @@ import { getLongMessage } from '../../../user_messages_utils';
interface Props {
errors: Array<string | UserMessage>;
title: string;
onRender?: () => void;
}

export function WorkspaceErrors(props: Props) {
export function WorkspaceErrors({ errors, title, onRender }: Props) {
const [activePage, setActivePage] = useState(0);

const activeError = props.errors.length ? props.errors[activePage] : '';
const activeError = errors.length ? errors[activePage] : '';

React.useEffect(() => onRender?.(), [onRender]);

return (
<EuiEmptyPrompt
actions={
props.errors.length > 1 ? (
errors.length > 1 ? (
<EuiFlexGroup
justifyContent="spaceAround"
data-test-subj="lnsWorkspaceErrorsPaginationControl"
>
<EuiFlexItem grow={false}>
<EuiPagination
pageCount={props.errors.length}
pageCount={errors.length}
activePage={activePage}
onPageClick={setActivePage}
/>
Expand All @@ -64,7 +67,7 @@ export function WorkspaceErrors(props: Props) {
)}
</div>
}
title={<h2>{props.title}</h2>}
title={<h2>{title}</h2>}
iconColor="danger"
iconType="warning"
data-test-subj="lnsWorkspaceErrors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,10 @@ function useReportingState(errors: UserMessage[]): {
return { isRenderComplete, setIsRenderComplete, hasDynamicError, setDynamicError, nodeRef };
}

const dataLoadingErrorTitle = i18n.translate('xpack.lens.editorFrame.dataFailure', {
defaultMessage: `An error occurred when loading data`,
});

export const VisualizationWrapper = ({
expression,
lensInspector,
Expand Down Expand Up @@ -734,9 +738,10 @@ export const VisualizationWrapper = ({
useReportingState(errors);

const onRenderHandler = useCallback(() => {
setDynamicError(false);
setIsRenderComplete(true);
onRender$();
}, [setIsRenderComplete, onRender$]);
}, [onRender$, setDynamicError, setIsRenderComplete]);
Copy link
Member

Choose a reason for hiding this comment

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

qq: Could be great to know what a DynamicError is since it looks like used only in this workspace_panel file.
Why is "dynamic"?

Copy link
Contributor Author

@mbondyra mbondyra Oct 17, 2024

Choose a reason for hiding this comment

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

I guess what we meant the error is runtime and coming from the fact we cannot generate expression (so most likely it would be a wrong kql syntax or a user mistake that can be recoverable). When it appears, ExpressionRendererComponent instead of trying to render the expression, renders the content of the renderError prop.

What if we call it hasRequestError / setHasRequestError instead? 🤔


const searchSessionId = useLensSelector(selectSearchSessionId);

Expand All @@ -759,10 +764,6 @@ export const VisualizationWrapper = ({
);
}

const dataLoadingErrorTitle = i18n.translate('xpack.lens.editorFrame.dataFailure', {
defaultMessage: `An error occurred when loading data`,
});

return (
<div
className="lnsExpressionRenderer"
Expand Down Expand Up @@ -795,11 +796,13 @@ export const VisualizationWrapper = ({
? [errorMessage]
: [];

if (!hasDynamicError) {
setDynamicError(true);
}

return <WorkspaceErrors errors={visibleErrorMessages} title={dataLoadingErrorTitle} />;
return (
<WorkspaceErrors
errors={visibleErrorMessages}
title={dataLoadingErrorTitle}
onRender={() => setDynamicError(true)}
/>
);
}}
/>
</div>
Expand Down